Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20693 Discussions

How to boot baremetal code from sd card

Altera_Forum
Honored Contributor II
3,208 Views

Hi 

I want to boot the baremetal code from sd card. 

I need some examples and the procedure about how to write the binary to SD card
0 Kudos
11 Replies
Altera_Forum
Honored Contributor II
2,147 Views

from what i've seen, Altera is recommending an RTOS over bare metal. i expect bare metal to be a fairly difficult flow

0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

If bare metal starts instead RTOS, where troubles ? 

Small, simple, fast, transparency one-thread-application, why may be difficult ? 

I also and long want to boot the baremetal code from SD card or QSPI !!! :)
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

You'll need to have boot code that understands how to read from the SD card as preset data in an M9K (or equivalent) memory block and to point the Nios's reset vector into that code. 

Since you know the Avalon address that will be used for the boot code, you don't need to make it position independant - so it can be written in C quite easily. 

I've posted minimal linker scripts before - all you need in assembler are the instructions to set %gp and %sp and a jump to the start of your C code. Without any of the Altera HAL/libc functions you can do a lot in a small amount of code. 

 

Never mind non-RTOS images, ones without even the HAL (etc) support are very useful. 

Especially if you want to run from internal memory
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

Why Nios there? This part of Altera Forum is about Cyclone V FPGA with internal ARM cores! 

To SD card I not may write my hwlib.bin (maked from hwlib.axf) through quartus_hps.exe on address 60000 or any, however to QSPI -- plainly, because there no MBR and filesystem, probably. And booting not work always :( 

I will get there from Altera Guru-s detailed rules to fill my any DDR3s-hwlib.axf to QSPI flash or raw partition of SD-card, to make in mind and practice full path of Baremetal application developing -- so that after repower kit board LEDs will blinking! 

Using or not RTOS, Linux ets. -- trouble of author of sources and its system architector/boss, I generally don`t need in "universal" fashionable garbage collections in my projects, using 100 M of ROM/RAM and booting more than 1 second. 

Using HAL to polling all system contents in one simple "thread" and processing in turn all of ingoing events are very effective in embedded applications.
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

I look at all the new posts by clicking on the 'Forum' link on the main header. 

It isn't entirely obvious of the context for some posts.
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

When I look to this page, up contain texts: 

Altera Forums - Powered by vBulletin Welcome, WitFed Notifications My Profile Settings Log Out Home Forum Marketplace Shared Material FAQ About Us Register Chinese Forum New Posts Private Messages FAQ Calendar Community Forum Actions Quick Links Forum Rules Advanced Search Forum * Device and Tools * Related * SoC * Cyclone SoC * How to boot baremetal code from sd card + Reply to Thread Results 1 to 6 of 6 Thread: How to boot baremetal code from sd card 

Among them was and path to topic from root, and "baremetal" must confuse... ;) 

 

...Please, anybody, help me to fill any Baremetal application to QSPI or SD ! Bugs, off please ! ;)
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

Linux probably loads using uboot - look at how uboot gets loaded. 

The ARM cpu itself will just execute code from its reset vector - which will need to be ROM. 

However uboot may well do a load of initialisation that your 'baremetal' code will need to replicate.
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

Hello, 

 

booting own baremetal code from SD Card or other Flash device is quite simple. 

All you need is a preloader, which is started first on bootup. 

 

the preloader initializes the basic functions of your HPS and loads i.e. code from FLASH or SD-Card into the SDRAM. 

The code that is loaded can be either an U-Boot, that loads your Linux image or it could be directly an baremetal application. 

 

A tutorial for the preloader can be found here: 

http://www.rocketboards.org/foswiki/documentation/gsrdpreloader#generating_the_preloader 

 

if you want to store your baremetal application on a FAT partition, you have to enable some settings for the preloader: 

http://www.rocketboards.org/foswiki/documentation/preloaderubootcustomization#preloaderubootfatpartition 

 

The image for the baremetal application, stored on the SD-CARD have to be created with a command like this: 

mkimage -A arm -O u-boot -T standalone -C none -a 0x01000000 -e 0x01000000 -n "Name_Of_Your_Application" -d baremetal.bin baremetal.img  

 

The mkimage tool can be found in the source folder of the generated preloader. 

 

That's all. If you've any more questions, just ask.
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

Thanks, and how to get baremetal.bin from my baremetal.axf ? 

Hardly keys "-a 0x01000000 -e 0x01000000" may work -- offsets of DDR3, in flash if 02000000 and 60000. 

I don`t have Linux, git and other s-h-i-t (sorry :) to dig up sources of u-boot from Yokto for recipe of getting its image to put to flash, however want on Windows 7 fast program example application Altera-SoCFPGA-HardwareLib-FPGA-CV-GNU from EDS, repower board -- and LEDs blinking! 

Best way from stupid users may be button in DS-5 "Program current .axf to jumpers selected current flash device, with offset in project settings" -- for Windows users, loving comfort and respectful to myself treatment. 

Slightly worse may be 10 pages in ug_soc_eds.pdf, where with pictures and command line options described full way of convert/program my .axf. 

However already 3 weeks while I cycling all documentation from Altera, Mentor, RocketBoards ets... and found nothing worth -- horror! :) 

