frank-w / BPI-Router-Images

9 stars 7 forks source link

Can't boot bpi-r3 after system upgrade #12

Open GiovanniBalestrieri opened 2 months ago

GiovanniBalestrieri commented 2 months ago

I am using a debian 12 image created with your tool.

./buildimg.sh bpi-r3 bookworm

After a system update and upgrade I am not able to boot the system anymore.

I am getting:

## Error: "initrd" not defined
PARTITION_CONFIG only exists on eMMC
sd available
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: ff, ef, aa
Failed to initialize SPI flash at 0:0 (error 0)
NAND available
sd nand
fit=bpi-r3.itb
** No partition table - mmc 0 **
Couldn't find partition mmc 0:5
Can't set block device
BPI-R3>  

Any advice?

frank-w commented 2 months ago

Try poweroff, there is a strange issue where sdcard isn't detected in uboot (or nvme in linux) after software reboot

GiovanniBalestrieri commented 2 months ago

Thanks for the quick reply. Power cycled the BPi R3. I am getting the same issue.

This is the output of

BPI-R3> printenv                                                                                                                        
askbootnetfit=run lstftp askkernel;if printenv kernelinput; then setenv bootfile "${kernelinput}"; run bootnetfit;fi                    
askbootnvme=run usenvme; if test "$device" = "nvme"; then run askkernel;if printenv kernelinput; then setenv fit $kernelinput;run newboot;fi;fi
askkernel=askenv kernelinput "enter kernel name:";                                                                                      
board=bpi-r3                                                                                                                            
boot0=run lskernel;run askkernel;if printenv kernelinput ;then setenv fit ${kernelinput}; run newboot; fi;                              
bootargs=board=bpi-r3 earlycon=uart8250,mmio32,0x11002000 debug=7 root=/dev/mmcblk0p6 rootfstype=ext4 rootwait                          
bootcmd=setenv bootdelay 3; run loadenv;bootmenu;                                                                                       
bootconf=#conf-sd#nand#sata                                                                                                             
bootdelay=3                                                                                                                             
bootdevice=sd                                                                                                                           
bootenv=uEnv.txt                                                                                                                        
bootfile=bpi-r3.itb                                                                                                                     
bootmenu_0=1. Enter kernel-name to boot from SD/EMMC.=run boot0                                                                         
bootmenu_1=2. Boot kernel from TFTP.=run askbootnetfit                                                                                  
bootmenu_2=3. Boot from SD/EMMC.=run newboot                                                                                            
bootmenu_3=4. Boot kernel from NVME.=run askbootnvme
bootmenu_default=2
bootnetfit=run checkrd; run setbootconf;run buildargs;if tftp $kaddr ${bootfile}; then bootm ${kaddr}${bootconf};fi
bootnor=run loadnor;run useinitrd;run setbootconf; run buildargs; bootm ${kaddr}${bootconf};
bootopts=debug=7
buildargs=setenv bootargs "board=${board} earlycon=uart8250,mmio32,0x11002000 ${bootopts} root=${root}"
checkenv=test -e ${device} ${partition} ${bootenv}
checkmmc=if mmc partconf 0; then echo "emmc available";mmcdev="emmc";else echo "sd available";mmcdev="sd";fi
checkrd=if printenv initrd;then if fatload ${device} ${partition} ${rdaddr} ${initrd};then run useinitrd;fi;fi
checksata=satacfg=;if test -n "$sata_en";then satacfg="#sata"; fi;
checkspi=if sf probe; then echo "NOR available";spidev="nor";else echo "NAND available";spidev="nand";fi
console=ttyS0,115200n1 earlycon=uart8250,mmio32,0x11002000
device=mmc
ethaddr=ba:c7:31:d6:8c:30
fdtcontroladdr=bf7fca10
fit=bpi-r3.itb
ipaddr=192.168.0.19
kaddr=0x46000000
kernel=bpi-r3.itb
loadaddr=0x46000000
loadenv=if run checkenv;then run loadenvfile;fi
loadenvfile=if fatload ${device} ${partition} ${loadaddr} ${bootenv};then env import -t ${loadaddr} ${filesize};else echo "fatload (${bootenv}) failed";fi
loadkernel=fatload $device $partition $kaddr ${kernel}
loadnor=sf read ${rdaddr} 0x180000 0xa80000;sf read ${kaddr} 0xc00000 0x1400000;
loaduboot=if fatload $device $partition $loadaddr $ubootfile;then go $loadaddr;fi
lskernel=ls ${device} ${partition};
lstftp=if tftp ${loadaddr} ${serverip}:r3-itbfiles.lst;then setexpr listend ${loadaddr} + ${filesize};mw.b ${listend} 00 2;strings ${loadaddr};else echo "tftp download failed";fi
netmask=255.255.255.0
newboot=run checkrd; run setbootconf; run buildargs;if printenv fit;then setenv kernel ${fit};if run loadkernel; then bootm ${kaddr}${bootconf}; fi;fi;
nvme_boot=0:1
nvme_root=/dev/nvme0n1p2
partition=0:5
rdaddr=0x48000000
resetenv=env default -a;printenv;
root=/dev/mmcblk0p6 rootfstype=ext4 rootwait
sata_en=0
serverip=192.168.0.10
setbootconf=run checkmmc checkspi checksata;echo $mmcdev $spidev;setenv bootconf "#conf-$mmcdev$version#$spidev$satacfg"
stderr=serial@11002000
stdin=serial@11002000
stdout=serial@11002000
ubootfile=u-boot.bin
usb_part=0:1
useinitrd=setenv bootopts "${bootopts} initrd=${rdaddr},20M";
usenvme=pci enum; nvme scan;nvme info; if ls nvme $nvme_boot;then setenv device "nvme";setenv partition $nvme_boot;setenv root $nvme_root;else echo "nvme partition not found";fi
useusb=if usb info; then usb reset;else usb start;fi; if ls usb $usb_part $usb_path; then setenv device usb;setenv partition $usb_part;fi
wremmc=if printenv bl2file;then mmc partconf 0 1 1 1;if fatload $device $partition $loadaddr $bl2file;then mmc erase 0x0 0x400;mmc write ${loadaddr} 0x0 0x400;else echo "loading bl2 $bl2file failed";fi;ei
wrfitnor=if printenv fitfile;then if fatload $device $partition ${loadaddr} ${fitfile};then sf erase 0xc00000 0x1400000; sf write ${loadaddr} 0xc00000 ${filesize};else echo "cannot load fitfile ${fitfilei
wrinitnor=if printenv rdfile;then if fatload $device $partition ${loadaddr} ${rdfile};then sf erase 0x180000 0xa80000; sf write ${loadaddr} 0x180000 ${filesize};else echo "cannot load rdfile ${rdfile}";fi
wrspimnand=if printenv bl2file;then if fatload $device $partition $loadaddr $bl2file;then mtd erase spi-nand0 0x0 0x100000;mtd write spi-nand0 $loadaddr 0x0 0x100000;else echo "loading bl2 $bl2file failei
wrspimnor=if printenv bl2file;then if fatload $device $partition $loadaddr $bl2file;then sf erase 0 0x40000;sf write ${loadaddr} 0 0x40000;else echo "loading bl2 $bl2file failed";fi;else echo "bl2file noi

