mccp
Posts: 26
Joined: Thu Dec 01, 2011 8:53 am
Contact: Website

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 10:01 am

One of the systems I'm currently working with has a 64 MHz Coldfire CPU with 16 MB of SDRAM, the biggest system is a 266 MHz Coldfire with 128 MB of RAM. I'm looking forward to playing with 700 MHz and 256 MB!

I'm most interested in bare metal (i.e. no OS) development. I have absolutely nothing against Linux or any other OS, but developing software without the help of relatively massive operating systems and OS libraries is fascinating. It is always very satisfying when you have worked out how to get a new computer to wake up and start flashing its LEDs at you .

I hope that there are others that agree - Gert's post here implies that there may be at least one other! I know that the Gertboard will encourage microcontroller development, but a whole ARM CPU - oh, suits me, sir!

Anyhow, I have two points to make:


Would it be useful if this sub-forum were split or had sub-sub-forums for Linux projects and Other OS/bare metal projects?
Is anyone interested in a bare metal Raspberry Pi development environment? If so, I will probably be building something based around Eclipse and a GNU toolchain for my own use and would be happy to write it up for wider use.

User avatar
RaTTuS
Posts: 10459
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 10:41 am

if you really want to then start here - if it becomes too BIG then it will get moved to somewhere else,

but you are wrong in thinking that linux is massive - it's as large as you make it really - check out LFS  http://www.linuxfromscratch.org/ if nothing else
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

mccp
Posts: 26
Joined: Thu Dec 01, 2011 8:53 am
Contact: Website

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 11:00 am

RaTTuS said:


but you are wrong in thinking that linux is massive


That's not really my point, I understand that you can strip linux down.

It appears to me that there are very many professional programmers who are unable to clearly separate the CPU from the OS (any OS). For example, I am well known in my organisation for complaining about thread proliferation - even though programmers know that their process is only executing on a single core, they still seem to believe that threads mean that you can do more than one thing at a time. This is an illusion created by the OS.

It may be that the Raspberry Pi is not the best hardware to target for bare metal embedded development. However, I don't think that the chance to promoted embedded development in the educational community should be missed and it looks like the Raspberry Pi is going to be a very successful educational platform.

zippy
Posts: 21
Joined: Fri Dec 30, 2011 1:28 am

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 12:06 pm

Yes, I'm also hoping to use the RasPi as a cheap/powerful microcontroller, if the necessary low level hardware info is made available at some point.

I'm not up-to-date on RISCOS and BBC Basic (last time I used either was on my A3000 about 20 years ago) but maybe it'll be possible to use those for development if the BASIC assembler produces ARM11 code. You can just add a *SAVE command at the end of the basic program (after all the assembler code) to save the object binary file and then copy it to another SD card as "kernel.img" to boot it.

I have a couple of old A3000 demos that I'm aiming to get running in "bare metal" mode initially, just to see what's possible.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23686
Joined: Sat Jul 30, 2011 7:41 pm

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 1:37 pm

mccp said:


That's not really my point, I understand that you can strip linux down.It appears to me that there are very many professional programmers who are unable to clearly separate the CPU from the OS (any OS). For example, I am well known in my organisation for complaining about thread proliferation - even though programmers know that their process is only executing on a single core, they still seem to believe that threads mean that you can do more than one thing at a time. This is an illusion created by the OS.


Nothing wrong with thread proliferation (within reason) - the GPU software has dozens. What's wrong is that you appear to be employing idiots.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23686
Joined: Sat Jul 30, 2011 7:41 pm

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 1:38 pm

zippy said:


Yes, I'm also hoping to use the RasPi as a cheap/powerful microcontroller, if the necessary low level hardware info is made available at some point.


Not long now....
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

hippy
Posts: 5963
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 2:48 pm

mccp said:

Is anyone interested in a bare metal Raspberry Pi development environment? If so, I will probably be building something based around Eclipse and a GNU toolchain for my own use and would be happy to write it up for wider use.
Definitely interested.