Our firm must be create board with CV and not necessarily with SD, MBR, partitions, u-boot and Linux! 

Exist simple way to program 4 items of 64K-preloader to QSPI to addresses 0..40000 and my .axf to default 60000, possible .rbf to 600000 ? I very hate complicated ways, and to me sell its continuously and hide best behind huge Linux and RTOS ! :) 

 

Also good way is have one configurable pin in FPGA, through which ARM will load from custom BootROM in external direct reading flash from address 10000, just after its current internal BootROM, unrestricted from current complex-stupid puzzling architecture :) And on boot-wathdog automatic loads from 110000, 210000, 310000, 410000, 510000 and more any amount in all adress space with up round... 

And sources of this preloader10000 may be open, then will be hapiness ! Regardless to Bosses :) 

 

Worst of all, that my application not start in DS-5 debugger with jumpers at mentioned for QSPI-boot: J28 right shorted, J29 left shorted, J30 left shorted. 

 

On http://www.rocketboards.org/foswiki/documentation/bootingbaremetalapplicationfromqspiorsdcard create topic with similar request...
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

Hi, 

 

to get a *.bin file from *.axf file, you can use the fromelf tool, like this: 

 

fromelf --bin --output=baremetal.bin baremetal.axf 

 

You say, you only want to develop under Win7. It's no problem.  

I'm developing on Windows 7 system, too.  

 

A complete boot from SD CARD, with integrated preloader is on windows a little bit difficult, because you have to create a special "a2" partition on the card. That's much more easier on a linux system.  

 

But there is another way you can go. You can put the preloader into the QSPI flash and load the baremetal image from a FAT partition on SD Card. It's easy, because you only need to configure the preloader to load the image from SD-Card/FAT and put this preloader into the QSPI Flash, using the quartus_hps programmer. It's best to start this tool from Embedded_Command_Shell.bat 

 

quartus_hps -c 1 -o PV -a 0x0000 preloader-mkpimage.bin 

 

and than you put the baremetal.img on the FAT partition of the SD-Card. 

 

I can write a better step-by-step tutorial in the evening.
0 Kudos
Altera_Forum
Honored Contributor II
2,147 Views

Yes, yes, BIG Thanks!!! :) 

I try earlier make .bin through "objcopy --gap-fill=0xff -O binary hwlib.axf hwlib.bin", as found in makefiles for u-boot. 

And then calls "mkimage -A arm -O u-boot -T standalone -C none -a 0x02000000 -e 0 -n "baremetal image" -d hwlib.bin hwlib.img.bin". 

Please, check our way on usual live kit board with word to word, with Altera LEDs example, since I find in text ug_soc_eds.pdf many large amount of mistakes, then need serious control. Any miss in long chain and 5 folders -- and all not work. 

My application Altera-SoCFPGA-HardwareLib-FPGA-CV-GNU/hwlib.axf not need change settings before compilation ? 

I try: 

$ fromelf --bin --output=hwlib.bin hwlib.axf ARM FromELF, 5.03 Fatal error: Q9932E: Cannot obtain license for Fromelf (feature fromelf5) with license version >= 5.0201301 

In license.lic, bouht with board, really absent "fromelf5" :( Exist other method of binarisation ? 

 

...Partition A2 present on my SD-card, FAT also. 

It is possible recreate it through Win32DiskImager.exe and sd_card_linux_boot_image.img from embeddedsw/socfpga/prebuild_images. 

 

I can try "another way" and "more another ways" for learning, however my end target is 2nd stage in QSPI (preloader) and 3th also in QSPI (hwlib.axf.img.bin after 2 conversions). 

To have one flash device for 256K-preloader and another for 2M-application and 3M-rbf, let 2-3-4 times copied, is very-very strange.
0 Kudos
Reply