Environment size: 5382/524284 bytes
BPI-R3> 
BPI-R3> run buildargs
BPI-R3> printenv bootargs 
bootargs=board=bpi-r3 earlycon=uart8250,mmio32,0x11002000 debug=7 root=/dev/mmcblk0p6 rootfstype=ext4 rootwait
frank-w commented 2 months ago

Was my image on this card before? Was it completely written? You could try sgdisk fix from my wiki

GiovanniBalestrieri commented 2 months ago

Was my image on this card before?

Yes it worked for quite some time, then I updated and upgraded the system, rebooted and got the error.

Was it completely written?

I assume yes.

You could try sgdisk fix from my wiki

Doing it now. First thing I noticed is that there are a few errors associated with /dev/sde


GPT PMBR size mismatch (15269887 != 249670655) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sde: 119.5 GiB, 127831375872 bytes, 249670656 sectors
Disk model: MassStorageClass
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 43CE453F-1314-45D8-95FD-C5CCD821F662

Device      Start      End  Sectors  Size Type
/dev/sde1      34     8191     8158    4M Linux filesystem
/dev/sde2    8192     9215     1024  512K Linux filesystem
/dev/sde3    9216    13311     4096    2M Linux filesystem
/dev/sde4   13312    17407     4096    2M Linux filesystem
/dev/sde5   17408   222207   204800  100M Linux filesystem
/dev/sde6  222208 13739008 13516801  6.5G Linux filesystem

And the output of gdisk:

userk@dopamine:~$ sudo gdisk  -l /dev/sde
GPT fdisk (gdisk) version 1.0.5

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sde: 249670656 sectors, 119.1 GiB
Model: MassStorageClass
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 43CE453F-1314-45D8-95FD-C5CCD821F662
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 15269854
Partitions will be aligned on 2-sector boundaries
Total free space is 1530846 sectors (747.5 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              34            8191   4.0 MiB     8300  bl2
   2            8192            9215   512.0 KiB   8300  u-boot-env
   3            9216           13311   2.0 MiB     8300  factory
   4           13312           17407   2.0 MiB     8300  fip
   5           17408          222207   100.0 MiB   8300  boot
   6          222208        13739008   6.4 GiB     8300  rootfs

Question Which wiki are you referring to?

GiovanniBalestrieri commented 2 months ago

I run gdisk on /dev/sde to fix the problem with no luck. Could you point me to the wiki you were referring to?

i found an answer to an old post where you mentioned sgdisk.

userk@dopamine:~$ sudo gdisk  /dev/sde
GPT fdisk (gdisk) version 1.0.5

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): ? 
b   back up GPT data to a file
c   change a partition's name
d   delete a partition
i   show detailed information on a partition
l   list known partition types
n   add a new partition
o   create a new empty GUID partition table (GPT)
p   print the partition table
q   quit without saving changes
r   recovery and transformation options (experts only)
s   sort partitions
t   change a partition's type code
v   verify disk
w   write table to disk and exit
x   extra functionality (experts only)
?   print this menu

