Rebuilt kernel does not boot complains "Bad Linux RISCV Image magic!"

Hi !

I try to recompile the current vf2 kernel from github. It seems to be 6.8.0-rc2

When i try to boot it i get the following log:

U-Boot menu
1: Debian GNU/Linux bookworm/sid 5.15.0-starfive NVME
2: Debian GNU/Linux bookworm/sid vmlinuz-6.1.31 NVME default
3: Debian GNU/Linux bookworm/sid 6.8 NVME
Enter choice: 3
3: Debian GNU/Linux bookworm/sid 6.8 NVME
Retrieving file: /initrd.img-6.8.0-rc2-visionfive-g35960454d7db
5135906 bytes read in 30 ms (163.3 MiB/s)
Retrieving file: /vmlinuz-6.8.0-rc2-visionfive-g35960454d7db
6263296 bytes read in 36 ms (165.9 MiB/s)
append: root=/dev/nvme0n1p4 rw console=tty0 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0
Retrieving file: /dtbs/starfive/jh7110-visionfive-v2.dtb
48366 bytes read in 5 ms (9.2 MiB/s)
Bad Linux RISCV Image magic!
1: Debian GNU/Linux bookworm/sid 5.15.0-starfive NVME
Retrieving file: /initrd.img-5.15.0-starfive
5153484 bytes read in 35 ms (140.4 MiB/s)
Retrieving file: /vmlinuz-5.15.0-starfive
8420005 bytes read in 52 ms (154.4 MiB/s)
append: root=/dev/nvme0n1p4 rw console=tty0 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0
Retrieving file: /dtbs/starfive/jh7110-visionfive-v2.dtb
48366 bytes read in 6 ms (7.7 MiB/s)
Uncompressing Kernel Image
Moving Image from 0x44000000 to 0x40200000, end=41973000

So it seems u-boot does not want to boot the kernel.
Inspecting the kernel file i can see that the magic RISCV header is missing:
zless vmlinuz-5.15.0-starfive yields:
MZo^P`^L^A^@^@^@ ^@^@^@^@^@^@0w^A^@^@^@^@^@^@^@^@^@^@^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@RISCV^@^@^@RSC^E@^@^@^@PE^@^@dP^B^@^@^@^@^@^@^
as first line, zless vmlinuz-6.8.0-rc2-visionfive-g35960454d7db yields:
MZ^@^@zimg&^A^@<93>=^^@^@^@^@^@^@^@^@^@zstd22^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@#<82><81>@^@^@^@PE^@^@dP^B^@^@^@^@^@^

So i conclude that my kernel has the wrong magic header, thus u-boot refuses to boot it.
The kernel was built on a Linux starfive 5.15.0-starfive #1 SMP Sun Mar 26 12:29:48 EDT 2023 riscv64 GNU/Linux system doing:
git clone GitHub - starfive-tech/linux
cd linux
cp arch/riscv/configs/starfive_visionfive2_defconfig .config
make olddefconfig
make -j4 bindeb-pkg

Any ideas what i did wrong ?

1 Like

Could you post your .config file on github gist or pastebin and then post the link here?

You must have CONFIG_EFI_ZBOOT enabled during kernel build. Try disable that.

No config on my side involved. Just the starfive_visionfive2_defconfig in a fresh github kernel tree. I ran exactly the commands posted above. I would understand that tinkering with the config might lead to unpredictable results, but i just downloaded the tree from github and compiled with default defconfig.

that seems to be enabled in the visionfive_defconfig:

user@starfive:~/kernel/linux$ grep CONFIG_EFI_ZBOOT arch/riscv/configs/visionfive_defconfig CONFIG_EFI_ZBOOT=y

well, i used arch/riscv/configs/visionfive_defconfig as there is no starfive_visionfive2_defconfig in the repo

you were right, disabling CONFIG_EFI_ZBOOT made u-boot load the kernel.

thanks a lot for the help, its still not booting and dies with kernel panic, but now i at least i get the kernel loaded. :slight_smile:

Early memory node ranges
node 0: [mem 0x0000000040000000-0x000000004007ffff]
node 0: [mem 0x0000000040080000-0x00000000c010ffff]
node 0: [mem 0x00000000c0110000-0x00000000c01fffff]
node 0: [mem 0x00000000c0200000-0x000000023fffffff]
Initmem setup node 0 [mem 0x0000000040000000-0x000000023fffffff]
SBI HSM extension detected
CPU with hartid=0 is not available
CPU with hartid=1 is invalid: this kernel does not parse “riscv,isa”
CPU with hartid=2 is invalid: this kernel does not parse “riscv,isa”
CPU with hartid=3 is invalid: this kernel does not parse “riscv,isa”
CPU with hartid=4 is invalid: this kernel does not parse “riscv,isa”
------------[ cut here ]------------
kernel BUG at arch/riscv/kernel/smpboot.c:158!
Kernel BUG [#1]
CPU: 0 PID: 0 Comm: swapper Not tainted 6.8.0-rc2-visionfive-g35960454d7db #4
Hardware name: StarFive VisionFive V2 (DT)
epc : setup_smp+0x8c/0xea
ra : setup_smp+0x84/0xea
epc : ffffffff80803fe6 ra : ffffffff80803fde sp : ffffffff81203e30
gp : ffffffff812d32e8 tp : ffffffff81209c80 t0 : 0000226173692c76
t1 : 0000000000000022 t2 : 2c76637369722220 s0 : 0000000000000000
s1 : 0000000000000001 a0 : 0000000000000000 a1 : 0000000000000000
a2 : 00000000ffffefff a3 : 0000000000000147 a4 : 0000000000000000
a5 : 0000000000000148 a6 : ffffffff81307df0 a7 : 0000000000000000
s2 : 0000000000000000 s3 : ffffffff80eabc30 s4 : 0000000000000003
s5 : 00000000f7fd2470 s6 : 0000000000000000 s7 : 0000000000000000
s8 : 00000000f7f0d1ee s9 : 00000000f7f8ea28 s10: 00000000f7718fb0
s11: 0000000000000000 t3 : ffffffff812e5f04 t4 : ffffffff812e5f04
t5 : ffffffff812e5ec0 t6 : ffffffff81203c90
status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003
[] setup_smp+0x8c/0xea
[] setup_arch+0xdc/0x118
[] start_kernel+0x78/0x61e
Code: 4905 8522 7097 ffdc 80e7 9a60 842a b775 1363 0009 (9002) 8413
—[ end trace 0000000000000000 ]—
Kernel panic - not syncing: Fatal exception in interrupt

Probably you are on a different branch. I’m using origin/JH7110_VisionFive2_upstream

1 Like

And again you are right, i used the wrong branch.
well, one should never stop learning. :slight_smile:

sorry for the noise, cheers, k

2 Likes

Can you boot from NVME ?
I compiled JH7110_VisionFive2_6.1.y_devel using arch/riscv/configs/starfive_visionfive2_defconfig and i can not see any nvme devices once booted into initramfs.
I then tried to enable all NVME kernel options that are enabled in the stock kernel taken from config-5.15.0-starfive, but still no /dev/nvme0n1p4 in initramfs.

Anything else i need to enable ?
Thanks for your help !

1 Like