解决了就好!补充几点,供以后搜到这个帖子的人参考。
为什么之前 dd 了还是 rknext
我看了官方 u-boot-rk2410(2017.09-66)里 rock-5c 的 idbloader.img,SPL 设备树里的启动顺序是:
u-boot,spl-boot-order = mmc@fe2c0000 (SD) → SPI → mmc@fe2e0000 (eMMC)
也就是说,即使 SPL 是从 eMMC 加载的,只要插着带系统镜像的 SD 卡,SPL 也会优先加载 SD 卡上的 u-boot.itb。所以如果当时插着旧镜像的 SD 卡,或者 dd 写到了 SD 卡上,看到的就还是旧的 rknext。
先确认哪个设备是 eMMC
grep -H . /sys/block/mmcblk*/device/type # MMC = eMMC,SD = SD 卡
确认写进去的确实是自己编译的版本
# SPL 的版本和编译时间(SD 卡也可以这样查,看看上面有没有旧的 loader)
sudo dd if=/dev/mmcblk0 bs=512 skip=64 count=1024 status=none | grep -a -o "U-Boot SPL [[:print:]]*"
# 逐字节比对
sudo cmp -n $(stat -c%s idbloader.img) idbloader.img /dev/mmcblk0 0 $((64*512)) && echo "idbloader OK"
sudo cmp -n $(stat -c%s u-boot.itb) u-boot.itb /dev/mmcblk0 0 $((16384*512)) && echo "u-boot.itb OK"
SD 卡
偏移完全相同(idbloader 在 sector 64,u-boot.itb 在 sector 16384),只要把 of= 换成 SD 卡的设备即可(用上面的命令确认,通常是 /dev/mmcblk1)。
官方包里的脚本做的也是同样的事,安装自己编译的 deb 之后可以直接用:
sudo /usr/lib/u-boot/rock-5c/setup.sh update_bootloader /dev/mmcblk0
变砖时怎么恢复(更正我上次的说法)
如果 eMMC 上自己编译的 SPL 起不来,BootROM 不一定会回退到 SD 卡。这时进 Maskrom 模式,用 rkdeveloptool 重新写入即可,不需要换板子。同一个 setup.sh 里也有 maskrom_update_bootloader、maskrom_erase_bootloader 这些函数可以参考。
Glad you got it working! A few notes for anyone who finds this thread later.
Why the earlier dd still booted rknext
I looked at the rock-5c idbloader.img in the official u-boot-rk2410 package (2017.09-66). The boot order in the SPL device tree is:
u-boot,spl-boot-order = mmc@fe2c0000 (SD) → SPI → mmc@fe2e0000 (eMMC)
So even when the SPL itself is loaded from eMMC, if an SD card with an OS image is inserted, the SPL loads u-boot.itb from the SD card first. If an SD card with the old image was in the slot, or the dd went to the SD card, you would still see the old rknext.
Check which device is the eMMC
grep -H . /sys/block/mmcblk*/device/type # MMC = eMMC, SD = SD card
Check that what you wrote is really your own build
# SPL version and build time (also works on the SD card, to see if an old loader is there)
sudo dd if=/dev/mmcblk0 bs=512 skip=64 count=1024 status=none | grep -a -o "U-Boot SPL [[:print:]]*"
# byte-for-byte check
sudo cmp -n $(stat -c%s idbloader.img) idbloader.img /dev/mmcblk0 0 $((64*512)) && echo "idbloader OK"
sudo cmp -n $(stat -c%s u-boot.itb) u-boot.itb /dev/mmcblk0 0 $((16384*512)) && echo "u-boot.itb OK"
SD card
The offsets are the same (idbloader at sector 64, u-boot.itb at sector 16384). Just point of= at the SD card device instead (check it with the command above; usually /dev/mmcblk1).
The script in the official package does exactly the same thing, so after installing your own deb you can simply run:
sudo /usr/lib/u-boot/rock-5c/setup.sh update_bootloader /dev/mmcblk0
Recovering from a bad build (correcting what I said last time)
If a self-built SPL on the eMMC doesn’t boot, the BootROM won’t necessarily fall back to the SD card. In that case, enter Maskrom mode and rewrite it with rkdeveloptool; the board isn’t lost. The same setup.sh has maskrom_update_bootloader and maskrom_erase_bootloader functions you can use as a reference.