Command (? for help): x

Expert command (? for help): ?
a   set attributes
c   change partition GUID
d   display the sector alignment value
e   relocate backup data structures to the end of the disk
f   randomize disk and partition unique GUIDs
g   change disk GUID
h   recompute CHS values in protective/hybrid MBR
i   show detailed information on a partition
j   move the main partition table
l   set the sector alignment value
m   return to main menu
n   create a new protective MBR
o   print protective MBR data
p   print the partition table
q   quit without saving changes
r   recovery and transformation options (experts only)
s   resize partition table
t   transpose two partition table entries
u   replicate partition table on new device
v   verify disk
w   write table to disk and exit
z   zap (destroy) GPT data structures and exit
?   print this menu

Expert command (? for help): w
Warning! Secondary header is placed too early on the disk! Do you want to
correct this problem? (Y/N): Y
Have moved second header and partition table to correct location.

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sde.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.

Same issue:

## Error: "initrd" not defined
PARTITION_CONFIG only exists on eMMC
sd available
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: ff, ef, aa
Failed to initialize SPI flash at 0:0 (error 0)
NAND available
sd nand
fit=bpi-r3.itb
** No partition table - mmc 0 **
Couldn't find partition mmc 0:5
Can't set block device
BPI-R3> 
frank-w commented 2 months ago

Let r3 off for some minutes, that helped me always (but i had it rarely). Which vendor of sdcard do you use?

GiovanniBalestrieri commented 2 months ago

SanDisk 128 Gb. I left it overnight, I turned it on, it worked.

Then I added mt7915e entry in the/etc/modules file rebooted. Dead again.

I just cannot work with it. There must be something wrong

frank-w commented 2 months ago

Of course something is wron,but i guess it is different clock config between linux and uboot...but i did not found it and have this issue really rarely,so can't reproduce/force it for deeper digging

GiovanniBalestrieri commented 2 months ago

I’m in the process of creating a new image to see if the issue can be reproduced. After running the command $./buildimg.sh bpi-r3 bookworm .

I’m currently writing the image with the following command: $ gunzip -c bpi-r3_bookworm_6.6.45-main.img.gz | sudo dd bs=1M status=progress conv=notrunc,fsync of=/dev/sde

I will provide an update once the write operation is complete. If there’s anything I should be doing differently, please let me know.

GiovanniBalestrieri commented 2 months ago

The write operation completed successfully:

$ gunzip -c bpi-r3_bookworm_6.6.45-main.img.gz | sudo dd bs=1M status=progress conv=notrunc,fsync of=/dev/sde
2674720768 bytes (2.7 GB, 2.5 GiB) copied, 176 s, 15.2 MB/s
7808679936 bytes (7.8 GB, 7.3 GiB) copied, 544 s, 14.4 MB/s
0+202934 records in
0+202934 records out
7818182656 bytes (7.8 GB, 7.3 GiB) copied, 593.959 s, 13.2 MB/s

However, when I insert the SD card into the BPI-R3, I encounter the following issue:

F0: 102B 0000
FA: 1040 0000
FA: 1040 0000 [0200]
F9: 103F 0000
F3: 1001 0000 [0200]
F3: 1001 0000
F6: 300C 0028
F5: 480A 0031
00: 1005 0000
FA: 1040 0000
FA: 1040 0000 [0200]
F9: 103F 0000
F3: 1001 0000 [0200]
F3: 1001 0000
F6: 300C 0028
01: 102A 0001
02: 1005 0000
BP: 2000 00C0 [0001]
EC: 0000 0000 [3000]
T0: 0000 010F [010F]
System halt!

Is there a specific way I should be preparing the SD card to avoid this issue?

frank-w commented 2 months ago

Really wait till all data is written...e.g. calling sync

GiovanniBalestrieri commented 2 months ago

Running the gunzip and dd command again. I will leave it as it is.

I will update the comment when done

GiovanniBalestrieri commented 2 months ago
userk@dopamine:~/development/git/BPI-Router-Images$ gunzip -c bpi-r3_bookworm_6.6.45-main.img.gz | sudo dd bs=1M status=progress conv=notrunc,fsync of=/dev/sde
7806517248 bytes (7.8 GB, 7.3 GiB) copied, 550 s, 14.2 MB/s
0+202392 records in
0+202392 records out
7818182656 bytes (7.8 GB, 7.3 GiB) copied, 595.087 s, 13.1 MB/s
userk@dopamine:~/development/git/BPI-Router-Images$ sudo gparted