I'd prefer a Windows command line cross-compiling setup using the CodeSourcery G++ Lite toolchain as that's working well for me as best I can tell in the absence of a physical R-Pi. Easy to install and setup and working for creating X86 binaries which run under Ubuntu. Doesn't require any installation of Cygwin nor MinGW which really helps make it 'just works'.

Whatever you choose please make sure it's easy to install and configure; I got nowhere faffing about with Code::Blocks trying to make that work. I want to be developing code not thrashing about fighting toolchains

If you ( or anyone else ) create some bare-metal example programs; (1) flashing a LED on a GPIO pin, (2) reading a switch on the same, (3) receiving and echoing via the UART, plus (4) putting something in the frame buffer for display should be enough of a foundation for everyone to build on.

mccp
Posts: 26
Joined: Thu Dec 01, 2011 8:53 am
Contact: Website

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 5:11 pm

JamesH said:


What's wrong is that you appear to be employing idiots.


Hmm . I don't think they are idiots, not the ones that are still here anyway.

mccp
Posts: 26
Joined: Thu Dec 01, 2011 8:53 am
Contact: Website

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 5:17 pm

hippy said:


CodeSourcery G++ Lite toolchain as that's working /snip


Works for me too, although for Coldfire, not currently for ARM. Coldfires provide an interface that Freescale call 'background debug mode' and you use a BDM dongle to download code and debug. Raspberry Pi would have to use a JTAG dongle and I don't have any experience of these so would appreciate any advice on suitable devices (cheap enough for hobbyists).

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23686
Joined: Sat Jul 30, 2011 7:41 pm

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 5:18 pm

mccp said:


JamesH said:


What's wrong is that you appear to be employing idiots.


Hmm . I don't think they are idiots, not the ones that are still here anyway.


What would you call someone who calls themselves a professional software engineer who thinks that with a single core threads means stuff executes at the same time? Or are those the ones who have all 'disappeared'!!
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 5:25 pm

See .sig (code untested on actual pi hardware)

Simon.

mccp
Posts: 26
Joined: Thu Dec 01, 2011 8:53 am
Contact: Website

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 5:26 pm

JamesH said:


What would you call someone who calls themselves a professional software engineer who thinks that with a single core threads means stuff executes at the same time?


A teaching opportunity?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23686
Joined: Sat Jul 30, 2011 7:41 pm

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 7:01 pm

mccp said:


JamesH said:


What would you call someone who calls themselves a professional software engineer who thinks that with a single core threads means stuff executes at the same time?


A teaching opportunity?


Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

hippy
Posts: 5963
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Bare metal Raspberry Pi

Fri Feb 03, 2012 9:22 pm

mccp said:


hippy said:


CodeSourcery G++ Lite toolchain as that's working /snip


Works for me too, although for Coldfire, not currently for ARM. Coldfires provide an interface that Freescale call 'background debug mode' and you use a BDM dongle to download code and debug. Raspberry Pi would have to use a JTAG dongle and I don't have any experience of these so would appreciate any advice on suitable devices (cheap enough for hobbyists).


AIUI it should be possible to get the bare-metal executable into a kernel.img, slap it on SD Card and simply boot it. The proof's in the doing it but I'm sure we'll get there and it's what  puts R-Pi well ahead of other flash memory / JTAG-only platforms IMO. No way to brick it is an absolute godsend.

Once we have something booting that something could take downloads via UART and update the SD Card so it would be no different to having any other bootloader micro.

For more advanced stuff, debugging with JTAG would probably be the way to go but download with fingers crossed and judicious use of printchar should get most people on the road if interested.

snowyseal
Posts: 1
Joined: Wed Feb 08, 2012 9:15 am

Re: Bare metal Raspberry Pi

Wed Feb 08, 2012 9:29 am

