From 282f805d6dcad5390aed7486aa70c930a7e56eb3 Mon Sep 17 00:00:00 2001 From: Andreas Grapentin Date: Wed, 27 Dec 2017 17:08:03 +0100 Subject: [PATCH] initial commit - working archlinuxarm boot for versatile express emulation --- .gitignore | 7 ++++++ create.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ start.sh | 25 +++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 .gitignore create mode 100755 create.sh create mode 100755 start.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef6b600 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ + +# image files +*.qcow2 +*.raw + +# tarballs +*.tar.* diff --git a/create.sh b/create.sh new file mode 100755 index 0000000..e509b86 --- /dev/null +++ b/create.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +set -eu + +# this script prepares an archlinuxarm image for use with start.sh + +OUTFILE=${OUTFILE:-armv7h.raw} +SIZE=${SIZE:-64G} + +_builddir=build +_outfile=$_builddir/$(basename $OUTFILE) + +mkdir -p $_builddir + +# create an empty image +rm -f $_outfile +qemu-img create -f raw $_outfile $SIZE + +# setup an available loop device +_loopdev=$(losetup -f --show $_outfile) + +# setup an error exit handler for cleanup +function cleanup { + echo "exiting due to earlier errors..." >&2 + for part in p1 p2; do + umount $_loopdev$part || true + done + losetup -d $_loopdev || true + rm -rf $_builddir/boot $_builddir/root + rm -f $_outfile +} +trap cleanup ERR + +# fetch latest archlinuxarm tarball +wget -nc http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz + +# following are the installation instructions provided on +# https://archlinuxarm.org/platforms/armv7/arm/versatile-express +dd if=/dev/zero of=$_loopdev bs=1M count=8 +parted -s $_loopdev \ + mklabel gpt \ + mkpart ESP fat32 1MiB 513MiB \ + set 1 boot on \ + mkpart primary ext4 513MiB 100% +mkfs.vfat -F 32 ${_loopdev}p1 +mkdir -p $_builddir/boot +mount ${_loopdev}p1 $_builddir/boot +mkfs.ext4 ${_loopdev}p2 +mkdir $_builddir/root +mount ${_loopdev}p2 $_builddir/root +bsdtar -vxpf ArchLinuxARM-armv7-latest.tar.gz -C $_builddir/root +sync +mv -v $_builddir/root/boot/* $_builddir/boot +cat >> $_builddir/root/etc/fstab << EOF +/dev/mmcblk0p1 /boot vfat defaults 0 0 +EOF + +# tie up any loose ends +for part in p1 p2; do + umount $_loopdev$part +done +losetup -d $_loopdev +mv -v $_outfile $OUTFILE +rm -rf $_builddir diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..8e1bcfb --- /dev/null +++ b/start.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +IMAGE=${IMAGE:-armv7h.raw} + +_loopdev=$(sudo losetup -f --show $IMAGE) +_bootdir=.boot + +function cleanup { + sudo umount ${_loopdev}p1 + sudo losetup -d $_loopdev + rm -rf $_bootdir +} +trap cleanup EXIT + +mkdir -p $_bootdir +sudo mount ${_loopdev}p1 $_bootdir + +qemu-system-arm \ + -M vexpress-a9 \ + -dtb $_bootdir/dtbs/vexpress-v2p-ca9.dtb \ + -kernel $_bootdir/zImage \ + --append "root=/dev/mmcblk0p2 rw roottype=ext4 console=ttyAMA0" \ + -drive if=sd,driver=raw,cache=writeback,file=$IMAGE \ + --nographic \ + -snapshot