Same System Halt issue:

F0: 102B 0000
FA: 1040 0000
FA: 1040 0000 [0200]
F9: 103F 0000
F3: 1001 0000 [0200]
F3: 1001 0000
F6: 300C 0028
F5: 480A 0032
00: 1005 0000
FA: 1040 0000
FA: 1040 0000 [0200]
F9: 103F 0000
F3: 1001 0000 [0200]
F3: 1001 0000
F6: 300C 0028
01: 102A 0001
02: 1005 0000
BP: 2000 00C0 [0001]
EC: 0000 0000 [3000]
T0: 0000 0585 [010F]
System halt!

This is the screeshot of gparted. Any idea of what I am doing wrong?

Screenshot from 2024-08-12 22-15-52

frank-w commented 2 months ago

Gpt looks right...are the switches on board on right position and card correctly inserted? Your output is only bootrom...not even bl2 is found so strange...this is part of the base image which is downloaded from my uboot repo and should be ok

frank-w commented 2 months ago

You can try do a hexdump of first 1M of your card which should show a sdmmc header in the first bytes

GiovanniBalestrieri commented 2 months ago

are the switches on board on right position and card correctly inserted?

Yes, double checked. Switched are all up.

You can try do a hexdump of first 1M of your card which should show a sdmmc header in the first bytes

I wasn't sure how to check the sdmmc header with hexdump.

I tried this approach:

sudo hexdump -C -n 1048576 /dev/sde | grep -C 50 'sdmmc'

