I managed to get my Unmatched to boot from flash. It was a matter of enabling the SPI flash drivers in the SPL, and adding an SPI option to spl_boot_device(). Here are the diffs I applied to U-Boot:
I wrote the image to flash while running FreeBSD using “dd if=FLASH.img of=/dev/flash/spi0 bs=4096 conv=sync”. I’m not sure what the flash device is on Linux.
Flip the boot DIP switches to 6 and yank the SD card out.
Making the SPI readable will allow us to store the environment and UEFI variables there.
Can the boot ROM boot from SPI? Then we could put OpenSBI and U-Boot or maybe in future EDK II there and get rid of the SD-card.
How does the boot ROM identify that it should boot from SPI? Where do SPL+OpenSBI and main U-Boot have to be stored? Is there a way to unbrick the board if the SPI image is bad?
The position of the boot select switches determines whether you boot from flash or sdcard. The first post in this thread mentions setting the boot select switches to 6.
If you break flash, you just flip the switches back to boot from sdcard and then use an sdcard image to fix flash.
Flash is just another disk, so it can hold a disk image just like the sdcard does.
I see the same problem with the syslog spamming regarding mmc if there is no SD card inserted. Interestingly it goes away after inserting one - even if it is removed again. I wonder if it is related with the voltage warning thingy…? That could probably be disabled by removing the voltage-ranges line from the DT as explained in this (possibly outdated) blog post: July | 2014 | Vonger's Blog
If so that DT should be fixed “officially” I guess (what’s upstream for these)?
Or there is a proper quirks setting for the controller? AFAICT the driver is built-in into the Ubuntu kernel… that makes experimenting with that too much of a hassle for me right now.
I have tested it and yes that’s all that is needed. One can simply replace the existing dtb in /lib/firmware/5.11.0-1017-generic/device-tree/sifive/ or whatever (but beware it will be overwritten by kernel updates). To ease recompilation of a decompiled version, here is the change with expanded values: gpios = <0x0b 0x0f 0x01>;
Writing the image with dd takes quite a while. If you install flashrom you can improve on that a lot. It also is a good idea to create the images with all ones because that reduces the wear on the flash (that’s the tr part below). I use these bits to create and flash the image instead of what skibo posted above:
Note that I create a 32MB image to match the flash size (a requirement of flashrom) and that the last two steps operate via SSH on the host unmatched. Replace that with the IP of your board if necessary.
As mentioned before you can dd to SPI-NOR Flash directly under linux (done that before) as mtdblock is available.
In general (quick look) the patch above looks OK. Basically the code should be the same as on Unleashed (copy & paste). I am not sure you need all the CONFIG_* here. For example CONFIG_SYS_SPI_U_BOOT_OFFS should be part of DTSI. From Unleashed:
I had tried to arrange the flash partitions so that they are aligned to 4K boundaries to make it easier to update the SPL and U-boot partitions but I could not get the SPL to boot unless I set up the partitions exactly as I did (sectors 34 and 2082). I never went back to figure out why. Also, I should’ve added a dos or EFI partition to store the environment or have a boot.scr.
EDIT: Ha. I figured it out. When I moved the partitions to align them, I think I forgot to modify the seek values in the dd commands so I corrupted the image. I managed to get it to work.
I’ve finally had some time to come back to this. This new patch is simplified a bit and supports storing the environment in flash. It is mostly the same as the July 15, 2020 commit to add SPI support to Unleashed but without support for putting the distro in flash.
I am now using partitions the same as the Unleashed which are aligned to make them easier to update. I have used the following script to create the correct partitions in flash and copy the FSBL (u-boot-spl.bin) and u-boot into their partitions:
I also added these patches to 1. enable fallback booting from SD (useful for testing and if Flash contains errors) and 2. a configuration file for genimage to automatically build a flash image.
This can then be flashed in linux using flash_erase /dev/mtd0 0 0 && dd if=spi-nor.img of=/dev/mtd0 bs=4K status=progress.
Note that these offsets are still for the first path of skibo (u-boot,spl-payload-offset = <0x104400>;)
Since U-boot support has been integrated, is there now a simpler process for enabling booting from SPI flash with a recent SiFive software release? Ideally, without needing to rebuild anything?
I recently acquired a used board with a broken MicroSD card latch, so I’m looking for a way to boot the machine without have to hold the MicroSD card in place.