Boot fails with self-build u-boot

Partition is used only to load kernel (1=sd/0=emmc,1=bpi-boot,2=rootfs),kernel itself uses root variable in bootargs (/dev/mmcblkxpy and its own mapping which is same in mainline,but swapped in my kernel => 0=sd,1=emmc)

on host pc use type or file command to show arch of binary and ls -l to show execute bit

How have you got rootfs and hoe did you copy ot to sd-card/image

For copying to kernel into the image I used these steps:

sudo mount ${loopdev}p2 /mnt/
sudo cp -r debian_buster_armhf/. /mnt/
kernelpack=SD/bpi-r2_5.4.2-main.tar.gz
sudo tar -xzf ${kernelpack} -C /mnt/ --strip-components=1 BPI-ROOT
sudo umount /mnt
sudo mount ${loopdev}p1 /mnt/
sudo tar -xzf ${kernelpack} -C /mnt/ --strip-components=1 BPI-BOOT
sudo umount /mnt

To write the image on the sdcard I use Balena Etcher tool.

Below is the permissions for the list of files used to create the image. None of them has the execution bit set

sysadmin@banana-pi-r2:~$ ls -ltrh
-rw-r--r--  1 sysadmin sysadmin 1.5K Dec 21 23:58 BPI-R2-HEAD1-512b.img
-rw-r--r--  1 sysadmin sysadmin  440 Dec 22 00:00 BPI-R2-HEAD440-0k.img
-rw-r--r--  1 sysadmin sysadmin  90K Dec 28 23:19 BPI-R2-preloader-DDR1600-20190722-2k.img
-rw-r--r--  1 sysadmin sysadmin 315K Dec 30 12:21 u-boot.bin
-rw-r--r--  1 sysadmin sysadmin 1.0G Dec 30 13:03 bpi-r2-buster.img

sysadmin@banana-pi-r2:~$ ls -ltrh SD/
-rw-r--r-- 1 sysadmin sysadmin  75M Dec 29 00:13 bpi-r2_5.4.2-main.tar.gz

sysadmin@banana-pi-r2:~$ file u-boot.bin  
u-boot.bin: COM executable for DOS

sysadmin@banana-pi-r2:~$ file bpi-r2-buster.img  
bpi-r2-buster.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0xc,190,51), end-CHS (0x2d,97,52), startsector 204800, 524288 sectors; partition 2 : ID=0x83, start-CHS (0x2d,97,53
), end-CHS (0x82,138,8), startsector 729088, 1368064 sectors

For the init files below is the output

root@banana-pi-r2:/home/sysadmin/debian_buster_armhf# file sbin/init
sbin/init: symbolic link to /lib/systemd/systemd
root@banana-pi-r2:/home/sysadmin/debian_buster_armhf# file bin/sh
bin/sh: symbolic link to dash
oot@banana-pi-r2:/home/sysadmin/debian_buster_armhf# file lib/systemd/systemd  
lib/systemd/systemd: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=88a674d14a2f58d
940028741d56808f5b3b69d3f, stripped
root@banana-pi-r2:/home/sysadmin/debian_buster_armhf# file bin/dash
bin/dash: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=642545b6392ba038e9c366fa9c
33b9ed0f835cf9, stripped

root@banana-pi-r2:/home/sysadmin/debian_buster_armhf# ls -ltrh lib/systemd/systemd
-rwxr-xr-x 1 root root 955K Oct 16 16:24 lib/systemd/systemd
root@banana-pi-r2:/home/sysadmin/debian_buster_armhf# ls -ltrh bin/dash
-rwxr-xr-x 1 root root 74K Jan 17  2019 bin/dash

Mhm…last block looks good…strange that kernel reports no init found…have you buster from my gdrive?

I used the buster image from your drive and it boots fine. :slightly_smiling_face:

In the end if I do not make it work I will try to use your image and build on top of it.

I do not know if somewhere is defined where partitions need to start and how large they need to be…i only took partition table from existing jessie image for stretch and buster and replaced rootfs

Finally made it boot successfully :partying_face:

The kernel panic issues was due to the fact that in the debian bootstrap folder the lib directory is a symlink pointing to /usr/bin and the kernel tar gz image also has a lib folder in BPI-ROOT (no symlink there).

