U-boot and switching O.S. on eMMC

Right now I have two Debian systems:

  • one on the eMMC, stock image.
  • one on the SD, a Debian/stable (from reform.debian.net).

If I replace the contents of the boot/root partitions on the eMMC with the contents of the SD by using rsync, would then U-boot load Debian/stable from the eMMC?

I’m not worried about fstab, but trying to understand how U-boot works and if the contents of the /boot partition can be completely replaced or not, or if U-boot has some special code like BIOS/MBR hidden somewhere in the disk and prone to be lost if one tinkers with partition tools.

By reading reform-migrate and reform-boot-config tools I would say this rsync method should work, but I am not 100% sure.

Also, U-boot reads boot.scr right? Who generates boot.scr and how can it be repaired if needed?

1 Like

If you do that and do not have your sd-card inserted, then u-boot will load boot.scr that was created by your debian-stable system which in turn will load kernel and initramfs from your debian-stable system from your emmc. But then the initramfs itself will panic because it is configured to load /boot and / partitions from the sd-card (unless your /etc/fstab is configured to look for partition labels and instead of just rsync you dd-ed the whole filesystem to eMMC).

U-boot has some special code on the eMMC: u-boot itself. But overwriting that code is a bit more tricky as that would require you to overwrite the contents of /dev/mmcblk2boot0 and /dev/mmcblk2boot1 which will not happen if you just dd onto /dev/mmcblk2. Indeed, writing to these two partitions is protected by writing 0 into the respective /sys/class/block/*/force_ro entry.

Depends. “should work” to achieve what? This document was written for the imx8mq (so ignore the content about the DIP switch position) but maybe it helps: document boot options (#2) · Issues · Reform / reform-handbook · GitLab

boot.scr is generated by the flash-kernel utility. You can craft your own by writing a script and then converting it into boot.scr format (there is a binary hash at the very top of the file) using the mkimage tool.

A better way to boot is using extlinux.conf which gets generated by the u-boot-update utility from the u-boot-menu package. I say better, because in contrast to boot.scr, extlinux.conf:

  • does not have a binary header, so no conversion tool is needed, you just edit the file and you are done
  • is declarative instead of turing-complete
  • if your u-boot has display support, can give you a boot menu allowing you to select a different kernel or operating system to boot
  • for u-boot versions that set the $fdtfile variable, we could have one image that runs on all platforms without any changes to it (currently we need to build 9 different images to accommodate for some vendor u-boot not setting $fdtfile)

Why do we not default to extlinux.conf yet? Because there are old classic reform units with imx8mq boundary vendor u-boot around that do not have support for extlinux.conf and would need to have their u-boot upgraded first.

1 Like

Thank you very much josch, this was a really good text to read, both your reply and the link you posted! Perfectly shows how it works :star_struck:.

Finally I moved the Debian/bookworm from my SD to the eMMC :upside_down_face:. To do this I had to:

  • rsync root and boot from SD to eMMC.
  • chroot, edit fstab and update-initramfs -u.

Because everything is just files, instead of removing the stock Debian files, I moved them into a root subfolder, so moving between them is as easy as just a couple of mv commands and reboot.