#!/bin/sh # # Copyright (c) 2012, Intel Corporation. # All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Modification from mkefidisk.sh provided by the Yocto project by Dominig # to install Automotive Grade Linux (AGL) on # Intel platforms equipped with the Automotive Linux Boot (ABL) # # Dependencies: # Relies on the Intel iasImage tool to pakage the Kernel and the initrd in ABL format # # changes # - simpler use model # - keep initrd if present # - does not allocate swap # - accept .hddimg, wic and wic.xz as sources # LANG=C # Set to 1 to enable additional output DEBUG=0 exec 3>/dev/null # # Defaults # # 100 Mb for the boot partition BOOT_SIZE=100 # min available space on TMP_DIR for uncompressing xz image in kB e.g. 5G (5000000) TMP_SIZE_MIN=5000000 # TMP_DIR directory use for holding image file for uncompression (e.g. /tmp or $HOME) TMP_DIR=/tmp # MRB_DEBUG_TTY="ttyS2,115200n8" MRB_HDMI="HDMI-A-1:e" # IAS_PATH="" IAS_EXE="ias_image_app" IAS_CMD_LINE=/tmp/iasCommandLine.cmd # Cleanup after die() cleanup() { debug "Syncing and unmounting devices" # Unmount anything we mounted unmount $ROOTFS_MNT || error "Failed to unmount $ROOTFS_MNT" unmount $BOOTFS_MNT || error "Failed to unmount $BOOTFS_MNT" unmount $HDDIMG_ROOTFS_MNT || error "Failed to unmount $HDDIMG_ROOTFS_MNT" unmount $HDDIMG_MNT || error "Failed to unmount $HDDIMG_MNT" if [ "$IMG_TYPE" = "DISK" ]; then debug "de-attaching loop devices" for LOOP_DEVICE in `losetup --list |grep $HDDIMG | cut -d" " -f1` ; do losetup -d $LOOP_DEVICE 1>&3 2>&1 || error "Detaching $LOOP_DEVICE from $HDDIMG failled" done fi # Remove the TMPDIR debug "Removing temporary files" if [ -d "$TMPDIR" ]; then rm -rf $TMPDIR || error "Failed to remove $TMPDIR" fi [ -f "$TMP_DIR/TMP-AGL-wic-image.wic" ] || rm -f $TMP_DIR/TMP-AGL-wic-image.wic } trap 'die "Signal Received, Aborting..."' HUP INT TERM # Logging routines WARNINGS=0 ERRORS=0 CLEAR="$(tput sgr0)" INFO="$(tput bold)" RED="$(tput setaf 1)$(tput bold)" GREEN="$(tput setaf 2)$(tput bold)" YELLOW="$(tput setaf 3)$(tput bold)" info() { echo "${INFO}$1${CLEAR}" } error() { ERRORS=$((ERRORS+1)) echo "${RED}$1${CLEAR}" } warn() { WARNINGS=$((WARNINGS+1)) echo "${YELLOW}$1${CLEAR}" } success() { echo "${GREEN}$1${CLEAR}" } die() { error "$1" cleanup exit 1 } debug() { if [ $DEBUG -eq 1 ]; then echo "$1" fi } usage() { echo "Install AGL on a removable device to boot ABL based computer" echo "ABL on the target must accept non signed development Linux kernel" echo "In particular is can create USB or SD bootable support for Intel MRB" echo "" echo "Usage: $(basename $0) [-v] [-p path_to_iasImage_tool] HDDIMG REMOVABLE_DEVICE" echo " -v: Verbose debug" echo " path_to_iasImage_tool: path the iasImage tool provided by Intel." echo " HDDIMG: The hddimg file to generate the efi disk from" echo " Supported formats are .hddimg, .wic .wic.xz" echo " REMOVABLE_DEVICE: The block device to write the image to, e.g. /dev/sdh" echo "ex:" echo " mkabl-agl.sh agl-demo-platform-intel-corei7-64.wic.xz /dev/sdd" echo " mkabl-agl.sh agl-demo-platform-intel-corei7-64.hddimg /dev/sdd" echo " assuming that iasImage is accessible via your default path" exit 1 } image_details() { IMG=$1 info "Image details" echo " image: $(stat --printf '%N\n' $IMG)" echo " size: $(stat -L --printf '%s bytes\n' $IMG)" echo " modified: $(stat -L --printf '%y\n' $IMG)" echo " type: $(file -L -b $IMG)" echo "" } device_details() { DEV=$1 BLOCK_SIZE=512 info "Device details" echo " device: $DEVICE" if [ -f "/sys/class/block/$DEV/device/vendor" ]; then echo " vendor: $(cat /sys/class/block/$DEV/device/vendor)" else echo " vendor: UNKOWN" fi if [ -f "/sys/class/block/$DEV/device/model" ]; then echo " model: $(cat /sys/class/block/$DEV/device/model)" else echo " model: UNKNOWN" fi if [ -f "/sys/class/block/$DEV/size" ]; then echo " size: $(($(cat /sys/class/block/$DEV/size) * $BLOCK_SIZE)) bytes" else echo " size: UNKNOWN" fi echo "" } unmount_device() { grep -q $DEVICE /proc/mounts if [ $? -eq 0 ]; then warn "$DEVICE listed in /proc/mounts, attempting to unmount" umount $DEVICE* 2>/dev/null ! grep -q $DEVICE /proc/mounts && info "Unmounted successfully" return $? fi return 0 } unmount() { if [ "$1" = "" ] ; then return 0 fi grep -q $1 /proc/mounts if [ $? -eq 0 ]; then debug "Unmounting $1" umount $1 ! grep -q $1 /proc/mounts # check if unmounted successfully return $? fi return 0 } # # Parse and validate arguments # if [ "$1" = "-v" ] ; then DEBUG=1 exec 3>&1 shift fi if [ "$1" = "-p" ] ; then IAS_PATH="$2""/" shift 2 fi if [ $# -ne 2 ]; then usage fi IAS_IMAGE_TOOL="$IAS_PATH$IAS_EXE" debug "iasImage tool is: $IAS_IMAGE_TOOL" which $IAS_IMAGE_TOOL > IAS_IMAGE_TOOL_PATH if [ ! -x "$(command -v $IAS_IMAGE_TOOL)" ]; then die "$IAS_IMAGE_TOOL not found pointed by the path via 'sudo; use -p option'" fi HDDIMG=$1 DEVICE=$2 LINK=$(readlink $DEVICE) if [ $? -eq 0 ]; then DEVICE="$LINK" fi if [ ! -w "$DEVICE" ]; then if [ ! -e "${DEVICE}" ] ; then die "Device $DEVICE cannot be found" else die "Device $DEVICE is not writable (need to run under sudo?)" fi fi if [ ! -e "$HDDIMG" ]; then die "HDDIMG $HDDIMG does not exist" fi HDDIMG_EXT=${HDDIMG##*.} case $HDDIMG_EXT in hddimg) IMG_TYPE="MOUNT" IMG_COMPRESS="NO" debug "Detected: uncompressed image type .hddimg" ;; wic) IMG_TYPE="DISK" IMG_COMPRESS="NO" debug "Detected: uncompressed image type .wic" ;; xz) IMG_TYPE="DISK" IMG_COMPRESS="YES" debug "Detected: xz compressed image type .wic" command -v xz >/dev/null 2>&1 || { die "xz command is not available, pleaes install xz package"; } TMP_SIZE=`df -k $TMP_DIR | awk '/[0-9]%/{print $(NF-2)}'` if [ "$TMP_SIZE" -lt "$TMP_SIZE_MIN" ]; then die "Available space on $TMP_DIR must be at least $TMP_SIZE_MIN kB" fi printf "Starting decompression of the image. It may take some time ..." xz --decompress --keep --format=auto --force --threads=0 --stdout > $TMP_DIR/TMP-AGL-wic-image.wic $HDDIMG|| \ die "xz