Skip to content

Commit

Permalink
Add handling of xz images in qemu scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosproject committed Apr 15, 2022
1 parent e88ec0a commit c50d74b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 32 deletions.
18 changes: 12 additions & 6 deletions src/qemu_boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ ZIP_IMG=$1
DEST=/tmp
source ${DIR}/common.sh

IMG_NAME=$(unzip -Z "${ZIP_IMG}" | head -n 3 | tail -n 1 | awk '{ print $9 }')
if [[ $ZIP_IMG == *.txt ]]; then
IMG_NAME=$(unzip -Z "${ZIP_IMG}" | head -n 3 | tail -n 1 | awk '{ print $9 }')
else
unxz --keep "${ZIP_IMG}"
IMG_NAME=$(echo $(basename $ZIP_IMG) | sed "s/.xz//")
fi

BASE_IMG_PATH=${DEST}/"${IMG_NAME}"


Expand All @@ -18,13 +24,13 @@ if [ ! -f "${BASE_IMG_PATH}" ]; then
BASE_ROOT_PARTITION=2
BASE_MOUNT_PATH=${DEST}/mount
mkdir -p "${BASE_MOUNT_PATH}"

sudo bash -c "$(declare -f mount_image); $(declare -f detach_all_loopback); mount_image $BASE_IMG_PATH $BASE_ROOT_PARTITION $BASE_MOUNT_PATH"

pushd "${BASE_MOUNT_PATH}"
sudo bash -c "$(declare -f fixLd); fixLd"
sudo sed -e '/PARTUUID/ s/^#*/#/' -i etc/fstab
sudo bash -c 'echo "/dev/sda1 /boot vfat defaults 0 2" >> etc/fstab'
sudo bash -c "$(declare -f fixLd); fixLd"
sudo sed -e '/PARTUUID/ s/^#*/#/' -i etc/fstab
sudo bash -c 'echo "/dev/sda1 /boot vfat defaults 0 2" >> etc/fstab'
popd
sudo bash -c "$(declare -f unmount_image); unmount_image $BASE_MOUNT_PATH force"
fi
Expand Down
58 changes: 32 additions & 26 deletions src/qemu_boot64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ ZIP_IMG=$1
DEST=/tmp
source ${DIR}/common.sh

IMG_NAME=$(unzip -Z "${ZIP_IMG}" | head -n 3 | tail -n 1 | awk '{ print $9 }')
if [[ $ZIP_IMG == *.txt ]]; then
IMG_NAME=$(unzip -Z "${ZIP_IMG}" | head -n 3 | tail -n 1 | awk '{ print $9 }')
else
unxz --keep "${ZIP_IMG}"
IMG_NAME=$(echo $(basename $ZIP_IMG) | sed "s/.xz//")
fi

BASE_IMG_PATH=${DEST}/"${IMG_NAME}"


Expand All @@ -18,23 +24,23 @@ if [ ! -f "${BASE_IMG_PATH}" ]; then
BASE_ROOT_PARTITION=2
BASE_MOUNT_PATH=${DEST}/mount
mkdir -p "${BASE_MOUNT_PATH}"

sudo bash -c "$(declare -f mount_image); $(declare -f detach_all_loopback); mount_image $BASE_IMG_PATH $BASE_ROOT_PARTITION $BASE_MOUNT_PATH"

pushd "${BASE_MOUNT_PATH}"
sudo bash -c "$(declare -f fixLd); fixLd"
sudo sed -e '/PARTUUID/ s/^#*/#/' -i etc/fstab
sudo bash -c "$(declare -f fixLd); fixLd"
sudo sed -e '/PARTUUID/ s/^#*/#/' -i etc/fstab
popd

pushd "${BASE_MOUNT_PATH}/boot"
rm -rf /tmp/debian_bootpart || true
mkdir /tmp/debian_bootpart
cp kernel8.img /tmp/debian_bootpart
DTB_PATH="$(ls *-3-b.dtb | head)"
# sudo bash -c 'cp initrd.img*-arm64 /tmp/debian_bootpart'
cp ${DTB_PATH} /tmp/debian_bootpart
# sudo bash -c 'cp cmdline.txt /tmp/debian_bootpart'
# sudo bash -c 'cp vmlinuz-*-arm64 /tmp/debian_bootpart'
rm -rf /tmp/debian_bootpart || true
mkdir /tmp/debian_bootpart
cp kernel8.img /tmp/debian_bootpart
DTB_PATH="$(ls *-3-b.dtb | head)"
# sudo bash -c 'cp initrd.img*-arm64 /tmp/debian_bootpart'
cp ${DTB_PATH} /tmp/debian_bootpart
# sudo bash -c 'cp cmdline.txt /tmp/debian_bootpart'
# sudo bash -c 'cp vmlinuz-*-arm64 /tmp/debian_bootpart'
popd
sudo bash -c "$(declare -f mount_image); $(declare -f detach_all_loopback); unmount_image $BASE_MOUNT_PATH force"

Expand All @@ -47,19 +53,19 @@ fi
#sudo qemu-system-arm -enable-kvm -m 1024 -cpu host -M virt -nographic -pflash flash0.img -pflash flash1.img -drive if=none,file=vivid-server-cloudimg-arm64-uefi1.img,id=hd0 -device virtio-blk-device,drive=hd0 -netdev type=tap,id=net0 -device virtio-net-device,netdev=net0,mac=$randmac

#/usr/bin/qemu-system-arm -kernel ${KERNEL_PATH} -cpu arm1176 -m 256 -M versatilepb -dtb ${DTB_PATH} -no-reboot -serial stdio -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' -hda ${BASE_IMG_PATH} -net nic -net user,hostfwd=tcp::5022-:22
DTB_PATH=$(ls /tmp/debian_bootpart/*-3-b.dtb | head)
qemu-system-aarch64 \
-kernel /tmp/debian_bootpart/kernel8.img \
-dtb "${DTB_PATH}" \
-m 1024 -M raspi3 \
-cpu cortex-a53 \
-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="${BASE_IMG_PATH}",format=raw,if=sd \
-no-reboot


DTB_PATH=$(ls /tmp/debian_bootpart/*-3-b.dtb | head)

qemu-system-aarch64 \
-kernel /tmp/debian_bootpart/kernel8.img \
-dtb "${DTB_PATH}" \
-m 1024 -M raspi3 \
-cpu cortex-a53 \
-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="${BASE_IMG_PATH}",format=raw,if=sd \
-no-reboot



Expand Down

1 comment on commit c50d74b

@guysoft
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduced a bug. if [[ $ZIP_IMG == *.txt ]]; then should have been if [[ $ZIP_IMG == *.zip ]]; then

Please # to comment.