0002bdb0  37 31 35 34 63 66 36 36  34 20 73 64 6d 6d 63 00  |7154cf664 **sdmmc**.|
0002bdc0  0a 42 4c 32 3a 20 46 61  69 6c 75 72 65 20 69 6e  |.BL2: Failure in|
0002bdd0  20 70 72 65 20 69 6d 61  67 65 20 6c 6f 61 64 20  | pre image load |
0002bde0  68 61 6e 64 6c 69 6e 67  20 28 25 69 29 0a 00 0a  |handling (%i)...|
0002bdf0  42 4c 32 3a 20 46 61 69  6c 65 64 20 74 6f 20 6c  |BL2: Failed to l|
0002be00  6f 61 64 20 69 6d 61 67  65 20 69 64 20 25 75 20  |oad image id %u |
0002be10  28 25 69 29 0a 00 0a 42  4c 32 3a 20 46 61 69 6c  |(%i)...BL2: Fail|
0002be20  75 72 65 20 69 6e 20 70  6f 73 74 20 69 6d 61 67  |ure in post imag|
0002be30  65 20 6c 6f 61 64 20 68  61 6e 64 6c 69 6e 67 20  |e load handling |
0002be40  28 25 69 29 0a 00 0a 42  4c 32 3a 20 46 61 69 6c  |(%i)...BL2: Fail|
0002be50  75 72 65 20 69 6e 20 75  70 64 61 74 69 6e 67 20  |ure in updating |
0002be60  61 6e 74 69 2d 72 6f 6c  6c 62 61 63 6b 20 76 65  |anti-rollback ve|
0002be70  72 73 69 6f 6e 20 28 25  69 29 0a 00 14 42 4c 32  |rsion (%i)...BL2|
0002be80  3a 20 25 73 0a 00 14 42  4c 32 3a 20 42 6f 6f 74  |: %s...BL2: Boot|
0002be90  69 6e 67 20 42 4c 33 31  0a 00 0a 46 61 69 6c 65  |ing BL31...Faile|
0002bea0  64 20 74 6f 20 64 65 63  6f 6d 70 72 65 73 73 20  |d to decompress |
0002beb0  69 6d 61 67 65 20 28 65  72 72 3d 25 64 29 0a 00  |image (err=%d)..|
0002bec0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0002bed0  0a 43 4d 44 31 33 20 66  61 69 6c 65 64 20 61 66  |.CMD13 failed af|
0002bee0  74 65 72 20 25 64 20 72  65 74 72 69 65 73 0a 00  |ter %d retries..|
0002bef0  0a 43 4d 44 31 20 66 61  69 6c 65 64 20 61 66 74  |.CMD1 failed aft|
0002bf00  65 72 20 25 64 20 72 65  74 72 69 65 73 0a 00 0a  |er %d retries...|
0002bf10  41 43 4d 44 34 31 20 66  61 69 6c 65 64 20 61 66  |ACMD41 failed af|
0002bf20  74 65 72 20 25 64 20 72  65 74 72 69 65 73 0a 00  |ter %d retries..|
0002bf30  0a 41 43 4d 44 35 31 20  66 61 69 6c 65 64 20 61  |.ACMD51 failed a|
0002bf40  66 74 65 72 20 25 64 20  72 65 74 72 69 65 73 20  |fter %d retries |
0002bf50  28 72 65 74 3d 25 64 29  0a 00 00 0a 0c 0d 0f 14  |(ret=%d)........|
0002bf60  19 1e 23 28 2d 32 37 3c  46 50 00 0a 0c 0d 0f 14  |..#(-27<FP......|
0002bf70  1a 1e 23 28 2d 34 37 3c  46 50 45 46 49 20 50 41  |..#(-47<FPEFI PA|
0002bf80  52 54 00 0a 49 6e 76 61  6c 69 64 20 47 50 54 20  |RT..Invalid GPT |
0002bf90  48 65 61 64 65 72 20 43  52 43 3a 20 45 78 70 65  |Header CRC: Expe|
0002bfa0  63 74 65 64 20 30 78 25  78 20 62 75 74 20 67 6f  |cted 0x%x but go|
0002bfb0  74 20 30 78 25 78 2e 0a  00 0a 78 7a 3a 20 78 7a  |t 0x%x....xz: xz|
0002bfc0  5f 64 65 63 5f 69 6e 69  74 28 29 20 66 61 69 6c  |_dec_init() fail|
0002bfd0  65 64 0a 00 0a 78 7a 3a  20 78 7a 5f 64 65 63 5f  |ed...xz: xz_dec_|
0002bfe0  72 75 6e 28 29 20 66 61  69 6c 65 64 20 28 65 72  |run() failed (er|
0002bff0  72 20 3d 20 25 75 29 0a  00 fd 37 7a 58 5a 00 59  |r = %u)...7zXZ.Y|
0002c000  5a 00 66 69 70 00 0a 50  61 72 74 69 74 69 6f 6e  |Z.fip..Partition|
0002c010  20 27 66 69 70 27 20 6e  6f 74 20 66 6f 75 6e 64  | 'fip' not found|
0002c020  0a 00 0a 46 49 50 20 62  6f 6f 74 20 73 6f 75 72  |...FIP boot sour|
0002c030  63 65 20 69 6e 69 74 69  61 6c 69 7a 61 74 69 6f  |ce initializatio|
0002c040  6e 20 66 61 69 6c 65 64  20 77 69 74 68 20 25 64  |n failed with %d|
0002c050  0a 00 47 d4 08 6d 4c fe  98 46 9b 95 29 50 cb bd  |..G..mL..F..)P..|
0002c060  5a 00 05 d0 e1 89 53 dc  13 47 8d 2b 50 0a 4b 7a  |Z.....S..G.+P.Kz|
0002c070  3e 38 d6 d0 ee a7 fc ea  d5 4b 97 82 99 34 f2 34  |>8.......K...4.4|
0002c080  b6 e4 04 04 00 04 05 00  0a 02 05 00 0a 02 0a 4d  |...............M|
0002c090  53 44 43 3a 20 52 65 61  64 20 64 61 74 61 20 73  |SDC: Read data s|
0002c0a0  69 7a 65 20 65 78 63 65  65 64 73 20 70 72 65 70  |ize exceeds prep|
0002c0b0  61 72 65 64 20 73 69 7a  65 0a 00 0a 4d 53 44 43  |ared size...MSDC|
0002c0c0  3a 20 43 52 43 20 65 72  72 6f 72 20 6f 63 63 75  |: CRC error occu|
0002c0d0  72 65 64 20 77 68 69 6c  65 20 72 65 61 64 69 6e  |red while readin|
frank-w commented 2 months ago

It shold be on beginning,but uppercase...

Something like this

dd if=/dev/sde bs=1M count=1 | hexdump -C | less
GiovanniBalestrieri commented 2 months ago

