@ -1,5 +1,7 @@
#!/bin/sh
#!/bin/sh
GIB_IN_BYTES = "1073741824"
target = " ${ 1 :- pi1 } "
target = " ${ 1 :- pi1 } "
image_path = "/sdcard/filesystem.img"
image_path = "/sdcard/filesystem.img"
zip_path = "/filesystem.zip"
zip_path = "/filesystem.zip"
@ -15,6 +17,14 @@ if [ ! -e $image_path ]; then
fi
fi
fi
fi
qemu-img info $image_path
image_size_in_bytes = $( qemu-img info --output json $image_path | grep "virtual-size" | awk '{print $2}' | sed 's/,//' )
if [ [ " $(( $image_size_in_bytes % ( $GIB_IN_BYTES * 2 )) ) " != "0" ] ] ; then
new_size_in_gib = $(( ( $image_size_in_bytes / ( $GIB_IN_BYTES * 2 ) + 1 ) * 2 ))
echo " Rounding image size up to ${ new_size_in_gib } GiB so it's a multiple of 2GiB... "
qemu-img resize $image_path " ${ new_size_in_gib } G "
fi
if [ " ${ target } " = "pi1" ] ; then
if [ " ${ target } " = "pi1" ] ; then
emulator = qemu-system-arm
emulator = qemu-system-arm
kernel = "/root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster"
kernel = "/root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster"
@ -22,21 +32,23 @@ if [ "${target}" = "pi1" ]; then
machine = versatilepb
machine = versatilepb
memory = 256m
memory = 256m
root = /dev/sda2
root = /dev/sda2
nic = '--net nic --net user,hostfwd=tcp::5022-:22'
nic = "--net nic --net user,hostfwd=tcp::5022-:22"
elif [ " ${ target } " = "pi2" ] ; then
elif [ " ${ target } " = "pi2" ] ; then
emulator = qemu-system-arm
emulator = qemu-system-arm
machine = raspi2
machine = raspi2b
memory = 1024m
memory = 1024m
kernel_pattern = kernel7.img
kernel_pattern = kernel7.img
dtb_pattern = bcm2709-rpi-2-b.dtb
dtb_pattern = bcm2709-rpi-2-b.dtb
nic = ''
append = "dwc_otg.fiq_fsm_enable=0"
nic = "-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
elif [ " ${ target } " = "pi3" ] ; then
elif [ " ${ target } " = "pi3" ] ; then
emulator = qemu-system-aarch64
emulator = qemu-system-aarch64
machine = raspi3
machine = raspi3b
memory = 1024m
memory = 1024m
kernel_pattern = kernel8.img
kernel_pattern = kernel8.img
dtb_pattern = bcm2710-rpi-3-b-plus.dtb
dtb_pattern = bcm2710-rpi-3-b-plus.dtb
nic = ''
append = "dwc_otg.fiq_fsm_enable=0"
nic = "-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
else
else
echo " Target ${ target } not supported "
echo " Target ${ target } not supported "
echo "Supported targets: pi1 pi2 pi3"
echo "Supported targets: pi1 pi2 pi3"
@ -78,7 +90,7 @@ exec ${emulator} \
${ nic } \
${ nic } \
--dtb " ${ dtb } " \
--dtb " ${ dtb } " \
--kernel " ${ kernel } " \
--kernel " ${ kernel } " \
--append " rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root= ${ root } rootwait panic=1 " \
--append " rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root= ${ root } rootwait panic=1 ${ append } " \
--no-reboot \
--no-reboot \
--display none \
--display none \
--serial mon:stdio
--serial mon:stdio