Forum Discussion
Cyclone V SoC Preloader will not run bare metal app
Hello all,
I've been working on this problem for several days now. I've read every website/pdf I can find (e.g. these forums, rocketboards, altera pdfs, etc, etc, etc, etc) regarding bare metal applications on Cyclone V SoC and I still can't get this to work. I've gotten pretty far but I've basically run out of steam. I usually never post on forums unless I've tried every possible thing I can think of and have totally run out of ideas and places to search. I think I must just be missing something very simple. Here's what I've done so far (targetting DE10-Nano board): 1) Created basic HPS design with UART and SDMMC peripherals enabled and DDR3 settings configured same as golden reference design that was provided with the board 2) Built hardware design to .SOF without error and converted SOF to RBF so that it can be loaded by pre-loader 3) Using the 'hps_isw_handoff' I created the spl_bsp with bsp-editor and configured to boot from SDMMC 4) Compiled preloader using 'make' which generated preloader-mkpimage.bin without error 5) Ran alt-boot-disk-util to update pre-loader image on special partition of SD card 6) Created SD/MMC example C project in SoC EDS application (from https://www.altera.com/content/dam/altera-www/global/en_us/others/support/examples/soc/altera-socfpga-hardwarelib-sdmmc-cv-gnu.tar.gz) 7) Compiled example C project to .AXF with no errors using baremetal GCC arm-altera-eabi- toolchain 8) Copied AXF file to SD card FAT partition and inserted SD card into board 9) Powered on board Pre-loader uboot output is as follows:U-Boot SPL 2013.01.01 (Sep 04 2017 - 20:01:43)
BOARD : Altera SOCFPGA Cyclone V Board
CLOCK: EOSC1 clock 25000 KHz
CLOCK: EOSC2 clock 25000 KHz
CLOCK: F2S_SDR_REF clock 0 KHz
CLOCK: F2S_PER_REF clock 0 KHz
CLOCK: MPU clock 800 MHz
CLOCK: DDR clock 400 MHz
CLOCK: UART clock 100000 KHz
CLOCK: MMC clock 50000 KHz
CLOCK: QSPI clock 3125 KHz
RESET: COLD
INFO : Watchdog enabled
SDRAM: Initializing MMR registers
SDRAM: Calibrating PHY
SEQ.C: Preparing to start memory calibration
SEQ.C: CALIBRATION PASSED
SDRAM: 1024 MiB
ALTERA DWMMC: 0
U-Boot 2017.03-rc2 (Mar 30 2017 - 19:07:16 -0700)
CPU: Altera SoCFPGA Platform
FPGA: Altera Cyclone V, SE/A6 or SX/C6 or ST/D6, version 0x0
BOOT: SD/MMC Internal Transceiver (3.0V)
Watchdog enabled
I2C: timeout in enabling I2C adapter
timeout in enabling I2C adapter
ready
DRAM: 1 GiB
MMC: dwmmc0@ff704000: 0
timeout in enabling I2C adapter
timeout in enabling I2C adapter
In: serial
Out: serial
Err: serial
Model: Terasic DE10-Nano
Net: No ethernet found.
Hit any key to stop autoboot: 0
=> run fpga_cfg
reading de10-nano.rbf
1952756 bytes read in 192 ms (9.7 MiB/s)
=> load mmc 0:1 0x01000000 sdmmc_example.axf
reading sdmmc_example.axf
669244 bytes read in 73 ms (8.7 MiB/s)
=> bootelf
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range # # Starting application at 0x00100040 ...
INFO: System Initialization.INFO: Setting up Global Timer.INFO: Setting up SDMMC.RESULT: Some failures detected. As you can see the pre-loader loads the FPGA design file. The configuration DONE light turns on so I know configuration is successful. However, the example application fails. Clearly there are some cache issues but I have no idea what they mean or why they are happening. But then the example application starts and just fails with no indication as to why. I inserted some printfs into the example code and it fails at the call to alt_sdmmc_card_identify(). I'm not sure if the 0x01000000 address that I'm loading to makes sense. The only reason that I'm using it is because that's the address that the 'bootelf' command tries to load from. It's obvious that the SD card peripheral is working since the pre-loader can read from it. I also tried changing the u-boot environment variables and writing them back to the SD card and that worked as well. So SD card read/write operation seems OK. It's also obvious that the DDR is working because the pre-loader can clearly write the ELF file to the DDR at address 0x01000000 and the HPS can obviously read from it since the application does in fact run (just not successfully). Can someone please help me figure this out? Regards P.S. I'm not interested in using the debugger to load the application. I need the fpga design and application to be loaded off of the SD card as I've shown. So please don't reply with "use the debugger and make a debug script" or similar. I need the board to boot and just start running without cables attached. UPDATE: I've also tried the GPIO example from the altera website (https://www.altera.com/content/dam/altera-www/global/en_us/others/support/examples/soc/altera-socfpga-hardwarelib-gpio-cv-gnu.tar.gz) and doesn't even successfully print the first printf statement. Instead it just prints a bunch of garbage: => load mmc 0:1 0x01000000 gpio_example.axf
reading gpio_example.axf
610864 bytes read in 64 ms (9.1 MiB/s)
=> bootelf
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range
CACHE: Misaligned operation at range # # Starting application at 0x00100040 ...-ÊÊêJåÍѵ%¹¥Ñ¥±¥é?½¹¹J9=éJ¹¥ÑA%=j½Õ±¹J9=éÑÑ¥¹ÕÁA%=¥¹ÑÉÉÕÁ?J9=??ÕÁ:A%=½Éb?J9=é?ÕÁA%=½ÉAÕÍ¡ ÕÑ?¹¹J9=?¥ÍÑ?¥¹ÑÉÉÕÁ?¢¹±É¹J9=é?ÍÍ"AM}A }UMI}ÁéBAM0? ±¥¹*¹J9=??ÍÍ!AM}A }UMI}ÅéB5b5E5??±±?¡Ñ¹J9=??ÍÍBAM}A }UMI}ÉêBAM"???±±b?J9=??ÍÍ!AM}A }UMI}ÍÒB5b)E5ÒÕ?½¹á¥Ñ¢µ½¹26 Replies
- Altera_Forum
Honored Contributor
It's not that hard to create a debug configuration. Why are you so against testing it that way?
- Altera_Forum
Honored Contributor
If you think using the debugger will somehow get the SD card approach to work then I'm OK with trying it. My point is that if the design works with the debugger that's great but ultimately it doesn't end up helping me because I need it to work without the debugger. There are several forum posts for SoC issues where people suggest using the debugger, it works, and then no one bothers to help anymore even though that's not what the original poster requested help with. I want to avoid this.
Additionally, the bare metal applications that I'm running are not mine. They are known working altera reference designs. So I'm not sure what I'd be debugging as far as the software is concerned...? I'm more apt to believe at this point that this is a process/flow issue (like I'm skipping a step or using the wrong file format or something) rather than an application bug. If you'd like to point to or provide some debug instructions I'll try it out and report results. I've never used the debugger before. Just keep in mind that I'm using the bare metal GCC arm-altera-eabi- toolchain and not the licensed ARM DS-5 tool-chain. - Altera_Forum
Honored Contributor
jwdonal,
have you considered using a simpler program instead? Alike "hello world" or toggling the LED on the DE0-10 nano connected to the HPS. Without the licensed DS-5, you will be limited to what U-BOOT offers: memory dumps. You should look at the memory map file from your compilation/link, check the generated code with objdump (the exception jump table is a good one) and then verify the code binary values are at the expected memory locations with UBOOT's md command. Regards - Altera_Forum
Honored Contributor
Just wanted to give a last update to this thread. After several weeks of attempting to get this to work I was finally able to get bare metal apps working but not with u-boot. U-boot never worked for me. I think the worst part about this is getting the same bare metal app running on Xilinx Zynq devices is totally trivial compared to my experience with Altera. Same goes for Linux on Xilinx Zynq devices. With the Xilinx tools and chips everything "just works" as you'd expect - no fuss. Here are my final tallies for getting bare metal and linux apps to work on Xilinx Zynq and Altera Soc devices (having the same amount of prior technical experience using both vendors chips):
- Xilinx Zynq Bare metal = 1 day - Xilinx Zynq Linux OS = 2 days - Altera SoC Bare metal = 3 weeks - Altera SoC Linux OS = 2 weeks I also find it pretty ridiculous that getting a full Ubuntu linux distribution working on an Altera SoC took _less_ time to get working than it did to get a bare metal app working. Absurd. The# 1 issue I ran into with the Altera SoC flow was the major lack of documentation and reference designs. Some of the reference designs worked but as soon as I tried to create my own design using the same steps nothing worked. - Altera_Forum
Honored Contributor
Hi jwdonal & all,
I'm struggling myself to have a small bare-metal demo loading from SD card, and I'm actually not interested in having uboot. The steps I followed are: 1. Got the GHRD for my platform (DE0-Nano) 2. Created a BSP using BSP editor. I'm booting from SD and enabled FAT support. 3. Build preloader successfully 4. Used alt-boot-disk-util to write pre-loader image to the relevant partition on the SD card 5. I have a small "hello world" application that I was able to load via DS5. 6. Using 'mkimage' tool I've created an *.img file and copied it to the FAT partition Unfortunately, the small app wouldn't load. I forgot mentioning that in the BSP editor I'v modified the FAT_LOAD_PAYLOAD_NAME to the *.img file. It seems like preloader loads the file but can't jump to it. I might be using mkimage in a wrong manner, I'm not sure. I see you are mentioning that you were able to load a bare-metal application without uboot, so I'd really appreciate if you can share your steps or at least point out what I was missing in mine. Thanks. - Altera_Forum
Honored Contributor
Thanks for the information!!
The missing part in my "puzzle" was the placement of the image in the memory layout. I'm using mkimage for generating the 'img' file, and since it adds 0x40 bytes of header it was important to update the linker where I'd like the actual code to begin. After aligning that, the preloader was launching my application. I didn't invest in trying to launch my application from uboot. - Altera_Forum
Honored Contributor
Yes, I saw the same kind of 0x40 offset used in the linker file for the Unhosted sample, so I merged that into the SDMMC code sample, and it started working. I saw a similar solution posted here:
https://forum.rocketboards.org/t/hwlib-example-design-is-not-running-on-my-custom-board/217/3 - Altera_Forum
Honored Contributor
Hello elizr and austin944,
I'm beginner on this approach (bare metal in FPGA fabric) and I would like to ask if it's possible, if you can post the tutorial or article that explains how to create the SD card to boot a bare metal code from preloader because the documentation of terasic from DE10-Nano doesn't match this topics (bare metal). - Altera_Forum
Honored Contributor
The following Wiki describes the different types of HPS booting for a Cyclone V system like the DE10-Nano:
http://www.alterawiki.com/wiki/socbootfromfpga 1) Boot from SD/MMC card, 2) Boot from QSPI, 3) Boot from NAND, 4) RAM Boot - on Warm Reset only, 5) Boot from FPGA, 6) FPGA Fallback boot. I've only done# 1 so far, where the preloader and the baremetal application are loaded onto the SD card. Which one are you interested in? You mention "bare metal in FPGA fabric", so do you mean# 5 above? - Altera_Forum
Honored Contributor
--- Quote Start --- The following Wiki describes the different types of HPS booting for a Cyclone V system like the DE10-Nano: http://www.alterawiki.com/wiki/socbootfromfpga 1) Boot from SD/MMC card, 2) Boot from QSPI, 3) Boot from NAND, 4) RAM Boot - on Warm Reset only, 5) Boot from FPGA, 6) FPGA Fallback boot. I've only done# 1 so far, where the preloader and the baremetal application are loaded onto the SD card. Which one are you interested in? You mention "bare metal in FPGA fabric", so do you mean# 5 above? --- Quote End --- Thanks for the quick reply Austin, sorry for the confusion but when I mentioned bare metal I mean to boot from SD/MMC card to program the FPGA with the .rfb or .sof file and then start the bare metal application for the ARM, also I don't know exactly who programs the FPGA itself but my idea is to load some hdl into FPGA and then start my application (c baremetal) that'll talk with the hdl. Reading the documents I think that the main idea is to use this flow: boot rom -> preloader -> bare metal (ARM) :)