Getting back to what mccp asked – how to go about writing some assembler code to write to an SD card so that it will be run on startup.  I think there are plenty of real-time applications that don't want to boot a linux OS (simplest case: to flash an led)

I understand there is some initial bootstrap code embedded somewhere on the board which will then load stuff off the SD card. I read somewhere that the SD format must be vfat, and you would also have to provide the boot format and details the onboard bootstrap code is expecting.

Is there any documentation on this boot process?

Bit here:

http://elinux.org/RPi_Software

which says the GPU mounts the SD card, loads the GPU firmware, initialises hardware, then loads a kernel image. So, does it have to be a kernel image or could it just be a wee bit of hand-crafted code?

rpt
Posts: 51
Joined: Tue Jan 31, 2012 3:09 pm

Re: Bare metal Raspberry Pi

Wed Feb 08, 2012 9:59 am

snowyseal said:


So, does it have to be a kernel image or could it just be a wee bit of hand-crafted code?


There's nothing special about a Linux kernel image. You can boot any code or OS you want. Since all the booting is done by the GPU it should be easy to create a bare metal system.

10+10 is that a new record?

Velko
Posts: 7
Joined: Mon Feb 20, 2012 9:50 pm

Re: Bare metal Raspberry Pi

Mon Feb 20, 2012 11:01 pm

snowyseal said:

Bit here:
http://elinux.org/RPi_Software

which says the GPU mounts the SD card, loads the GPU firmware, initialises hardware, then loads a kernel image. So, does it have to be a kernel image or could it just be a wee bit of hand-crafted code?


It was puzzling me as well, but now, when official image is available, I took a liberty to reverse-engineer a little. With some effort I managed to disassemble a part of kernel.img. Here's what I got:00000000 :
0: ea000006 b 20
4: e1a00000 nop
8: e1a00000 nop
c: e1a00000 nop
10: e1a00000 nop
14: e1a00000 nop
18: e1a00000 nop
1c: e1a00000 nop