[...]
0002bdb0  37 31 35 34 63 66 36 36  34 20 73 64 6d 6d 63 00  |7154cf664 sdmmc.|
002bdc0  0a 42 4c 32 3a 20 46 61  69 6c 75 72 65 20 69 6e  |.BL2: Failure in|
0002bdd0  20 70 72 65 20 69 6d 61  67 65 20 6c 6f 61 64 20  | pre image load |
0002bde0  68 61 6e 64 6c 69 6e 67  20 28 25 69 29 0a 00 0a  |handling (%i)...|
0002bdf0  42 4c 32 3a 20 46 61 69  6c 65 64 20 74 6f 20 6c  |BL2: Failed to l|
0002be00  6f 61 64 20 69 6d 61 67  65 20 69 64 20 25 75 20  |oad image id %u |
0002be10  28 25 69 29 0a 00 0a 42  4c 32 3a 20 46 61 69 6c  |(%i)...BL2: Fail|
0002be20  75 72 65 20 69 6e 20 70  6f 73 74 20 69 6d 61 67  |ure in post imag|
0002be30  65 20 6c 6f 61 64 20 68  61 6e 64 6c 69 6e 67 20  |e load handling |
0002be40  28 25 69 29 0a 00 0a 42  4c 32 3a 20 46 61 69 6c  |(%i)...BL2: Fail|
0002be50  75 72 65 20 69 6e 20 75  70 64 61 74 69 6e 67 20  |ure in updating |
0002be60  61 6e 74 69 2d 72 6f 6c  6c 62 61 63 6b 20 76 65  |anti-rollback ve|
0002be70  72 73 69 6f 6e 20 28 25  69 29 0a 00 14 42 4c 32  |rsion (%i)...BL2|
0002be80  3a 20 25 73 0a 00 14 42  4c 32 3a 20 42 6f 6f 74  |: %s...BL2: Boot|
0002be90  69 6e 67 20 42 4c 33 31  0a 00 0a 46 61 69 6c 65  |ing BL31...Faile|
0002bea0  64 20 74 6f 20 64 65 63  6f 6d 70 72 65 73 73 20  |d to decompress |
0002beb0  69 6d 61 67 65 20 28 65  72 72 3d 25 64 29 0a 00  |image (err=%d)..|
0002bec0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0002bed0  0a 43 4d 44 31 33 20 66  61 69 6c 65 64 20 61 66  |.CMD13 failed af|
0002bee0  74 65 72 20 25 64 20 72  65 74 72 69 65 73 0a 00  |ter %d retries..|
0002bef0  0a 43 4d 44 31 20 66 61  69 6c 65 64 20 61 66 74  |.CMD1 failed aft|
0002bf00  65 72 20 25 64 20 72 65  74 72 69 65 73 0a 00 0a  |er %d retries...|
0002bf10  41 43 4d 44 34 31 20 66  61 69 6c 65 64 20 61 66  |ACMD41 failed af|
0002bf20  74 65 72 20 25 64 20 72  65 74 72 69 65 73 0a 00  |ter %d retries..|
0002bf30  0a 41 43 4d 44 35 31 20  66 61 69 6c 65 64 20 61  |.ACMD51 failed a|
0002bf40  66 74 65 72 20 25 64 20  72 65 74 72 69 65 73 20  |fter %d retries |
0002bf50  28 72 65 74 3d 25 64 29  0a 00 00 0a 0c 0d 0f 14  |(ret=%d)........|
0002bf60  19 1e 23 28 2d 32 37 3c  46 50 00 0a 0c 0d 0f 14  |..#(-27<FP......|
0002bf70  1a 1e 23 28 2d 34 37 3c  46 50 45 46 49 20 50 41  |..#(-47<FPEFI PA|
0002bf80  52 54 00 0a 49 6e 76 61  6c 69 64 20 47 50 54 20  |RT..Invalid GPT |
0002bf90  48 65 61 64 65 72 20 43  52 43 3a 20 45 78 70 65  |Header CRC: Expe|
0002bfa0  63 74 65 64 20 30 78 25  78 20 62 75 74 20 67 6f  |cted 0x%x but go|
0002bfb0  74 20 30 78 25 78 2e 0a  00 0a 78 7a 3a 20 78 7a  |t 0x%x....xz: xz|
0002bfc0  5f 64 65 63 5f 69 6e 69  74 28 29 20 66 61 69 6c  |_dec_init() fail|
0002bfd0  65 64 0a 00 0a 78 7a 3a  20 78 7a 5f 64 65 63 5f  |ed...xz: xz_dec_|
0002bfe0  72 75 6e 28 29 20 66 61  69 6c 65 64 20 28 65 72  |run() failed (er|
0002bff0  72 20 3d 20 25 75 29 0a  00 fd 37 7a 58 5a 00 59  |r = %u)...7zXZ.Y|
0002c000  5a 00 66 69 70 00 0a 50  61 72 74 69 74 69 6f 6e  |Z.fip..Partition|
0002c010  20 27 66 69 70 27 20 6e  6f 74 20 66 6f 75 6e 64  | 'fip' not found|
0002c020  0a 00 0a 46 49 50 20 62  6f 6f 74 20 73 6f 75 72  |...FIP boot sour|
0002c030  63 65 20 69 6e 69 74 69  61 6c 69 7a 61 74 69 6f  |ce initializatio|
0002c040  6e 20 66 61 69 6c 65 64  20 77 69 74 68 20 25 64  |n failed with %d|
0002c050  0a 00 47 d4 08 6d 4c fe  98 46 9b 95 29 50 cb bd  |..G..mL..F..)P..|
0002c060  5a 00 05 d0 e1 89 53 dc  13 47 8d 2b 50 0a 4b 7a  |Z.....S..G.+P.Kz|
0002c070  3e 38 d6 d0 ee a7 fc ea  d5 4b 97 82 99 34 f2 34  |>8.......K...4.4|
0002c080  b6 e4 04 04 00 04 05 00  0a 02 05 00 0a 02 0a 4d  |...............M|
0002c090  53 44 43 3a 20 52 65 61  64 20 64 61 74 61 20 73  |SDC: Read data s|
0002c0a0  69 7a 65 20 65 78 63 65  65 64 73 20 70 72 65 70  |ize exceeds prep|
0002c0b0  61 72 65 64 20 73 69 7a  65 0a 00 0a 4d 53 44 43  |ared size...MSDC|
0002c0c0  3a 20 43 52 43 20 65 72  72 6f 72 20 6f 63 63 75  |: CRC error occu|
0002c0d0  72 65 64 20 77 68 69 6c  65 20 72 65 61 64 69 6e  |red while readin|
0002c0e0  67 20 64 61 74 61 20 77  69 74 68 20 63 6d 64 3d  |g data with cmd=|

