Jump to content

How to make a SD card bootable with U-Boot


Recommended Posts

Hello guys!


Recently I bought a Helios64 NAS and now I am playing around with it. My intention is to set it up as I need it, but I also want to understand how the system works. The last weeks I did a huge effort to read everything about what armbian exactly is, how it works, and also how the boot process works. I would say I have a good overview of the topics right now, but now I am at a point where I need your help.


My intention right now is the following: I want to make an automatic backup system, which runs regularly and saves the backups incrementally on an external HDD. The idea is: When I am messing up my system (which I certainly will when playing around), I can copy one of the working backups onto another SD card and boot from that instead. And have a working system again.


I had already a look at the nand-sata-install script, and based on that I already have the commands ready to copy the root filesystem. (I am using parted mklabel and parted mkpart for preparing the partition table, then using mkfs.ext4 to create the filesystem, and then the rsync command from the nand-sata-install script (+x option to stop at file system boundaries) to copy the root file system). This is the first step for now. Later, I want to include another step: I will backup my root file system with borg backup into a borg repository. This can store incremental backups very well. And then, when I need a backup, I rsync from one of the borg backups onto my SD card.


But even after a exhausting research how the boot process works in general (loading the MBR -> jumping to the boot sector or boot partition -> loading the boot file -> loading the kernel), and trying to understand how the nand-sata-install script handles the U-Boot install, I don't understand how to make my SD card bootable. With

hexdump -C -n 512 /dev/mmcblk0

I can see the MBR with the signature "55 aa" as the last two bytes, which tells the BIOS that this card is bootable. Then I see with

parted /dev/mmcblk0 unit s print

that the first and only partition (primary ext4) starts at sector 32768, where one sector equals 512 bytes. With hexdump, I see that the sectors before the first partition contain actually some data. But I am not sure, if this is garbage, or if this is the boot code from Das U-Boot. Reading this tutorial (https://linux-sunxi.org/Bootable_SD_card) it actually seams that the first sectors of the SD card is the U-Boot binary code written to the SD card with dd. However, I didn't find any *.bin file on armbian in /boot/ directory. Based on this tutorial (https://neosmart.net/wiki/mbr-boot-process/ ) I actually understood how the boot process is working, and that also the first sector(s) of a partition can contain boot code. However, with hexdump on /dev/mmcblk0p1, I saw that the first 1024 bytes of the partition are zero.


So my question now is: How can I make my cloned SD card bootable, by either backing up the boot code from the original card and copying it onto the new card, or by re-creating the boot code freshly on the cloned SD card (from my personal PC). I also like to understand, what I am actually doing and why, not just copying commands blindly.


Thanks a lot for your help!

Link to comment
Share on other sites

Moved to Helios64 club forums.


32 minutes ago, Chalix said:

I am not an expert in this but there might be differences in the boot behavior between Allwinner SoCs (sunxi family) and Rockchip SoCs (like the RK3399 which the Helios64 is built around).

Link to comment
Share on other sites

@Chalix You have done quite a research already :)

Helios64 is Rockchip RK3399 based so you are better off with the theory found here http://opensource.rock-chips.com/wiki_Boot_option as a starter.


U-boot and vendor blob binaries are found in "/usr/lib/linux-u-boot-$BRANCH-helios64_$RELEASE_arm64" folder on your system.

You are probably using "current" $BRANCH and the latest $RELEASE is 21.02.3.


The recipe to write the images to device (more or less) is to be found here.


Link to comment
Share on other sites

Thank you for moving this topic. I thought actually, that the boot process is independent from the hardware, and all the hardware related stuff would be handled in the BIOS ROM. Seems like I have still to learn a lot about booting. Good that I have some hardware available to experiment with :)


@piter75Yes, I am very interested in this topic. But I have very little practical experience with it. I want to change that right now. Thanks a lot for pointing me to the right pages! I will read about it and experiment with my Helios and my SD card.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines