#!/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 "$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" ] && [ $# -ne 2 ]; then usage fi if [ "$1" = "-v" ] && [ $# -ne 3 ]; then usage fi if [ "$1" = "-v" ] ; then DEBUG=1 exec 3>&1 shift 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"
/*
 * Copyright (C) 2017-2018 "IoT.bzh"
 * Author Sebastien Douheret <sebastien@iot.bzh>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package main

import (
	"os"
	"syscall"
	"unsafe"
)

const (
	syscallEBADE = syscall.EBADEXEC

	syscall_TCGETS = 0x402c7413
	syscall_TCSETS = 0x802c7414
)

func fcntl(fd uintptr, cmd int, arg int) (val int, err error) {
	r, _, e := syscall.Syscall(syscall.SY