This suspiciously looks like standard ARM interrupt/exception vector table, with reset vector set to jump to address 0x20, rest filled with nop-s. 20: e3a00000 mov r0, #0
24: e3a01042 mov r1, #66
28: e3811c0c orr r1, r1, #3072
2c: e59f2000 ldr r2, [pc, #0] ; 0x34
30: e59ff000 ldr pc, [pc, #0] ; 0x38
34: 00000100
38: 00008000

There at address 0x20 it loads r0 with zero, does some mumbo-jumbo on r1 (sorry, I'm not that good in ARM assembly), then loads r2 with value from address 0x34 and pc (program counter) with value from address 0x38, effectively jumping to address 0x8000.

Then there are some bytes I'm not interested in anymore (must be data) and a big pile of zeros up to the address 0x8000. And sure enough: 8000: e321f0d3 msr CPSR_c, #211 ; 0xd3
8004: ee109f10 mrc 15, 0, r9, cr0, cr0, {0}
8008: eb0e81fd bl 3a8804
800c: e1b0a005 movs sl, r5

Code continues there.

So far it makes sense, so I imagine what bootloader does is: loads whatever is in file named kernel.img into RAM at address 0, and then starts executing it from there.

As a conclusion, there shouldn't be any problems to link a flat binary image with yet another bootloader, custom kernel or MCU-style firmware.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Bare metal Raspberry Pi

Tue Feb 21, 2012 12:09 pm

Velko said:


So far it makes sense, so I imagine what bootloader does is: loads whatever is in file named kernel.img into RAM at address 0, and then starts executing it from there.


Yep, that's exactly what happens.  This was made clear in October or so by (IIRC) Gert.


As a conclusion, there shouldn't be any problems to link a flat binary image with yet another bootloader, custom kernel or MCU-style firmware.


Indeed.  You'll want the datasheet, as it isn't quite a "standard" ARM implementation, but it's not hard to do.

Musmuris
Posts: 6
Joined: Fri Jan 13, 2012 4:12 pm

Re: Bare metal Raspberry Pi

Fri Feb 24, 2012 4:32 pm

I also had a hankering to write a (very simple) OS, purely as an academic exercise (well the Pi is targeted at education right?) so was also trying what Velko did

Velko said:


It was puzzling me as well, but now, when official image is available, I took a liberty to reverse-engineer a little. With some effort I managed to disassemble a part of kernel.img. Here's what I got:


That assembler must be in the source code that got released as well mustn't it?  Can anyone point out where? (Trying to learn low level linux stuff at the same time - been many years since I wrote assembler - and Z80 was somewhat simpler!)

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Bare metal Raspberry Pi

Fri Feb 24, 2012 5:24 pm

As an educational opportunity, _this_ is one of the most important kinds of things that the R-Pi will enable budding geek kids to learn.  I'm a SillyCon Valley software engineer and volunteer senior docent at the Computer History Museum in Mountain View, CA (http://www.ComputerHistory.org), and I can't tell you how disappointing it is when I'm explaining how fundamental digital electronics computing elements work, and even some college engineering students have no clue how the hardware actually works at the transistor, flip-flop, register, bus, etc., levels.  I hope this level of the R-Pi is documented and promoted as strongly as the other aspects so that kids can play around and experiment with low level aspects of the hardware as well as other levels all the way up to a full system with an OS, GUI, etc.  The inclusion of a GPU and support for 1080p video, along with the low-power features of the system, are especially important, given how many products now depend on these technologies.

I'll be following the efforts here closely and plan to have an R-Pi with me to demonstrate various computing principles when I present my tours of the museum. Keep up the great work!
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Bare metal Raspberry Pi

Fri Feb 24, 2012 7:10 pm

See my .sig

Simon

Musmuris
Posts: 6
Joined: Fri Jan 13, 2012 4:12 pm

Re: Bare metal Raspberry Pi

Fri Feb 24, 2012 7:35 pm

tufty said:


See my .sig

Simon


Thank you,

I did and read the first few posts on the ARM, which are quite informative and are also what I was thinking as well so far (from what I could glean from the Arm reference).

However there's that "/* Do any hardware intialisation that absolutely must be done first */". Now from what i've read I think the GPU has initialized some stuff first, but whatever is left is must be in the linux kernel source somewhere - hence wanting to find where that was.  And then hopefully trace that through to getting something like "hello world" put on the screen.

Velko
Posts: 7
Joined: Mon Feb 20, 2012 9:50 pm

Re: Bare metal Raspberry Pi

Fri Feb 24, 2012 9:13 pm

I'm afraid, it may be like trying to find a needle in a haystack. Personally, I feel lost every time, when looking at Linux source tree. And it may be a very long path from first instruction to actual "Hello world!" appearing on screen.

It looks that making characters appear on screen may be somewhat uneasy task - you'll need to render them pixel-by-pixel. But I'm studying Raspberry-Pi stuff only for a few days, so I may be wrong.

Output using UART looks much easier, however. For starters you could try ARM Integrator-CP Bare Bones. While it's not exactly R-Pi, the principle should be the same. Of course you'll need to adjust it to BCM2835 using information from datasheet. Also in ?? repo you can find Makefile, to use as a sample on how to produce kernel.img from your sources.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Bare metal Raspberry Pi

Fri May 18, 2012 12:19 am

I want to build a robot and only need:

1) input via SD card

2) output via GPIO pins

Frank Buss has modified the kernel to incorporate I2C modules - http://www.frank-buss.de/tmp/kernel.img

so..... what else do i need?

..... theoretically, if I had Frank's source code, could I just add to it to program my robot and access I2C devices wired up to the GPIO pins as he has - http://www.frank-buss.de/io-expander/

... If I cant get his source code, what file name does the kernel load next....?

... could I just compile my binary and give it that name...?
Ostendo ignarus addo scientia.

Return to “Other projects”