Skip to content

Instantly share code, notes, and snippets.

@doevelopper
Last active June 6, 2018 12:56
Show Gist options
  • Save doevelopper/d9a1e59d721054afc03e0d12292e6bd1 to your computer and use it in GitHub Desktop.
Save doevelopper/d9a1e59d721054afc03e0d12292e6bd1 to your computer and use it in GitHub Desktop.
   qemu-system-aarch64 -m <memory size> -M <machine name> -drive if=none,file=<hard drive file name>,id=hd0 \
 -device virtio-blk-device,drive=hd0 -netdev type=tap,id=net0 -device virtio-net-device,netdev=net0

Read for RPI3 and qemu 2.12

https://translatedcode.wordpress.com/2018/04/25/debian-on-qemus-raspberry-pi-3-model/

Setup Buildroot environment

>$ ARCHI=64
>$ WORKING_DIR=$(readlink -f `pwd`)
>$ OS_TARGET=rpios${ARCHI}
>$ QEMU_KERNEL=${WORKING_DIR}/qemu_rpios${ARCHI}
>$ BLRT_BUILD_DIR=${WORKING_DIR}/${OS_TARGET}
>$ GIT_XENOMAI_LINUX_DIR=${WORKING_DIR}/xenomai-3
>$ BUILDROOT_DIRECTORY=${WORKING_DIR}/buildroot-2018.02

Build and install latest qemu

>$ git clone https://github.com/qemu/qemu.git
>$ ./configure --prefix=/home/happyman/dev_install/qemu12 --enable-debug-stack-usage \
    --enable-user --enable-system --enable-modules --enable-tcg-interpreter \
    --enable-debug-tcg --python=/usr/bin/python
>$ export PATH=/home/happyman/dev_install/qemu12/bin:$PATH
>$ qemu-system-aarch64 -M virt -cpu help
...
cortex-a15
cortex-a53
cortex-a57
>$ qemu-system-aarch64 -M help
    raspi2               Raspberry Pi 2
    raspi3               Raspberry Pi 3

Build RPI3 SDImage

>$ cd ${BUILDROOT_DIRECTORY}
>$ make O=${BLRT_BUILD_DIR} list-defconfigs
>$ make O=${BLRT_BUILD_DIR} raspberrypi3_64_defconfig
>$ make O=${BLRT_BUILD_DIR} busybox-menuconfig
>$ make O=${BLRT_BUILD_DIR} linux-menuconfig
>$ make O=${BLRT_BUILD_DIR} menuconfig
>$ make O=${BLRT_BUILD_DIR} source-check
>$ make O=${BLRT_BUILD_DIR} source
>$ make O=${BLRT_BUILD_DIR} 

Build Qemu Kernel image for RPI3

>$ make O=${QEMU_KERNEL} list-defconfigs
>$ make O=${QEMU_KERNEL} qemu_aarch64_virt_defconfig
>$ make O=${QEMU_KERNEL} menuconfig
>$ make O=${QEMU_KERNEL} 

#WARNING NONE WORKED

>$ qemu-system-aarch64 -machine virt -cpu cortex-a53 -machine type=virt -nographic \
   -smp 4 -m 1024 -kernel ${QEMU_KERNEL}/images/Image --append "console=ttyAMA0" --append "console=ttyAMA0"
   
>$ qemu-system-aarch64 -machine virt -cpu cortex-a53 -machine type=virt -nographic \
    -smp 4 -m 1024 -kernel ${BLRT_BUILD_DIR}/images/sdcard.img  --append "console=ttyAMA0"
    
>$ qemu-system-aarch64 -machine virt -cpu cortex-a53 -nographic -smp 1 -no-reboot -serial stdio \
    -hda ${BLRT_BUILD_DIR}/images/sdcard.img -kernel ${QEMU_KERNEL}/images/Image \
    -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" \
    -m 1024

Qemi TIPS

Install tools for distribueted filesystem

Sudo apt-get instll nbd-client nbd-server rbd-nbd

mount img file on filesystem

sudo qemu-nbd -c /dev/nbd0 ${QEMU_KERNEL}/images/Image
mkdir qemumnt
sudo mount /dev/nbd0p1 qemumnt

Now let's look at the arguments that configure our system:

  • -smp 2 - 2 (virtual) cores.
  • -m 1024 - 1024MB of system memory.
  • -M virt - emulate a generic QEMU ARM machine.
  • -cpu cortex-a53 - the CPU model to emulate.
  • -bios QEMU_EFI.fd - the BIOS firmware file to use.
  • -nographic - output goes to the terminal (rather than opening a graphics capable window).
  • -device virtio-blk-device,drive=image - create a Virtio block device called "image".
  • -drive if=none,id=image,file=ubuntu-16.04-server-cloudimg-arm64-uefi1.img - create a drive using the "image" device and our cloud server disk image.
  • -device virtio-blk-device,drive=cloud - create another Virtio block device called "cloud".
  • -drive if=none,id=cloud,file=cloud.img - create a drive using the "cloud" device and our cloud-config disk image.
  • -device virtio-net-device,netdev=user0 - create a Virtio network device called "user0"
  • -netdev user,id=user0 - create a user mode network stack using device "user0"
  • -redir tcp:2222::22 - map port 2222 on the host to port 22 (the standard ssh port) on the guest.

Here we create a generic QEMU ARM machine

@doevelopper
Copy link
Author

doevelopper commented Jun 5, 2018

>$ qemu-system-aarch64  -kernel ${QEMU_KERNEL}/images/Image \
  [  -initrd initrd.img-4.14.0-3-arm64 \ ]
  -dtb bcm2837-rpi-3-b.dtb  -M raspi3 -m 1024  -serial stdio \
  -append "rw earlycon=pl011,0x3f201000 console=ttyAMA0 loglevel=8 root=/dev/mmcblk0p2 fsck.repair=yes net.ifnames=0 rootwait \
   memtest=1"   -drive file=sdcard.img,format=raw,if=sd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment