BPI-R2 won't boot from SD Card after flashing BPI-R2-EMMC-boot0-DDR1600-20191024-0k.img.gz

Hi teammates,

after flashing EMMC with BPI-R2-EMMC-boot0-DDR1600-20191024-0k.img.gz it won’t boot anymore from SD. I know it sounds curious to mention EMMC and SD-CARD in respect of booting but I’ll describe what happened :

  • running OS from SD-CARD since a while ago
  • decided to move some part of OS from SD-CARD to EMMC
  • activated write mode on /dev/mmcblk1boot0
  • checked config with mmc extcsd read /dev/mmcblk1 | grep PARTITION_CONFIG
  • with bpi-bootsel I’ve flashed BPI-R2-EMMC-boot0-DDR1600-20191024-0k.img.gz onto EMMC
  • that is the point where I stucked, because I had to reboot, and since then my system is not working!
  • it was a plan further migrating from SD-CARD to EMMC

I suspect that I flashed accidentally the preloader to the SD-CARD!

After that I made a new SD-CARD with a pure system, and flashed preloader in the way what Frank-w exactly suggested :

gunzip -c BPI-R2-EMMC-boot0-DDR1600-0k-0905.img.gz | sudo dd of=/dev/mmcblk1boot0 bs=1024 seek=0

From this point, BPI-R2 can boot, but obviously there is no OS or anything on EMMC. With the old one ( SD-CARD ), I can’t boot neither from EMMC nor SD-CARD!

I would like to use the OS from SD-CARD again, at best could be migrated onto EMMC.

How should/could I do?

Have you checked boot-switch? its position defines first location where bootrom looks for preloader. If it is set to 0 and emmc has preloader installed it will not boot sdcard. So it should be set to 1 to allow sdcard boot (boot sd if it has preloader,if not try emmc)

If I attach the old SD-CARD, bpi-r2 doesn’t do anything, no UART, no HDMI, just light 3 leds out! With the new SD-CARD it boots. Without SD-CARD I get U-Boot Menu. It’s similar if I delete EMMC partitions. I think somehow the old SD-CARD consists wrong settings. Therefore if boot-switch was set 0, it wouldn’t boot with the new SD-CARD, but I might think it wrong!

Maybe your old sd has broken preloader or other headers (boot0/1). If these 3 are there the first output is visible on debug uart

If it works with new sd card all is good now,am i right?

Unfortunately just partially!

I would like to use it furthermore, because of the kernel and invested work in root fs! I have backup images of boot and root made from old SD-CARD. Now I’m trying install your pure buster image, and than take a backup boot/root. In this way, broken preloader or/and other headers could be fixed.

My main focus is using this kernel and settings, packages, etc…

You could dd the first 1M of my image to yours,if you have not changed partition layout (or first 320k if you want to leave your uboot)

DD-ing the first 1M solved my problem!

Thank you Frank!

remember for migrating from sd to emmc you have to configure uboot and your system to use the right device/partition

Let’s say I can apply this patch with dd onto /dev/mmcblk1boot0 :

BPI-R2-EMMC-boot0-DDR1600-20191024-0k.img.gz

After that on running system I can do this :

  • mmc bootpart enable 1 1 /dev/mmcblk1
  • mmc extcsd read /dev/mmcblk1 | grep PARTITION_CONFIG

Making partitions with :

 sfdisk /dev/mmcblk1 
 start=   204800, size=   524288, Id= c
 start=   729088, size= 14540800, Id=83
 mkfs -t vfat /dev/mmcblk1p1
 mkfs -t ext4 /dev/mmcblk1p2
 mkdir -p /mnt/emmc/boot
 mkdir -p /mnt/emmc/root
 mount /dev/mmcblk1p1 /mnt/emmc/boot
 mount /dev/mmcblk1p2 /mnt/emmc/root

Modify fstab :

/dev/mmcblk1p2 / ext4 errors=remount-ro 0 1 /dev/mmcblk1p1 /boot vfat defaults 0 0

And finally BOOT and ROOT should be copied and synced via rsync or tar or cp:

rsync -aAXv --exclude={"/dev/","/proc/","/sys/","/tmp/","/run/","/mnt/","/media/","/lost+found","/boot/"} / /mnt/emmc/root/

mkdir -p /mnt/emmc/boot/bananapi/bpi-r2/linux
cp /boot/bananapi/bpi-r2/linux/uImage /mnt/emmc/boot/bananapi/bpi-r2/linux
mkdir -p /mnt/emmc/root/lib/modules/
cp -r /lib/modules/$(uname -r) /mnt/emmc/root/lib/modules/

But what if my uEnv.txt consist just one line, is it okay ?

kernel=uImage_5.4.51-main

You also need to set root

Partition should be set by my checks (first try sd than emmc)

It’s absolutely great! Working!

If I attach an SD-CARD, it boots and displays Booting from SD. If I detach it, it starts up and shows Booting from Emmc.

Thank you Frank! :wink:

This is done by uboot env variable selectmmc/checksd,which checks for sdcard and if none is inserted it uses emmc

That is where i set partition to load kernel from. But i do not set root because in mainline-kernel emmc is 0 (like uboot) but in my and bpi kernels it is 1 (and sdcard is 0)