[...]
frank-w commented 2 months ago

SDMMC_BOOT should be near offset 0x0 and if the bootswitches are right it should be found by bootrom

GiovanniBalestrieri commented 2 months ago

Found the relevant part:

00000600  af 3d c6 0f 83 84 72 47  8e 79 3d 69 d8 47 7d e4  |.=....rG.y=i.G}.|
00000610  05 75 9f aa bd 2c 37 4f  ba 6b c3 08 c8 6f 46 1a  |.u...,7O.k...oF.|
00000620  00 44 00 00 00 00 00 00  ff 63 03 00 00 00 00 00  |.D.......c......|
00000630  00 00 00 00 00 00 00 00  62 00 6f 00 6f 00 74 00  |........b.o.o.t.|
00000640  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000680  af 3d c6 0f 83 84 72 47  8e 79 3d 69 d8 47 7d e4  |.=....rG.y=i.G}.|
00000690  74 98 f0 a0 91 f7 5c 4d  a3 18 c7 4e ea 74 55 48  |t.....\M...N.tUH|
000006a0  00 64 03 00 00 00 00 00  00 a4 d1 00 00 00 00 00  |.d..............|
000006b0  00 00 00 00 00 00 00 00  72 00 6f 00 6f 00 74 00  |........r.o.o.t.|
000006c0  66 00 73 00 00 00 00 00  00 00 00 00 00 00 00 00  |f.s.............|
000006d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00004400  53 44 4d 4d 43 5f 42 4f  4f 54 00 ff 01 00 00 00  |SDMMC_BOOT......|
00004410  00 02 00 00 ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00004420  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00004600  42 52 4c 59 54 00 00 00  01 00 00 00 00 06 00 00  |BRLYT...........|
00004610  68 10 03 00 42 42 42 42  08 00 01 00 00 06 00 00  |h...BBBB........|
00004620  68 10 03 00 ff ff ff ff  ff ff ff ff ff ff ff ff  |h...............|
00004630  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00004a00  4d 4d 4d 01 38 00 00 00  46 49 4c 45 5f 49 4e 46  |MMM.8...FILE_INF|
00004a10  4f 00 00 00 01 00 00 00  01 00 05 01 00 0d 20 00  |O............. .|
00004a20  68 0a 03 00 68 10 03 00  00 03 00 00 20 00 00 00  |h...h....... ...|
00004a30  00 03 00 00 01 00 00 00  4d 4d 4d 01 0c 00 01 00  |........MMM.....|
00004a40  01 00 00 00 4d 4d 4d 03  64 00 07 00 90 11 00 00  |....MMM.d.......|
00004a50  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00004a90  00 00 00 00 00 00 00 00  00 64 00 00 88 13 00 00  |.........d......|
00004aa0  00 00 00 00 00 00 00 00  4d 4d 4d 01 14 02 03 00  |........MMM.....|
00004ab0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00004cb0  00 00 00 00 00 00 00 00  00 00 00 00 4d 4d 4d 01  |............MMM.|
00004cc0  14 00 02 00 00 00 00 00  10 00 00 00 80 00 00 00  |................|
00004cd0  4d 4d 4d 01 30 00 08 00  03 00 00 00 00 00 00 00  |MMM.0...........|
00004ce0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
GiovanniBalestrieri commented 2 months ago

I’ve ordered some new micro SD cards and will give it another try once they arrive.

GiovanniBalestrieri commented 2 months ago

I ve tried with three brand new sd cards. Same error.

sudo fdisk -l returns:

GPT PMBR size mismatch (15269887 != 246947839) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sde: 117.77 GiB, 126437294080 bytes, 246947840 sectors
Disk model: MassStorageClass
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: EC5B6133-03E2-4A47-A613-D1AFEF156B57

