summaryrefslogtreecommitdiffstats
path: root/qt-ostree
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@theqtcompany.com>2016-02-22 10:09:05 +0100
committerGatis Paeglis <gatis.paeglis@theqtcompany.com>2016-03-08 12:20:53 +0000
commitb9878576a71c9df32ce59745f373455eb764d8b6 (patch)
tree8cdbf9955d5bed159a65588afb6c3a3a017c9ec8 /qt-ostree
parentf067b1bf10349a22e3095c097ce502c79d7ed1b9 (diff)
Add support for Intel NUC + GRUB
With this patch OTA integration now supports boards with GRUB2 boot loaders. The same patch moves from *.tar.gz to dd based OTA images: - assembling and deploying dd image takes significantly less time. - its more convenient to do this in qt-ostree, as we have all the relevant information available there. Change-Id: I2d0fb2426360b8afc4e62f2c98c3d7c75a10db07 Reviewed-by: Gatis Paeglis <gatis.paeglis@theqtcompany.com>
Diffstat (limited to 'qt-ostree')
-rwxr-xr-xqt-ostree/deploy.sh128
-rwxr-xr-xqt-ostree/mkcard.sh85
-rwxr-xr-xqt-ostree/ostree-grub-generator107
-rwxr-xr-xqt-ostree/qt-ostree249
4 files changed, 299 insertions, 270 deletions
diff --git a/qt-ostree/deploy.sh b/qt-ostree/deploy.sh
deleted file mode 100755
index b6f1aa9..0000000
--- a/qt-ostree/deploy.sh
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/bin/sh
-#############################################################################
-##
-## Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
-##
-## This file is part of the Qt Enterprise Embedded Scripts of the Qt
-## framework.
-##
-## $QT_BEGIN_LICENSE$
-## Commercial License Usage Only
-## Licensees holding valid commercial Qt license agreements with Digia
-## with an appropriate addendum covering the Qt Enterprise Embedded Scripts,
-## may use this file in accordance with the terms contained in said license
-## agreement.
-##
-## For further information use the contact form at
-## http://www.qt.io/contact-us.
-##
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-set -e
-
-if [ $(id -u) -ne 0 ]; then
- echo "You need root privileges to run this script"
- exit 1
-fi
-
-usage()
-{
- echo "Usage: $0 <device>"
-}
-
-DEVICE=""
-UBOOT="u-boot.imx"
-
-# parse parameters
-while [ $# -gt 0 ] ; do
- case "${1}" in
- -y)
- DONTASK=1
- ;;
- --uboot)
- UBOOT="${2}"
- shift 1
- ;;
- --verbose)
- VERBOSE="v"
- ;;
- -h | -help | --help)
- usage
- exit 0
- ;;
- -*)
- echo "Unknown parameter: ${1}"
- usage
- exit 1
- ;;
- *)
- if [ -n "${DEVICE}" ] ; then
- echo "Device given twice: ${DEVICE} and ${1}"
- usage
- exit 1
- else
- DEVICE="${1}"
- fi
- ;;
- esac
- shift 1
-done
-
-if [ -z "${DEVICE}" ]; then
- usage
- exit 1
-fi
-
-DIR=$(dirname $(readlink -f $0))
-DISK=$(readlink -f ${DEVICE})
-
-if [ -n "$(command -v lsblk)" ]; then
- lsblk
-fi
-fdisk -l ${DISK}
-if [ -z "${DONTASK}" ]; then
- read -p "Reformat disk '${DISK}', all files will be lost? (y/N) " format
- if [ "$format" != "y" -a "$format" != "Y" ]; then
- exit 0
- fi
-fi
-
-echo "-- STEP -- Formatting memory card ${DEVICE}"
-umount ${DISK}* 2> /dev/null || true
-${DIR}/mkcard.sh ${DISK}
-
-if [ -b ${DISK}1 ]; then
- BOOT=${DISK}1
- ROOTFS=${DISK}2
-elif [ -b ${DISK}p1 ]; then
- BOOT=${DISK}p1
- ROOTFS=${DISK}p2
-else
- echo "Unknown device partitions"
- exit 1
-fi
-
-echo "-- STEP -- Deploying boot files"
-udisks --mount ${BOOT} > /dev/null
-MOUNTPOINT=$(grep ${BOOT} /proc/mounts | awk '{print $2}')
-tar ${VERBOSE}xzf ${DIR}/boot.tar.gz -C ${MOUNTPOINT} --owner=root --group=root
-if [ -e uEnv.txt ]; then
- cp uEnv.txt ${MOUNTPOINT}
-fi
-sync
-if [ -e ${MOUNTPOINT}/${UBOOT} ]; then
- dd if=${MOUNTPOINT}/${UBOOT} of=${DISK} bs=512 seek=2
-fi
-
-udisks --unmount ${BOOT}
-
-echo "-- STEP -- Deploying rootfs, this may take a while"
-udisks --mount ${ROOTFS} > /dev/null
-MOUNTPOINT=$(grep ${ROOTFS} /proc/mounts | awk '{print $2}')
-tar ${VERBOSE}xzf ${DIR}/rootfs.tar.gz -C ${MOUNTPOINT}
-sync
-udisks --unmount ${ROOTFS}
-
-echo "-- STEP -- Done"
diff --git a/qt-ostree/mkcard.sh b/qt-ostree/mkcard.sh
deleted file mode 100755
index e82f7c8..0000000
--- a/qt-ostree/mkcard.sh
+++ /dev/null
@@ -1,85 +0,0 @@
-#! /bin/sh
-# mkcard.sh v0.5
-# (c) Copyright 2009 Graeme Gregory <dp@xora.org.uk>
-# Licensed under terms of GPLv2
-#
-# Parts of the procudure base on the work of Denys Dmytriyenko
-# http://wiki.omap.com/index.php/MMC_Boot_Format
-
-set -e
-
-export LC_ALL=C
-
-if [ $# -ne 1 ]; then
- echo "Usage: $0 <drive>"
- exit 1
-fi
-
-if ! which mkfs.ext2 >/dev/null ; then
- echo "Tool mkfs.ext2 needs to be installed"
- exit 1
-fi
-
-DRIVE=$1
-
-dd if=/dev/zero of=$DRIVE bs=1024 count=1024
-
-SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`
-
-echo DISK SIZE - $SIZE bytes
-
-SFDISK_VERSION=`sfdisk --version|awk '{print $4}'`
-SFDISK_NEW_VERSION="2.26"
-SFDISK_MIN_VERSION=`{
-echo $SFDISK_VERSION
-echo $SFDISK_NEW_VERSION
-} | sort -V | head -n1`
-
-echo "Using sfdisk unnamed-fields format for vesion $SFDISK_MIN_VERSION"
-
-if [ "$SFDISK_MIN_VERSION" = "$SFDISK_NEW_VERSION" ]; then
- {
- echo ,64MiB,,*
- echo ,,,-
- } | sfdisk $DRIVE
-else
- CYLINDERS=`echo $SIZE/255/63/512 | bc`
- echo CYLINDERS - $CYLINDERS
- {
- echo 1,9,,*
- echo 10,,,-
- } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
-fi
-
-sleep 1
-
-# handle various device names.
-# note something like fdisk -l /dev/loop0 | egrep -E '^/dev' | cut -d' ' -f1
-# won't work due to https://bugzilla.redhat.com/show_bug.cgi?id=649572
-
-PARTITION1=${DRIVE}1
-if [ ! -b ${PARTITION1} ]; then
- PARTITION1=${DRIVE}p1
-fi
-
-PARTITION2=${DRIVE}2
-if [ ! -b ${PARTITION2} ]; then
- PARTITION2=${DRIVE}p2
-fi
-
-# now make partitions.
-if [ -b ${PARTITION1} ]; then
- umount ${PARTITION1} || true
- mkfs.ext2 -L "boot" ${PARTITION1}
-else
- echo "Cant find boot partition in /dev"
- exit 1
-fi
-
-if [ -b ${PARITION2} ]; then
- umount ${PARTITION2} || true
- mke2fs -t ext3 -j -L "rootfs" ${PARTITION2}
-else
- echo "Cant find rootfs partition in /dev"
- exit 1
-fi
diff --git a/qt-ostree/ostree-grub-generator b/qt-ostree/ostree-grub-generator
new file mode 100755
index 0000000..ca47dfb
--- /dev/null
+++ b/qt-ostree/ostree-grub-generator
@@ -0,0 +1,107 @@
+#!/bin/sh
+
+# This script is called by ostree/src/libostree/ostree-bootloader-grub2.c whenever
+# boot loader configuration file needs to be updated. It can be used as a template
+# for a custom grub.cfg generator. When writing a custom grub.cfg generator:
+#
+# 1) cp ostree-grub-generator ostree-grub-generator-mydevice
+# 2) Edit ostree-grub-generator-mydevice
+# 3) Pass ostree-grub-generator-mydevice to qt-ostree via --grub2-cfg-generator
+# 4) Examine the generated grub.cfg file in the OTA sysroot (created by --create-initial-deployment)
+#
+# WARNINGS:
+#
+# - Do not modify populate_menu() function, unless you know what you are doing. This function
+# converts boot loader entries (https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/)
+# into GRUB2 menuentry sections.
+#
+# - Be aware that this script is executed not only on a host machine, but also on a
+# target device, thus think about shell portability. Target device for example might
+# be using busybox with a limited shell.
+
+set -e
+
+script=$(basename ${0})
+# Atomically safe location where to generete grub.cfg when executing OTA update.
+new_grub2_cfg=${2}
+entries_path=$(dirname $new_grub2_cfg)/entries
+
+read_config()
+{
+ config_file=${entries_path}/${1}
+ title=""
+ initrd=""
+ options=""
+ linux=""
+
+ while read -r line
+ do
+ record=$(echo ${line} | cut -f 1 -d ' ')
+ value=$(echo ${line} | cut -s -f2- -d ' ')
+ case "${record}" in
+ "title")
+ title=${value}
+ ;;
+ "initrd")
+ initrd=${value}
+ ;;
+ "linux")
+ linux=${value}
+ ;;
+ "options")
+ options=${value}
+ ;;
+ esac
+ done < ${config_file}
+
+ if [ -z "${title}" ]; then
+ title="(Untitled)"
+ fi
+}
+
+populate_menu()
+{
+ # We need to prepend "boot/" prefix when boot/ directory is on the same
+ # partition as usr/ - this is the layout we have on Intel NUC boards, the
+ # only board with GRUB boot loader that we support at the moment. When there
+ # will be more boards, determine boot_prefix at runtime.
+ boot_prefix="/boot"
+
+ for config in $(ls ${entries_path}); do
+ read_config ${config}
+ menu="${menu}menuentry '${title}' {\n"
+ menu="${menu}\t linux ${boot_prefix}/${linux} ${options}\n"
+ menu="${menu}\t initrd ${boot_prefix}/${initrd}\n"
+ menu="${menu}}\n\n"
+ done
+ # printf seems to be more reliable across shells for special character (\n, \t) evaluation
+ printf "$menu" >> ${new_grub2_cfg}
+}
+
+populate_warning()
+{
+cat >> ${new_grub2_cfg} <<EOF
+# This file was generated by ${script}. Do not modify the generated file - all
+# changes will be lost when this file will be regenerated by OSTree. For more
+# details refer to ${script} script.
+EOF
+}
+
+populate_header()
+{
+cat >> ${new_grub2_cfg} <<EOF
+serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
+default=boot
+timeout=10
+
+EOF
+}
+
+generate_grub2_cfg()
+{
+ populate_warning
+ populate_header
+ populate_menu
+}
+
+generate_grub2_cfg
diff --git a/qt-ostree/qt-ostree b/qt-ostree/qt-ostree
index 3b7490c..8e016fe 100755
--- a/qt-ostree/qt-ostree
+++ b/qt-ostree/qt-ostree
@@ -24,6 +24,7 @@ if [ -n "${QT_OSTREE_DEBUG}" ] ; then
set -x
fi
set -e
+shopt -s extglob
trap handle_non_zero_exit EXIT
ROOT=$(dirname $(readlink -f $0))
@@ -31,7 +32,6 @@ WORKDIR=$PWD
GENERATED_TREE=${WORKDIR}/tree
BOOT_FILE_PATH=${GENERATED_TREE}/boot
-UBOOT_ENV_FILE=""
SERVER_ROOT=${WORKDIR}/httpd
OTA_SYSROOT=false
START_HTTPD=false
@@ -39,6 +39,11 @@ INVALID_ARGS=false
BINARY_IMAGE=false
VERBOSE=""
OS_NAME="qt-os"
+# HARDWARE INTEGRATION
+DEVICE=""
+BOOTLOADER="u-boot"
+UBOOT_ENV_FILE=""
+GRUB2_CFG_GENERATOR=""
# REPO
OSTREE_REPO=${WORKDIR}/ostree-repo
OSTREE_BRANCH=linux/qt
@@ -55,8 +60,14 @@ GPG_KEY=""
GPG_HOMEDIR=""
GPG_TRUSTED_KEYRING=""
GPG_KEYS_PATH=${GENERATED_TREE}/usr/share/ostree/trusted.gpg.d/
-# PRIVATE
-PACK_DEPLOY=true
+# DD IMAGE
+ROOTFS_TYPE="ext3"
+ROOTFS_OPT="-F -L rootfs"
+BOOTFS_TYPE="ext2"
+BOOTFS_OPT="-F -L boot-ostree" # When /boot directory is on a separate partition from rootfs, ostree-remount attempts to mount filesystem where LABEL=boot-ostree
+BOOTFS_SIZE="65536" # Boot partition size [in KiB]
+ROOT_OVERHEAD_FACTOR="1.3" # Add 30% extra space in rootfs
+IMAGE_ROOTFS_ALIGNMENT="4096" # Set alignment to 4MB [in KiB]
exit_qt_ostree()
{
@@ -99,9 +110,7 @@ initialize()
fi
rpath=$(objdump -x ${ostree} | grep RPATH | awk '{print $2}')
if [ "${rpath}" != "\$ORIGIN/lib/" ] ; then
- msg="This script depends on 'ostree' binary from the SDK, "
- msg+="but PATH is set to ${ostree}."
- print_usage_header "$msg"
+ print_usage_header "This script depends on 'ostree' binary from the SDK, but PATH is set to ${ostree}."
exit_qt_ostree 1
fi
}
@@ -113,6 +122,7 @@ usage()
echo "--sysroot-image-path DIR A path to embedded linux sysroot *.tar.gz or *.img image files."
echo "--initramfs FILE OSTree boot compatible initramfs."
echo "--uboot-env-file FILE OSTree boot compatible u-boot environment file."
+ echo "--grub2-cfg-generator FILE GRUB2 configuration generator script."
echo
echo "--ostree-repo DIR Commits the generated tree into this repository. If the repository does not exist, "
echo " one is created in the specified location. If this argument is not provided, "
@@ -230,6 +240,10 @@ parse_args()
UBOOT_ENV_FILE=$(readlink -m ${2})
shift 1
;;
+ --grub2-cfg-generator)
+ GRUB2_CFG_GENERATOR=$(readlink -m ${2})
+ shift 1
+ ;;
--tls-ca-path)
SERVER_CERT=$(readlink -m ${2})
shift 1
@@ -293,6 +307,7 @@ parse_args()
validate_arg "--sysroot-image-path" "${SYSROOT_IMAGE_PATH}" true d
validate_arg "--initramfs" "${INITRAMFS}" true f
validate_arg "--uboot-env-file" "${UBOOT_ENV_FILE}" false f
+ validate_arg "--grub2-cfg-generator" "${GRUB2_CFG_GENERATOR}" false f
validate_arg "--gpg-homedir" "${GPG_HOMEDIR}" false d
validate_arg "--gpg-trusted-keyring" "${GPG_TRUSTED_KEYRING}" false f
validate_arg "--tls-ca-path" "${SERVER_CERT}" false f
@@ -315,6 +330,25 @@ parse_args()
fi
}
+clean_workdir()
+{
+ cd ${WORKDIR}/
+
+ dir_list="boot-mount rootfs-mount boot-dd rootfs-dd"
+ for dir in $dir_list ; do
+ if mountpoint -q ${dir} ; then
+ umount ${dir}
+ fi
+ rm -rf ${dir}
+ done
+
+ # Remove immutable attribute.
+ chattr -if sysroot/ostree/deploy/*/deploy/* || /bin/true
+ rm -rf sysroot
+ rm -rf ${GENERATED_TREE}
+ rm -rf fakepath
+}
+
find_and_rename_kernel()
{
cd ${BOOT_FILE_PATH}/
@@ -333,7 +367,9 @@ organize_boot_files()
{
cp ${INITRAMFS} ${BOOT_FILE_PATH}/initramfs
find_and_rename_kernel
- if [ -n "${UBOOT_ENV_FILE}" ] ; then
+
+ # Boot loader companions.
+ if [[ "${BOOTLOADER}" = "u-boot" && -n "${UBOOT_ENV_FILE}" ]] ; then
cp ${UBOOT_ENV_FILE} ${BOOT_FILE_PATH}/
name=$(basename ${UBOOT_ENV_FILE})
if [ "${name}" != "uEnv.txt" ] ; then
@@ -347,6 +383,14 @@ organize_boot_files()
fi
fi
fi
+
+ if [ "${BOOTLOADER}" = "grub2" ] ; then
+ if [ -z "${GRUB2_CFG_GENERATOR}" ] ; then
+ # Use default generator.
+ GRUB2_CFG_GENERATOR=${ROOT}/ostree-grub-generator
+ fi
+ cp ${GRUB2_CFG_GENERATOR} ${GENERATED_TREE}/usr/sbin/ostree-grub-generator
+ fi
}
adjust_sysroot_layout()
@@ -412,7 +456,6 @@ convert_to_ostree_sysroot()
mv initramfs initramfs-${bootcsum}
# OSTree requires /etc/os-release file (see The Boot Loader Specification).
- # U-boot does not have multi-boot menu so it doesn't really matter what we put here.
if [ ! -e ${GENERATED_TREE}/etc/os-release ] ; then
echo "PRETTY_NAME=\"${OS_NAME}\"" > ${GENERATED_TREE}/etc/os-release
fi
@@ -478,56 +521,136 @@ commit_generated_tree()
ostree --repo=${OSTREE_REPO} fsck
}
+configure_boot_loader()
+{
+ if [ "${BOOTLOADER}" = "u-boot" ] ; then
+ mkdir -p sysroot/boot/loader.0/
+ ln -s loader.0 sysroot/boot/loader
+ touch sysroot/boot/loader/uEnv.txt
+ ln -s loader/uEnv.txt sysroot/boot/uEnv.txt
+ # Add convenience symlinks, for details see ostree/src/libostree/ostree-bootloader-uboot.c
+ for file in ${BOOT_FILE_PATH}/* ; do
+ name=$(basename $file)
+ if [[ ! -f $file || $name == *.dtb || $name == initramfs-* || $name == vmlinuz-* ]] ; then
+ continue
+ fi
+ ln -sf loader/${name} sysroot/boot/${name}
+ done
+ fi
+
+ if [ "${BOOTLOADER}" = "grub2" ] ; then
+ mkdir -p sysroot/boot/grub2/
+ ln -s ../loader/grub.cfg sysroot/boot/grub2/grub.cfg
+ KERNEL_ARGS="--karg=root=LABEL=rootfs ${KERNEL_ARGS}"
+ # Add ostree-grub-generator to the PATH.
+ # https://bugzilla.gnome.org/show_bug.cgi?id=762220
+ mkdir -p ${WORKDIR}/fakepath
+ cp ${GRUB2_CFG_GENERATOR} ${WORKDIR}/fakepath/ostree-grub-generator
+ export PATH=${WORKDIR}/fakepath:$PATH
+ fi
+}
+
+populate_filesystem_images()
+{
+ mkdir rootfs-dd boot-dd
+ mount boot.${BOOTFS_TYPE} boot-dd/
+ mount rootfs.${ROOTFS_TYPE} rootfs-dd/
+
+ if [[ ${DEVICE} = *nuc* ]] ; then
+ mcopy -s -i boot.${BOOTFS_TYPE} ${GENERATED_TREE}/boot/EFI ::/EFI
+ # The whole sysroot on the same partition.
+ cp -rd sysroot/* rootfs-dd/
+ return
+ fi
+
+ # boot/ directory on a separate boot partition.
+ cp -rd sysroot/!(boot) rootfs-dd/
+ cp -rd sysroot/boot/* boot-dd/
+}
+
+# Disk layout:
+#
+# 0 -> IMAGE_ROOTFS_ALIGNMENT - reserved to boot loader (not partitioned)
+# IMAGE_ROOTFS_ALIGNMENT -> BOOTFS_SIZE - kernel and other data (boot partition)
+# BOOTFS_SIZE -> rootfs_size - rootfs (rootfs partition)
+#
+# ------------------------ ------------ ------------------------ -------------------------------
+# | IMAGE_ROOTFS_ALIGNMENT | BOOTFS_SIZE | rootfs_size | IMAGE_ROOTFS_ALIGNMENT |
+# ------------------------ ------------ ------------------------ -------------------------------
+
+assemble_dd_image()
+{
+ cd ${WORKDIR}
+ echo "Creating a deployable image..."
+ # Align boot partition and calculate total binary image size.
+ sysroot_size=$(du -sk sysroot/ | cut -f1)
+ rootfs_size=$(echo ${sysroot_size}*${ROOT_OVERHEAD_FACTOR} | bc | cut -f1 -d'.')
+ bootfs_size_aligned=$(( ${BOOTFS_SIZE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1 ))
+ bootfs_size_aligned=$(( ${bootfs_size_aligned} - ${bootfs_size_aligned} % ${IMAGE_ROOTFS_ALIGNMENT} ))
+ image_size=$(( ${IMAGE_ROOTFS_ALIGNMENT} + ${bootfs_size_aligned} + ${rootfs_size} + ${IMAGE_ROOTFS_ALIGNMENT} ))
+
+ # Initialize a sparse file.
+ image="${DEVICE}-ota.img"
+ rm -f ${image}
+ dd if=/dev/zero of=${image} bs=1k count=0 seek=${image_size}
+
+ # Create a partition table.
+ bootfs_start=${IMAGE_ROOTFS_ALIGNMENT}
+ bootfs_end=$(( ${IMAGE_ROOTFS_ALIGNMENT} + ${bootfs_size_aligned} ))
+ rootfs_end=$(( ${IMAGE_ROOTFS_ALIGNMENT} + ${bootfs_size_aligned} + ${rootfs_size} ))
+ if [ "${BOOTFS_TYPE}" = "vfat" ] ; then
+ fs_type="FAT32"
+ fi
+ parted -s ${image} mklabel msdos
+ parted -s ${image} unit KiB mkpart primary ${fs_type} ${bootfs_start} ${bootfs_end}
+ parted -s ${image} unit KiB mkpart primary ${bootfs_end} ${rootfs_end}
+ parted -s ${image} set 1 boot on
+ parted ${image} print
+
+ # Create filesystem images.
+ rm -f rootfs.${ROOTFS_TYPE} boot.${BOOTFS_TYPE}
+ dd if=/dev/zero of=boot.${BOOTFS_TYPE} seek=${bootfs_size_aligned} count=0 bs=1k
+ mkfs.${BOOTFS_TYPE} ${BOOTFS_OPT} boot.${BOOTFS_TYPE}
+ dd if=/dev/zero of=rootfs.${ROOTFS_TYPE} seek=${rootfs_size} count=0 bs=1k
+ mkfs.${ROOTFS_TYPE} ${ROOTFS_OPT} rootfs.${ROOTFS_TYPE}
+
+ populate_filesystem_images
+ sync
+
+ # Burn partitions.
+ dd if=boot.${BOOTFS_TYPE} of=${image} conv=notrunc seek=${bootfs_start} bs=1k && sync && sync
+ dd if=rootfs.${ROOTFS_TYPE} of=${image} conv=notrunc seek=${bootfs_end} bs=1k && sync && sync
+
+ echo
+ echo "Created a binary image - ${image}, deployable with dd command."
+ echo "Example: sudo dd bs=4M if=${image} of=/dev/sdX && sync"
+ echo
+}
+
create_initial_deployment()
{
- echo "Preparing initial deployment in ${WORKDIR}/sysroot/ ..."
cd ${WORKDIR}
- # Remove immutable attribute (and ignore return code).
- chattr -if sysroot/ostree/deploy/*/deploy/* || /bin/true
- rm -rf sysroot
mkdir -p sysroot/sysroot/
export OSTREE_SYSROOT=sysroot
ostree admin init-fs sysroot
ostree admin os-init ${OS_NAME}
- # Tell OSTree to use U-Boot boot loader backend.
- mkdir -p sysroot/boot/loader.0/
- ln -s loader.0 sysroot/boot/loader
- touch sysroot/boot/loader/uEnv.txt
- ln -s loader/uEnv.txt sysroot/boot/uEnv.txt
- # Add convenience symlinks, for details see ostree/src/libostree/ostree-bootloader-uboot.c
- for file in ${BOOT_FILE_PATH}/* ; do
- name=$(basename $file)
- if [[ ! -f $file || $name == *.dtb || $name == initramfs-* || $name == vmlinuz-* ]] ; then
- continue
- fi
- ln -sf loader/${name} sysroot/boot/${name}
- done
+
+ configure_boot_loader
ostree --repo=sysroot/ostree/repo pull-local --remote=${OS_NAME} ${OSTREE_REPO} ${OSTREE_BRANCH}
- ostree admin deploy --os=${OS_NAME} ${OS_NAME}:${OSTREE_BRANCH}
+ ostree admin deploy --verbose ${KERNEL_ARGS} --os=${OS_NAME} ${OS_NAME}:${OSTREE_BRANCH}
ostree admin status
# OSTree does not touch the contents of /var, it is the OS responsibility to manage this directory.
rm -rf sysroot/ostree/deploy/${OS_NAME}/var/
cp -r ${GENERATED_TREE}/var/ sysroot/ostree/deploy/${OS_NAME}/
- # Pack the OTA ready sysroot.
- if [ $PACK_DEPLOY = true ] ; then
- echo "Packing initial deployment ..."
- rm -rf boot.tar.gz rootfs.tar.gz
- tar -pcz${VERBOSE}f boot.tar.gz -C sysroot/boot/ .
- mv sysroot/boot/ .
- tar -pcz${VERBOSE}f rootfs.tar.gz -C sysroot/ .
- mv boot/ sysroot/
- if [ "${ROOT}" != "${WORKDIR}" ] ; then
- cp ${ROOT}/deploy.sh ${ROOT}/mkcard.sh ${WORKDIR}/
- fi
- fi
+
+ assemble_dd_image
}
extract_sysroot()
{
- rm -rf ${GENERATED_TREE}
mkdir ${GENERATED_TREE}/
mkdir ${BOOT_FILE_PATH}/
@@ -542,29 +665,15 @@ extract_sysroot()
boot_start=$(fdisk -l ${image} | grep ${image}1 | awk '{print $3}')
fi
rootfs_start=$(fdisk -l ${image} | grep ${image}2 | awk '{print $2}')
- boot_offset=$(expr ${units} \* ${boot_start})
- rootfs_offset=$(expr ${units} \* ${rootfs_start})
+ boot_offset=$(( ${units} * ${boot_start} ))
+ rootfs_offset=$(( ${units} * ${rootfs_start} ))
cd ${WORKDIR}/
- if [ -d boot-mount ] ; then
- # Ignore return code.
- umount boot-mount || /bin/true
- rm -rf boot-mount
- fi
- if [ -d rootfs-mount ] ; then
- # Ignore return code.
- umount rootfs-mount || /bin/true
- rm -rf rootfs-mount
- fi
-
mkdir boot-mount rootfs-mount
mount -o loop,offset=${boot_offset} ${image} boot-mount/
mount -o loop,offset=${rootfs_offset} ${image} rootfs-mount/
- cp -r boot-mount/* ${BOOT_FILE_PATH}
- cp -r rootfs-mount/* ${GENERATED_TREE}
- umount boot-mount
- umount rootfs-mount
- rm -rf boot-mount rootfs-mount
+ cp -rd boot-mount/* ${BOOT_FILE_PATH}
+ cp -rd rootfs-mount/* ${GENERATED_TREE}
else
# Extract *.tar.gz image files.
for image in ${SYSROOT_IMAGE_PATH}/*.tar.gz ; do
@@ -589,13 +698,37 @@ start_httpd_server()
ostree trivial-httpd --autoexit --daemonize -p ${SERVER_ROOT}/httpd-port
PORT=$(cat ${SERVER_ROOT}/httpd-port)
echo "http://127.0.0.1:${PORT}/ostree" > ${SERVER_ROOT}/httpd-address
+ echo "OTA update repository available on $(cat ${SERVER_ROOT}/httpd-address)"
+}
+
+detect_target_device()
+{
+ hostname_file=${GENERATED_TREE}/etc/hostname
+ DEVICE=$(cat ${hostname_file})
+ if [ -z "${DEVICE}" ] ; then
+ echo "error: no hostname specified in ${hostname_file}"
+ exit_qt_ostree 1
+ fi
+
+ case "${DEVICE}" in
+ *nuc*) # Intel NUC
+ BOOTLOADER="grub2"
+ BOOTFS_TYPE="vfat"
+ BOOTFS_OPT="-n boot"
+ ;;
+ esac
+
+ echo "Detected ${DEVICE} device with ${BOOTLOADER} boot loader."
}
main()
{
parse_args "$@"
+ clean_workdir
extract_sysroot
+ detect_target_device
+
convert_to_ostree_sysroot
commit_generated_tree
@@ -607,6 +740,8 @@ main()
start_httpd_server
fi
+ clean_workdir
+
echo "Done."
exit_qt_ostree 0
}