When I copied the lib folder from kernel BPI-ROOT it had overwritten the lib symlink from the debian bootstrap. So I needed to manually copy the lib folder from the debian bootstrap folder into the lib directory of the mounted image.

/sbin/init is a symlink pointing to /lib/systemd/systemd and since this file was not present there the kernel panic message was thrown.

For booting I used also the latest preloader BPI-R2-preloader-DDR1600-20191024-2k.img and also compiled the latest u-boot image from your 2020-01-bpi-r2 branch.

So far things work good. I created only a small 1.5Gb minimal image so I can speed up testing and writing down on the SD card.

Thanks also for providing guidance.

1 Like

thats strange…my buster bootstrap archive has no /lib link…it’s a regular directory. And link /lib to /usr/bin sounds wrong…

Sorry I meant debian bootstrap lib was a symlink to /usr/lib.

cioby@arch-desktop:/data/BPI-R2/debian_buster_armhf$ ls -ltrh lib            
lrwxrwxrwx 1 root root 7 Dec 30 16:38 lib -> usr/lib

Here are the details about this Debian change which is pretty recent. https://wiki.debian.org/UsrMerge

ArchLinux has moved all root folders bin, sbin, lib under usr folder a while ago and kept symlinks of old locations for compatibility. So it seems Debian took this path recently also.

1 Like

Hi @lexa2,

I’m trying to build a new OpenWRT image using the latest trunk 5.4 (kernel) and I applied most of your OpenWRT patches to my fork and managed to create an image, but I’m struggling in the last 2 days to boot it with success. The boot process it freezes at Starting kernel …

I compiled also a new U-boot version 2020.04-rc5 which has around 330k (most of your u-boot patches were merged) and added the latest BPI-R2 preloader BPI-R2-preloader-DDR1600-20191024-2k.img which increased the **load uboot size from 300000 to 524288 and added 512KB, flag for uboot"

Can you please explain me a little bit the partitioning scheme you used to create the image ?

I understand that the boot partition is starting at 1MB and if I use the new preloader from october and a bigger u-boot image (~330k) do I need to move the start of the partition to allow space for preloader and u-boot ?

I was looking at your gen_mediatek_sdcard_img.sh script above and I see that you set

UBOOT_OFFSET=320

If using the new preloader which increased the size for u-boot to 524288 do I need to modify this value and move u-boot to a higher offset ?

I was looking also at this picture to try and understand the partitioning

@sinovoip please shed some light about the partitioning requirements, preloader and u-boot

no, offset stays same

basicly he uses the partition sheme i’ve wrote down here: https://wiki.fw-web.de/doku.php?id=en:bpi-r2:storage

if you see “Starting kernel” you have all working till kernel-loading and i guess you have not set your serial console right in bootargs…my kernel uses ttyS0 where mainline kernel uses ttyS2

I’m using the mainline kernel now.

Where do I need to check where the serial port is configured for ttyS2 ?

You can print bootargs with printenv before loading kernel.

Below is the output of the printenv from U-boot console:

