I have an SD card with a standard Beaglebone Debian image. I also have the MLO
and u-boot.img
files from building u-boot. I’d like to install the new u-boot on the SD card and then flash the modified image to MMC on a Beaglebone Black.
I can flash onboard MMC from the SD card just fine. I can also connect to the board over serial and stop in u-boot.
What I don’t know how to do is write the new u-boot to the SD card correctly. I’ve tried a few things:
-
These elinux instructions are for erasing the SD card and creating a new bootable partition. I didn’t actually try this because I want to install the new u-boot to an existing image.
$ echo -e "onnnpn1nn+64Mnan1ntncnwn" | sudo fdisk /dev/MYDISK ; sudo fdisk /dev/MYDISK -l $ sudo mount /dev/MYDISK /mnt $ sudo cp MLO /mnt $ sudo cp u-boot.img /mnt $ sudo sync $ sudo umount /mnt
-
These digikey instructions are a different version of the same thing. I tried writing MLO and u-boot.img in this way, without erasing the disk, but the board still boots using the original u-boot instead of the new one.
$ sudo dd if=/dev/zero of=${DISK} bs=1M count=10 $ sudo dd if=./u-boot/MLO of=${DISK} count=1 seek=1 bs=128k $ sudo dd if=./u-boot/u-boot.img of=${DISK} count=2 seek=1 bs=384k
-
These beyondlogic instructions have a slightly different pair of dd commands. I tried these as well, but again the board still boot susing the original u-boot.
$ sudo dd if=MLO of=/dev/sdb bs=512 seek=256 count=256 conv=notrunc $ sudo dd if=u-boot.img of=/dev/sdb bs=512 seek=768 count=1024 conv=notrunc $ sudo blockdev --flushbufs /dev/sdb
-
Someone suggested that I write the new u-boot to MMC using tftp. Can I use the same procedure to write to the SD card? If so, how do I find the start addresses? And how to I load and write the files? I tried searching, but I didn’t find what I needed.
- boot into u-boot - discover the existing MLO and uboot.img start addresses - load the new MLO and uboot.img into RAM using tftp - write the new MLO and uboot.img to the correct location in MMC
Additional Notes
- Ideally, I would like to write the new u-boot to the SD card and test it without flashing. Supposedly the beaglebone will boot the SD card u-boot (instead of the MMC u-boot) if you press S2 when you supply power, but I’m not sure if that is working. How can I tell which u-boot is loaded?
- However, I can write the MMC image to an SD card, so it would also work to write the new u-boot to MMC and test that.
- Lastly, I’m willing to erase the SD card, write u-boot with one of the above methods, and manually setup/write the partitions if I have to. Is that the only way to do this?
SD Card / Image
The SD card contains the Debian 7.9 2015-11-12 firmware image from beagleboard latest images.
This is the partition table.
Model: Generic- USB3.0 CRW -SD (scsi)
Disk /dev/sdb: 31.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 102MB 101MB primary fat16 boot, lba
2 102MB 3565MB 3463MB primary ext4
The boot partition does not contain MLO or u-boot.img files to replace:
total 96
drwxr-xr-x 2 root root 2048 Nov 12 2015 App
-rwxr-xr-x 1 root root 288 Nov 12 2015 autorun.inf
drwxr-xr-x 4 root root 2048 Nov 12 2015 Docs
drwxr-xr-x 5 root root 2048 Nov 12 2015 Drivers
-rwxr-xr-x 1 root root 40 Nov 12 2015 ID.txt
-rwxr-xr-x 1 root root 41174 Nov 12 2015 LICENSE.txt
-rwxr-xr-x 1 root root 1008 Nov 12 2015 nfs-uEnv.txt
-rwxr-xr-x 1 root root 16838 Nov 12 2015 README.htm
-rwxr-xr-x 1 root root 428 Nov 12 2015 README.md
drwxr-xr-x 2 root root 2048 Nov 12 2015 scripts
-rwxr-xr-x 1 root root 16838 Nov 12 2015 START.htm
-rwxr-xr-x 1 root root 1179 Nov 12 2015 uEnv.txt
2
Answers
If you are using
init-eMMC-flasher-v3.sh
to flash the SD card to MMC, you can just copy the MLO and u-boot.img files to/opt/backup/uboot
on the SD card. In addition to setting up the partitions and writing the rootfs, the script writes the MMC bootloader using these files if they are present.It is not necessary to install the new u-boot to the SD card. It is also not necessary to boot the board using the SD card bootloader.
You may need to update the flasher scripts on the SD card by running
git pull
in /opt/scripts.So, assuming the SD card drive is
/dev/sdb
:And of course edit uEnv.txt to enable the eMMC flasher.
Then you can insert the SD card into the beaglebone and power on. Both the new bootloader and the SD card rootfs will be written to MMC.
The crux of your problem is that the ROM boot code of the AM335x SoC is capable of reading the MLO from the SD card (or eMMC) in either raw sector mode or in FAT file mode. Additionally in raw mode there are four possible areas to locate the boot image, although when the first sector of the medium contains the MBR, then there are only three areas.
The AM335x SoC will check for a boot image using raw mode first.
So if you want to install the MLO as a file in the FAT filesystem, then you have to ensure that any previous MLO stored in raw sectors are removed.
IOW there are multiple ways of storing the MLO on eMMC/SD card, and the order in which they are checked determines which image is used to boot. The FAT file would be the last image in the boot order.
The SD card with the Debian image that you have stores the MLO and u-boot.img as raw sectors (i.e. note that the FAT filesystem starts at sector 2049, offset 0x100000, so there are unallocated sectors preceding that first partition).
[Note that sector numbering starts with 1, not 0.]
The existing MLO on your SD card is stored at sector 257 (offset 0x20000 or 128K) which includes a sector for its TOC (Table of Contents) and an eight-byte GP header.
The existing u-boot.img on your SD card is stored at sector 769 (offset 0x60000 or 384K).
You can replace both of these images using the beyondlogic instructions, as the
seek=
displacements are correct for what already exists on your SD card.The Digikey instructions specify similar
seek=
displacements but use different blocksizes and counts. The first command would also remove the MBR (and render the FAT and ext filesystems inaccessible).Alternatively you could zero-out the TOC so that raw mode would fail and then the ROM boot would revert to FAT file mode.
You could then dispense with
dd
commands and sector offsets, and use ordinary filesystem commands.Your SD card has only one TOC to eliminate, so one command would suffice:
If you didn’t know where the image was located, then clearing the other possible areas would be necessary:
Do you mean which U-Boot image is executed/booted?
Wouldn’t the version string (with build timestamp) that U-Boot displays on start-up indicate which image has been booted?
The only “problem” I read is stated in your title.
Clarification
Although you may be able to locate/store the MLO at raw sectors or as a FAT file on eMMC or SD card, where you store the u-boot.bin image is dictated by how the U-Boot SPL was configured/built. (The MLO is simply the U-Boot SPL preceded with 520 bytes for a Table of Contents and GP header.)
For instance the default U-Boot configuration for the BBB will build a SPL/MLO that will expect the u-boot.bin to be stored at raw sector 0x300 (or 769 when properly not counting from zero).
I.E. from the .config file:
This seems to be the same configuration as the Debian SD card image that you are using.
If you want to store the u-boot.bin image as a file in the FAT filesystem of the SD card, then you would have to reconfigure the U-Boot SPL (i.e.
make menuconfig
) and rebuild to obtain a new MLO.Refer to chapter
26.1.8.5 MMC/ SD Cards
of the AM335x and AMIC110 Sitara Processors Technical Reference Manual.