#!/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 Minnowboard and any PC with UEFI boot # # changes # - simpler use model # - keep initrd if present # - create a grub config with PARTUID to ease boot from various devices automaticaly # - add a UEFI startup.nsh script for autoboot # - remove any configured swap is fstab # - 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 # 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 on IA UEFI based computer" echo "In particular is can create USB or SD bootable support for Minnowboard" echo "" echo "Usage: $(basename $0) [-v] IDSK_IMAGE REMOVABLE_DEVICE" echo " -v: Verbose debug" echo " HDDIMG: The DISK_IMAGE file generated by Yocto 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 " mkefi-agl.sh agl-demo-platform-intel-corei7-64.hddimg /dev/sdd" echo " mkefi-agl.sh agl-demo-platform-intel-corei7-64.wic.xz /dev/sdd" 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 "$DEV
TEMPLATE = lib
CONFIG += plugin use_c_linker
CONFIG -= qt
QMAKE_CFLAGS += -Wextra -Wconversion -Wno-unused-parameter -Werror=maybe-uninitialized -Werror=implicit-function-declaration -ffunction-sections -fdata-sections -Wl,--as-needed -Wl,--gc-sections

DESTDIR = $${OUT_PWD}/../package/root/lib
RUB_CFG; then warn "initrd=microcode.cpio detected, might not work on all boot configurations" fi sed -i "s@ root=[^ ]*@ @" $GRUB_CFG sed -i "s@vmlinuz @vmlinuz root=$ROOTFS_PARTUUID @" $GRUB_CFG fi # look for a systemd-boot loader.conf file and create a default boot entry SYSTEMDBOOT_CFG="$BOOTFS_MNT/loader/loader.conf" if [ -e "$SYSTEMDBOOT_CFG" ]; then info "Configuring SYSTEMD-BOOT" SYSTEMDBOOT_BOOT="$BOOTFS_MNT/loader/entries/boot.conf" SYSTEMDBOOT_DEBUG="$BOOTFS_MNT/loader/entries/debug.conf" # Delete the install entry sed -i "/menuentry 'install'/,/^}/d" $SYSTEMDBOOT_CFG rm -rf "$BOOTFS_MNT/loader/entries/install.conf" 1>&3 2>&1 # Add PARTUUID to the boot entry file if [ ! -e "$SYSTEMDBOOT_BOOT" ]; then die "no boot.conf entry found in systemd-boot directories" fi # Delete any LABEL= strings sed -i "s/ LABEL=[^ ]*/ /" $SYSTEMDBOOT_BOOT # detect config initrd=microcode.cpio if grep -q microcode $SYSTEMDBOOT_BOOT; then warn "initrd=microcode.cpio detected, might not work on all boot configurations" fi sed -i "s@ root=[^ ]*@ @" $SYSTEMDBOOT_BOOT sed -i "s@options @options root=$ROOTFS_PARTUUID @" $SYSTEMDBOOT_BOOT fi # Ensure we have at least one EFI bootloader configured if [ ! -e $GRUB_CFG ] && [ ! -e $SYSTEMDBOOT_CFG ] ; then die "No EFI bootloader configuration found" fi printf "Copying ROOTFS files ... " command -v rsync >/dev/null 2>&1 # check if rsync exists if [ $DEBUG -eq 1 ] && [ $? -eq 0 ]; then rsync --info=progress2 -h -aHAXW --no-compress $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT 1>&3 2>&1 || die "Root FS copy failed" else cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT 1>&3 2>&1 || die "Root FS copy failed" fi debug "removing any swap entry in /etc/fstab" sed --in-place '/swap/d' $ROOTFS_MNT/etc/fstab debug "fixing PARTUUID for /boot" sed --in-place -e "s#PARTUUID=[0-9a-z-]\+\t/boot#${BOOTFS_PARTUUID}\t/boot#" $ROOTFS_MNT/etc/fstab printf "flushing data on removable device. May take a while ... " sync --file-system $ROOTFS_MNT echo done # We dont want udev to mount our root device while we're booting... if [ -d $ROOTFS_MNT/etc/udev/ ] ; then echo "$TARGET_DEVICE" >> $ROOTFS_MNT/etc/udev/mount.blacklist fi # Call cleanup to unmount devices and images and remove the TMPDIR cleanup echo "" if [ $WARNINGS -ne 0 ] && [ $ERRORS -eq 0 ]; then echo "${YELLOW}Installation completed with warnings${CLEAR}" echo "${YELLOW}Warnings: $WARNINGS${CLEAR}" elif [ $ERRORS -ne 0 ]; then echo "${RED}Installation encountered errors${CLEAR}" echo "${RED}Errors: $ERRORS${CLEAR}" echo "${YELLOW}Warnings: $WARNINGS${CLEAR}" else success "Installation completed successfully" fi echo ""