Device      Start      End  Sectors  Size Type
/dev/sde1      34     8191     8158    4M Linux filesystem
/dev/sde2    8192     9215     1024  512K Linux filesystem
/dev/sde3    9216    13311     4096    2M Linux filesystem
/dev/sde4   13312    17407     4096    2M Linux filesystem
/dev/sde5   17408   222207   204800  100M Linux filesystem
/dev/sde6  222208 13739008 13516801  6.5G Linux filesystem
frank-w commented 2 months ago

This is normally no problem. It is caused by image uses fixed size of underlying storage and so it does not match the device you flash image to...

Also there is normally a backup gpt at the end of the disk which also causes similar warnings and can be corrected with sgdisk

GiovanniBalestrieri commented 2 months ago

Changed microSD adapter, microSD reader and computer. Now I am getting the following and the system boots. I ll use it for a few days and eventually mark the issue as Solved.

F0: 102B 0000                                                                                                                                                                                              
FA: 1040 0000                                                                                                                                                                                              
FA: 1040 0000 [0200]                                                                                                                                                                                       
F9: 103F 0000                                                                                                                                                                                              
F3: 1001 0000 [0200]                                                                                                                                                                                       
F3: 1001 0000                                                                                                                                                                                              
F6: 300C 0028                                                                                                                                                                                              
F5: 0000 0000                                                                                                                                                                                              
V0: 0000 0000 [0001]                                                                                                                                                                                       
00: 0000 0000                                                                                                                                                                                              
BP: 2400 0041 [0000]                                                                                                                                                                                       
G0: 1190 0000                                                                                                                                                                                              
EC: 0000 0000 [3000]                                                                                                                                                                                       
## Error: "initrd" not defined                                                                       
PARTITION_CONFIG only exists on eMMC                                                                                                                                                                       
sd available                                                                                         
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: ff, ef, aa                                                                                                                                           
Failed to initialize SPI flash at 0:0 (error -2)                                                                                                                                                           
NAND available                                                                                                                                                                                             
sd nand                                                                                                                                                                                                    
fit=bpi-r3.itb                                                                                                                                                                                             
9102564 bytes read in 579 ms (15 MiB/s)
## Loading kernel from FIT Image at 46000000 ...
   Using 'conf-sd' configuration
   Trying 'kernel-1' kernel subimage
     Description:  Linux Kernel 6.6.47-main
GiovanniBalestrieri commented 2 months ago

Rebooted and got stuck with this error message:

## Error: "initrd" not defined
PARTITION_CONFIG only exists on eMMC
sd available
jedec_spi_nor spi_nor@0: unrecognized JEDEC id bytes: ff, ef, aa
Failed to initialize SPI flash at 0:0 (error -2)
NAND available
sd nand
fit=bpi-r3.itb
Error reading cluster
Failed to load 'bpi-r3.itb'
BPI-R3> 

Looks like a rabbit hole

frank-w commented 2 months ago

Powerdown and wait some few minutes...

GiovanniBalestrieri commented 2 months ago

Waited one minute. It is booting up.

frank-w commented 2 months ago

You can look for mmc info when having this ...i had it not very often but saw mmc controller was only 1bit instead of 4...i guess clocks are different in linux/uboot but they looked same...with newer uboot we make clocks same and using linux dts...only need to solve the overlay build problem in uboot

GiovanniBalestrieri commented 2 months ago

If this approach proves to be consistently reliable and stable, I'm okay with closing the issue. However, I'm genuinely interested in helping to resolve this problem for good, as I've become quite invested in this repository and your work. Since it seems like I can reliably reproduce the issue, please let me know how I can assist in finding a permanent solution. I'm eager to collaborate and help out in any way I can.

GiovanniBalestrieri commented 2 months ago

Thank you for the detailed explanation! To help solve this, I'll start by consistently reproducing the issue and documenting when the MMC controller switches to 1-bit mode. I'll also compare the clock settings between Linux and U-Boot as you suggested.

If there's anything specific you'd like me to look into regarding the overlay build problem in U-Boot or other areas, please let me know. I'm eager to help out and work together to resolve this issue once and for all.

I have a limited understanding of the components involved in this issue. I need some guidance

frank-w commented 2 months ago

I'm also not deep enough in these things and had the issue not often enough to trace it to its root

If you deep enough in makefiles...i have uboot to build the dtbo with of_upstream and want the fdtoverlay call now to merge defined dtbo to base dt

https://github.com/frank-w/u-boot/commits/2024-07-bpi-ofupstream-all/

Used some code from linux,but it requires targets for dtbo i do not have as thes compiled without target (there is no makefile listing all dtbo,i compile all for current soc)

In this file you see what i do for dtbo (disabled the fdtoverlay command to fix build for now)

https://github.com/frank-w/u-boot/commit/3d1b891f651a3148ffd91c4c87be99af6caa2fc4

Which is defined here: https://github.com/frank-w/u-boot/commit/f44a0d84c646903c9e896caca1b83be55840713c

I just want to call fdtoverlay with basedt and all dtbos from config option