#!/bin/sh

KERN="$1"
RAMFS="$2"
IMAGE="$3"

if [ X$RAMFS = X ]; then
  echo "Usage: $0 kernel initramfs image"
  exit 1
fi

if [ ! -f "$KERN" ]; then
  echo "$KERN not found"
  exit 1
fi
if [ ! -f "$RAMFS" ]; then
  echo "$RAMFS not found"
  exit 1
fi
if [ ! -f "$IMAGE" ]; then
  echo "$IMAGE not found"
  exit 1
fi

if [ -f /usr/bin/qemu-system-arm ]; then
  qemu-system-arm -machine vexpress-a9 -m 1024 -nographic -net nic -net user \
    -append "console=ttyAMA0,115200n8 rw root=/dev/mmcblk0p2 rootwait physmap.enabled=0" \
    -kernel "$KERN" \
    -initrd "$RAMFS" \
    -sd "$IMAGE"
else
  echo "You need to install qemu-system-arm to boot a versatile express image"
fi
