Qemu + buildroot 101

Compile arm kernel and execute it via qemu

sudo apt-get install qemu-system-arm
tar -xvzf buildroot-2020.02.3.tar.gz
sudo apt-get install libncurses5-dev libncursesw5-dev

make menuconfig
make list-defconfigs
make qemu_arm_versatile_defconfig

export PATH=$PATH:/home/embeddedcraft/buildroot-2020.02.3/output/host/bin
arm-buildroot-linux-uclibcgnueabi-gcc hello.c -o hello
sudo mount -t ext2 -o rw,loop rootfs.ext2 /mnt/try
sudo cp hello /mnt/try/root/

qemu-system-arm -M versatilepb -kernel vmlinuz-3.2.0-4-versatile -initrd initrd.img-3.2.0-4-versatile -hda debian_wheezy_armel_standard.qcow2 -append "root=/dev/sda1"  -net nic -net user,hostfwd=tcp::7777-:22

tar zcf squashfs-root.tar.gz squashfs-root 
scp -P 7777 ./squashfs-root.tar.gz root@127.0.0.1:/root

Buildroot and QEMU – the quickest recipe for your own Linux

get buildroot version from the official website
$ tar -xvzf buildroot-2021.xxx.tar.gz
$ cd buildroot/
$ make qemu_arm_versatile_defconfig
$ make menuconfig
$ qemu-system-arm -M versatilepb -kernel output/images/zImage -dtb output/images/versatile-pb.dtb -drive file=output/images/rootfs.ext2,if=scsi -append "root=/dev/sda console=ttyAMA0,115200" -nographic

source: https://pressreset.net/2013/09/buildroot-and-qemu-the-quickest-recipe-for-your-own-linux/

buildroot essential commands that will safe your life

make menuconfig
make HOSTCC=gcc-4.4
make MAKEINFO=true
make -j8

qemu essential commands that will safe you

qemu-system-arm -machine help
qemu-system-arm -machine vexpress -cpu help

sudo qemu-system-arm \
    -M vexpress-a9 \
    -kernel ./zImage_arch \
    -dtb ./vexpress-v2p-ca9.dtb \
    --nographic \
    -append "root=/dev/mmcblk0 rw roottype=ext4 console=ttyAMA0" \
    -drive if=sd,driver=raw,cache=writeback,file=./arch_rootfs.ext4 \
    -net nic,macaddr=$macaddr \
    -net tap,vlan=0,ifname=tap0 \
    -snapshot

    
qemu-system-arm -M        vexpress-a9                                                    \
                -cpu      cortex-a9                                                      \
                -m        1024                                                           \
                -nographic                                                               \
                -kernel   $BRIMAGES/zImage                                               \
                -drive    file=$BRIMAGES/rootfs.ext2,index=0,media=disk,format=raw,if=sd \
                -dtb      $BRIMAGES/vexpress-v2p-ca9.dtb                                 \
                -net      nic                                                            \
                -net      user,hostfwd=tcp::2222-:22,hostfwd=tcp::9000-:9000             \
                -append   "rw console=ttyAMA0 console=tty root=/dev/mmcblk0"

                
qemu-system-arm -M versatilepb -kernel vmlinuz-3.2.0-4-versatile -initrd initrd.img-3.2.0-4-versatile -hda debian_wheezy_armel_standard.qcow2 -append "root=/dev/sda1"  -net nic -net user,hostfwd=tcp::7777-:22    

qemu-system-arm -M versatilepb -kernel output/images/zImage -dtb output/images/versatile-pb.dtb -drive file=output/images/rootfs.ext2,if=scsi -append "root=/dev/sda console=ttyAMA0,115200" -nographic

qemu-system-arm -M versatilepb -kernel zImage -dtb versatile-pb.dtb -drive file=rootfs.ext2,if=scsi,format=raw -append "root=/dev/sda console=ttyAMA0,115200" -serial stdio -net nic,model=rtl8139 -net user

Qemu + virtual tap

sudo brctl addbr virbr0
sudo ifconfig virbr0 192.168.122.1/24 up

sudo tunctl -t tap0
sudo ifconfig tap0 192.168.122.11/24 up
sudo brctl addif virbr0 tap0

sudo qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 -nographic

ifconfig eth0 192.168.122.12/24 up

Another option is portforwarding:

sudo qemu-system-mipsel -M malta -kernel vmlinux-3.2.0-4-4kc-malta -hda debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" -net user,hostfwd=tcp::80-:80,hostfwd=tcp::443-:443,hostfwd=tcp::2222-:22 -net nic -nographic

ssh -p 2222 root@127.0.0.1
scp -r ./data  root@192.168.122.12:/root/

Last updated