[HELP] Need help about quemu + u-root + x86 Linux kernel running in sd card like quemu + grub2 + x86 Linux kernel way

黄蓉刚 happy.every.day at 126.com
Sat Nov 19 05:53:14 CET 2022


November 19, 2022




Dear All,




Execute me. I need your help.




I am interested in qemu x86_64 and I have a problem that I want to input u-boot into a sdcard file and start Linux with the sdcard file, like grub-install(grub2) way.




The grub2 method (Method 1) is right, I want to use u-boot method (Method 2) to bootloader Linux kernel in x86. I guess that it needs write a program like grub-install to reach this aim.




Please help me to give a clear way like grub-install way. Thanks!




My steps:

cd ~/Code/kernel_sources

git clone https://github.com/qemu/u-boot.git

git checkout v2022.10-rc4

git reset --hard




cd ~/Code/kernel_sources/u-boot

export ARCH=arm

export CROSS_COMPILE=arm-linux-gnueabi-

make distclean

make vexpress_ca9x4_defconfig

make -j4 all




# Busybox and rootfs is ready

...




# Kernel

cd ~/Code/kernel_sources/linux-4.19.256

export ARCH=arm

export CROSS_COMPILE=arm-linux-gnueabi-

make clean

make bzImage -j2 ARCH=arm CROSS_COMPLIE=arm-linux-gnueabi-

make dtbs




cd ~/Code/kernel_sources/linux-4.19.256

# Create rootfs.img

sudo sh -c 'find . | cpio -o --format=newc >  ../initrd.img'




# Common disk method

cd ~/Code/kernel_sources/linux-4.19.256

rm -rf busybox_u-boot_64M_4.19.256.img

dd if=/dev/zero of=busybox_u-boot_64M_4.19.256.img bs=1 seek=63MiB count=1024




cd ~/Code/kernel_sources/linux-4.19.256

sudo parted busybox_u-boot_64M_4.19.256.img

mklabel msdos

mkpart primary ext4 2MiB 98%

toggle 1 boot

print

quit

sudo kpartx -a busybox_u-boot_64M_4.19.256.img

echo y | sudo mkfs.ext4 /dev/mapper/loop0p1

cd ~/Code/kernel_sources/linux-4.19.256

sudo rm -rf /mnt/rootfs/*

sudo mkdir -p /mnt/rootfs/boot/

sudo cp arch/arm/boot/zImage /mnt/rootfs/boot/zImage

sudo cp initrd.img /mnt/rootfs/boot/initrd.img




# Method 1(Grub2):

# Common disk method + Grub method

cd ~/Code/kernel_sources/linux-4.19.256/

sudo losetup /dev/loop0 busybox_grub_2G_4.19.256.img

sudo kpartx -a /dev/loop0

sudo grub-install --target=i386-pc --recheck --no-floppy --boot-directory=/mnt/rootfs/boot/ /dev/loop0




cd /mnt/rootfs/boot/grub/

sudo sh -c "cat > grub.cfg << EOF

set timeout=5

set default=0

menuentry 'Linux 4.19.256, busybox, root=/dev/sda2' {

    linux /boot/zImage root=/dev/sda2

    initrd /boot/initrd.img

}




menuentry 'Reboot' {

    reboot

}




menuentry 'Shutdown' {

    halt

}

EOF"




cd ~/Code/kernel_sources/linux-4.19.256

qemu-system-x86_64 -m 1024M -drive format=raw,file=busybox_grub_2G_4.19.256.img -curses

It can run successfully.




# Method 2(U-boot):

# Common disk method + U-boot method

cd ~/Code/kernel_sources/linux-4.19.256

dd if=~/Code/kernel_sources/u-boot/u-boot.bin of=busybox_u-boot_64M_4.19.256_usb.img conv=notrunc bs=1




cd ~/Code/kernel_sources/linux-4.19.256

qemu-system-arm -M vexpress-a9 \

     -nographic \

     -m 1024M \

     -sd ./busybox_u-boot_64M_4.19.256.img

...

It's can't start u-boot.




How use u-boot in sdcard file like grub-install?




Thanks!




Sincerely,

Ronggang Huang

2022.11.19


More information about the U-Boot mailing list