From 0a64ff89e41bb93a60f0c2ea737d6d85732c5d12 Mon Sep 17 00:00:00 2001 From: Tatiana Leon Date: Fri, 24 Feb 2017 22:08:43 +0100 Subject: [PATCH] swu-images: cc6: add pre-install script to open the virtual dev For CC6, when using rootfs encryption, the encrypted device must be opened before trying to update. https://jira.digi.com/browse/DEL-3664 https://jira.digi.com/browse/DEL-3665 Signed-off-by: Tatiana Leon --- .../swu-images/core-image-base-swu.bb | 5 ++ .../swu-images/dey-image-qt-swu.bb | 5 ++ .../swu-images/files/ccimx6/preinstall_swu.sh | 83 +++++++++++++++++++ .../swu-images/files/ccimx6/sw-description | 1 + 4 files changed, 94 insertions(+) create mode 100644 meta-digi-dey/recipes-digi/swu-images/files/ccimx6/preinstall_swu.sh diff --git a/meta-digi-dey/recipes-digi/swu-images/core-image-base-swu.bb b/meta-digi-dey/recipes-digi/swu-images/core-image-base-swu.bb index e877639bf..f996cf550 100644 --- a/meta-digi-dey/recipes-digi/swu-images/core-image-base-swu.bb +++ b/meta-digi-dey/recipes-digi/swu-images/core-image-base-swu.bb @@ -5,6 +5,7 @@ LICENSE = "GPL-2.0" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6" SRC_URI = "file://sw-description" +SRC_URI_append_ccimx6 = " ${@oe.utils.ifelse(d.getVar('TRUSTFENCE_INITRAMFS_IMAGE', True), 'file://preinstall_swu.sh', '')}" inherit swupdate @@ -26,6 +27,9 @@ ROOTFS_DEV_NAME_ccimx6ul ?= "rootfs" ROOTFS_ENC_DEV = "/dev/mapper/cryptroot" ROOTFS_ENC_DEV_ccimx6ul = "${ROOTFS_DEV_NAME}" ROOTFS_DEV_NAME_FINAL = "${@oe.utils.ifelse(d.getVar('TRUSTFENCE_INITRAMFS_IMAGE', True), '${ROOTFS_ENC_DEV}', '${ROOTFS_DEV_NAME}')}" +PREINST_SCRIPT_TEMPLATE = "scripts: ( { filename = \\"preinstall_swu.sh\\"; type = \\"preinstall\\"; sha256 = \\"@preinstall_swu.sh\\"; \\x7D );" +PREINST_SCRIPT_DESC = "" +PREINST_SCRIPT_DESC_ccimx6sbc = "${@oe.utils.ifelse(d.getVar('TRUSTFENCE_INITRAMFS_IMAGE', True), '${PREINST_SCRIPT_TEMPLATE}', '')}" python () { img_fstypes = d.getVar('BOOTFS_EXT', True) + " " + d.getVar('ROOTFS_EXT', True) @@ -40,4 +44,5 @@ fill_description() { sed -i -e "s,##ROOTIMG_NAME##,core-image-base-${MACHINE}${ROOTFS_EXT},g" "${WORKDIR}/sw-description" sed -i -e "s,##ROOTFS_DEV##,${ROOTFS_DEV_NAME_FINAL},g" "${WORKDIR}/sw-description" sed -i -e "s,##SW_VERSION##,${SOFTWARE_VERSION},g" "${WORKDIR}/sw-description" + sed -i -e "s/##PREINSTALL_SCRIPT##/${PREINST_SCRIPT_DESC}/g" "${WORKDIR}/sw-description" } diff --git a/meta-digi-dey/recipes-digi/swu-images/dey-image-qt-swu.bb b/meta-digi-dey/recipes-digi/swu-images/dey-image-qt-swu.bb index 6bf4a1c11..8a8a08695 100644 --- a/meta-digi-dey/recipes-digi/swu-images/dey-image-qt-swu.bb +++ b/meta-digi-dey/recipes-digi/swu-images/dey-image-qt-swu.bb @@ -5,6 +5,7 @@ LICENSE = "GPL-2.0" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6" SRC_URI = "file://sw-description" +SRC_URI_append_ccimx6 = " ${@oe.utils.ifelse(d.getVar('TRUSTFENCE_INITRAMFS_IMAGE', True), 'file://preinstall_swu.sh', '')}" inherit swupdate @@ -26,6 +27,9 @@ ROOTFS_DEV_NAME_ccimx6ul ?= "rootfs" ROOTFS_ENC_DEV = "/dev/mapper/cryptroot" ROOTFS_ENC_DEV_ccimx6ul = "${ROOTFS_DEV_NAME}" ROOTFS_DEV_NAME_FINAL = "${@oe.utils.ifelse(d.getVar('TRUSTFENCE_INITRAMFS_IMAGE', True), '${ROOTFS_ENC_DEV}', '${ROOTFS_DEV_NAME}')}" +PREINST_SCRIPT_TEMPLATE = "scripts: ( { filename = \\"preinstall_swu.sh\\"; type = \\"preinstall\\"; sha256 = \\"@preinstall_swu.sh\\"; \\x7D );" +PREINST_SCRIPT_DESC = "" +PREINST_SCRIPT_DESC_ccimx6sbc = "${@oe.utils.ifelse(d.getVar('TRUSTFENCE_INITRAMFS_IMAGE', True), '${PREINST_SCRIPT_TEMPLATE}', '')}" python () { img_fstypes = d.getVar('BOOTFS_EXT', True) + " " + d.getVar('ROOTFS_EXT', True) @@ -40,4 +44,5 @@ fill_description() { sed -i -e "s,##ROOTIMG_NAME##,dey-image-qt-${GRAPHICAL_BACKEND}-${MACHINE}${ROOTFS_EXT},g" "${WORKDIR}/sw-description" sed -i -e "s,##ROOTFS_DEV##,${ROOTFS_DEV_NAME_FINAL},g" "${WORKDIR}/sw-description" sed -i -e "s,##SW_VERSION##,${SOFTWARE_VERSION},g" "${WORKDIR}/sw-description" + sed -i -e "s/##PREINSTALL_SCRIPT##/${PREINST_SCRIPT_DESC}/g" "${WORKDIR}/sw-description" } diff --git a/meta-digi-dey/recipes-digi/swu-images/files/ccimx6/preinstall_swu.sh b/meta-digi-dey/recipes-digi/swu-images/files/ccimx6/preinstall_swu.sh new file mode 100644 index 000000000..07bca0909 --- /dev/null +++ b/meta-digi-dey/recipes-digi/swu-images/files/ccimx6/preinstall_swu.sh @@ -0,0 +1,83 @@ +#!/bin/sh +#=============================================================================== +# +# preinstall_swu.sh +# +# Copyright (C) 2017 by Digi International Inc. +# 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 version 2 as published by +# the Free Software Foundation. +# +# !Description: SWUpdate pre-install script to open the virtual mapped device +# +# SWUpdate calls this script before installing the image. +# +#=============================================================================== + +# Functions. +#------------------------------------------------------------------------------ +# Function - psplash_message +# +# Shows the given message in the psplash screen. +# +# @param ${1} - Message to show. +#------------------------------------------------------------------------------ +psplash_message() { + echo "MSG ${1}" > /tmp/psplash_fifo + sleep 0.2 +} + +#------------------------------------------------------------------------------ +# Function - psplash_progress +# +# Sets the psplash progress bar percentage to the given one. +# +# @param ${1} - Progress percentage. +#------------------------------------------------------------------------------ +psplash_progress() { + echo "PROGRESS ${1}" > /tmp/psplash_fifo + sleep 0.2 +} + +#------------------------------------------------------------------------------ +# Function - log +# +# Prints the given text in the console. +# +# @param ${1} - Text to print. +#------------------------------------------------------------------------------ +log() { + echo "[FW UPDATE] ${1}" +} + +#------------------------------------------------------------------------------ +# Function - log_error +# +# Prints the given text in the console as an error. +# +# @param ${1} - Error text to print. +#------------------------------------------------------------------------------ +log_error() { + log "[ERROR] ${1}" + psplash_message "ERROR: ${1}" + psplash_progress "0" +} + +# Main +#------------------------------------------------------------------------------ +# Check if encrypted device is already open. +if [ -b /dev/mapper/cryptroot ]; then + exit 0 +fi + +rootfs_block="/dev/mmcblk0p$(parted -s /dev/mmcblk0 print | sed -ne "s,^[^0-9]*\([0-9]\+\).*\.*,\1,g;T;p")" + +# Open LUKS encrypted device +trustfence-tool ${rootfs_block} cryptroot +if [ "$?" != "0" ]; then + log_error "Error executing the firmware update, cannot open virtual device" + exit 1 +fi + diff --git a/meta-digi-dey/recipes-digi/swu-images/files/ccimx6/sw-description b/meta-digi-dey/recipes-digi/swu-images/files/ccimx6/sw-description index 4f4884b62..cde521bf2 100644 --- a/meta-digi-dey/recipes-digi/swu-images/files/ccimx6/sw-description +++ b/meta-digi-dey/recipes-digi/swu-images/files/ccimx6/sw-description @@ -16,4 +16,5 @@ software = sha256 = "@##ROOTIMG_NAME##"; } ); + ##PREINSTALL_SCRIPT## }