askdtb=askenv dtbinput "enter dtb-name:";
askkernel=askenv kernelinput "enter uImage-name:";
boot0=run lskernel;run askkernel;if printenv kernelinput ;then setenv kernel ${kernelinput};run lsdtb;run askdtb;if printenv dtbinput ;then s;
boot1=run newboot;
bootall=if printenv fdt; then run loadfdt; if printenv dtolist;then run loaddtolist;fi; bootm ${loadaddr} - ${dtaddr} ;else bootm; fi
bootargs=console=ttyS0,115200 root=/dev/mmcblk1p2 rw rootwait ip=dhcp
bootcmd=setenv bootdelay 3; run reloadmenu;
bootdelay=0
bootdev=SD
printenv 
askdtb=askenv dtbinput "enter dtb-name:";
askkernel=askenv kernelinput "enter uImage-name:";
boot0=run lskernel;run askkernel;if printenv kernelinput ;then setenv kernel ${kernelinput};run lsdtb;run askdtb;if printenv dtbinput ;then s;
boot1=run newboot;
bootall=if printenv fdt; then run loadfdt; if printenv dtolist;then run loaddtolist;fi; bootm ${loadaddr} - ${dtaddr} ;else bootm; fi
bootargs=console=ttyS0,115200 root=/dev/mmcblk1p2 rw rootwait ip=dhcp
bootcmd=setenv bootdelay 3; run reloadmenu;
bootdelay=0
bootdev=SD
bootedfrom=SD
bootenv=uEnv.txt
bootfile=uImage
bootmenu_0=1. Enter kernel-name to boot from SD/EMMC.=run boot0
bootmenu_1=2. Boot kernel from TFTP.=run bootnet
bootmenu_2=3. Boot from SD/EMMC.=run boot1
bootmenu_3=4. Boot from eMMC.=run useemmc; run boot1
bootmenu_4=5. Boot from SD.=run usesd; run boot1
bootmenu_default=2
bootnet=run lstftp;run askkernel;if printenv kernelinput ;then setenv bootfile "${kernelinput}"; fi;printenv; setenv bootargs ${netbootargs};m
bootopts=vmalloc=496M debug=7 initcall_debug=0
buildargs=setenv bootargs "console=${console} root=${root} ${bootopts} ${graphic}"
checkbootedfrom=if itest.l *81dffff0 == 434d4d65 ; then setenv bootedfrom eMMC; else setenv bootedfrom SD; fi;
checkenv=test -e ${device} ${partition} ${bootenv}
checkmmc=fatinfo ${device} 0:1
checkroot=fatinfo ${device} ${partition}
checksd=fatinfo ${device} 1:1
console=earlyprintk console=ttyS0,115200 console=tty1 fbcon=map:0
detectroot=run useemmc; run checkbootedfrom; if test "${bootedfrom}" == "SD"; then run usesd; fi; run validateroot;
device=mmc
dtaddr=0x83f00000
fdt_high=0xffffffff
fdtcontroladdr=ff9fc570
fileaddr=83000000
filesize=11ea
graphic=video=1920x1080 drm.debug=0x7
importenv=env import -t ${scriptaddr} ${filesize}
ipaddr=192.168.0.11
kernel=uImage
loadaddr=0x80200000
loadbootenv=if fatload ${device} ${partition} ${scriptaddr} ${bootenv};then run importenv;else echo "fatload (${bootenv}) failed";fi
loaddto=echo "loaddto:${dto}";fdt addr ${dtaddr};fdt resize 8192; setexpr fdtovaddr ${dtaddr} + F000;fatload ${device} ${partition} ${fdtovad}
loaddtolist=for dto in ${dtolist} ; do run loaddto ; done
loadfdt=fatload ${device} ${partition} ${dtaddr} dtb/${fdt}
loadkernel=echo "loading kernel ${kernel}...";fatload ${device} ${partition} ${loadaddr} ${kernel}
lsdtb=ls ${device} ${partition} dtb
lskernel=ls ${device} ${partition};
lstftp=tftp ${loadaddr} ${serverip}:files.lst;setexpr listend ${loadaddr} + ${filesize};mw.b ${listend} 00 2;strings ${loadaddr};
netbootargs=console=ttyS0,115200 root=/dev/mmcblk1p2 rw rootwait
netmask=255.255.255.0
newboot=run prepsetroot; run setroot;run buildargs;printenv bootargs;fatload ${device} ${partition} ${loadaddr} ${kernel}; bootm
newboot2=run prepsetroot; run setroot;run buildargs; printenv bootargs; run loadkernel; run bootall;
partition=1:1
prepsetroot=setenv setroot setenv root ${roottmpl}
reloadenv=run detectroot; if run validroot; then if run checkenv; then run loadbootenv; run detectroot; else echo uEnv.txt file not found on ;
reloadmenu=run reloadenv; run reportboot; if run validroot; then if run checkenv; then run loadbootenv; else echo uEnv.txt file not found on ;
reportboot=run reportbootedfrom reportvalidroot reportrootswapwarn reportbootdev
reportbootdev=echo "Booting from ${bootdev}."
reportbootedfrom=echo "Preloader/U-Boot loaded from ${bootedfrom}."; run validroot || echo "Both SD and eMMC pt#1 are not FAT, falling back t"
reportrootswapwarn=if test "${bootedfrom}" != "${bootdev}" ; then echo "Warning: Partition 1 on ${bootedfrom} is not FAT, failing back to ${b;
reportvalidroot=run validroot || echo "Both SD and eMMC pt#1 are not FAT, falling back to U-Boot shell."
resetenv=env default -a;printenv;
rootdev=/dev/mmcblk1p2
roottmpl=${rootdev} rootfstype=ext4 rootwait
scriptaddr=0x83000000
serverip=192.168.0.10
swaproot=run useemmc
useemmc=setenv partition 0:1; setenv rootdev /dev/mmcblk0p2; setenv bootdev eMMC; setenv swaproot 'run usesd';
usesd=setenv partition 1:1; setenv rootdev /dev/mmcblk1p2; setenv bootdev SD; setenv swaproot 'run useemmc';
validateroot=setenv validroot false; run checkroot || run swaproot; run checkroot && setenv validroot true || run swaproot;
validroot=true

Environment size: 4417/8188 bytes

Currently I do not have ext4 support compiled in U-boot so I cannot see the root partition content.

As i see you use a modified version of my environment…

If you call newboot, buildargs is used to override buildargs you see…here console var is used…

console=earlyprintk console=ttyS0,115200 console=tty1 fbcon=map:0

Just try change this before loading kernel

Sorry excuse my ignorance I’m not very familiar with U-boot Uenv.txt file syntax. Is this the way how I should configure it and run it ?

setenv newboot "console=earlyprintk console=ttyS0,115200 console=tty1 fbcon=map:0"
run newboot

In uenv.txt:

console=earlyprintk console=ttyS2,115200 console=tty1 fbcon=map:0

Or in uboot itself

setenv console "earlyprintk console=ttyS2,115200 console=tty1 fbcon=map:0"

Before calling newboot you have to set kernel var…maybe also by uenv.txt…

How have you configured it?

I see the console line is already set and has all options from this output

bootargs=console=earlyprintk console=ttyS0,115200 console=tty1 fbcon=map:0 root=/dev/mmcblk1p2 rootfstype=ext4 rootwait vmalloc=496M debug=7 7
3154366 bytes read in 163 ms (18.5 MiB/s)
## Booting kernel from Legacy Image at 80200000 ...
Image Name:   ARM OpenWrt Linux-5.4.31
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    3154302 Bytes = 3 MiB
Load Address: 80008000
Entry Point:  80008000
Verifying Checksum ... OK
Loading Kernel Image

Starting kernel ...

I tried also manually to boot the kernel using U-boot menu and below is the output:

 4586   uEnv.txt
3154366   uImage

2 file(s), 0 dir(s)

enter uImage-name: uImage
kernelinput=uImage
enter dtb-name: 
## Error: "dtbinput" not defined

It does not have any dtb file. This might be the issue why it freezes ?

Your bootargs showing ttyS0…you need dtb only if it is not appended to kernel binary…

Ok i got a little further. I enabled earlyprintk and debug and after booting I see the kernel boots fine but no console

bootargs=console=earlyprintk console=ttyS0,115200 console=tty1 fbcon=map:0 root=/dev/mmcblk1p2 rootfstype=ext4 rootwait vmalloc=496M debug=7 7
3152846 bytes read in 163 ms (18.4 MiB/s)
## Booting kernel from Legacy Image at 80200000 ...
Image Name:   ARM OpenWrt Linux-5.4.31
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    3152782 Bytes = 3 MiB
Load Address: 80008000
Entry Point:  80008000
Verifying Checksum ... OK
Loading Kernel Image

Starting kernel ...

Uncompressing Linux... done, booting the kernel.

Also I modified in this patch 0006-dts-fix-bpi2-console.patch on the bootargs line the console value from ttyS2 to ttyS0 but no luck yet

— a/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts +++ b/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts @@ -19,6 +19,7 @@

chosen {
	stdout-path = "serial2:115200n8";
  •   bootargs = "console=ttyS0,115200n8";
    

    };

    cpus {

I guess you use mainline kernel where debuguart is (not moved) uart2. Why you change choosen-node? And ttyS2 is right for mainline… Your uboot still shows ttyS0 before starting kernel