From c856feed8a699c2113eadc28116deebe98c173bd Mon Sep 17 00:00:00 2001 From: Kirill Kapranov Date: Tue, 25 Aug 2020 18:23:25 +0300 Subject: [PATCH] Add utility cl-migrate-env The of the utility is purposed for automated migration of an environment block during a u-boot update. Signed-off-by: Kirill Kapranov --- .../cl-migrate-env/cl-migrate-env.bb | 32 +++++++++++ .../cl-migrate-env/files/cl-migrate-env | 54 +++++++++++++++++++ tools/setup-compulab-env | 2 +- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 recipes-desktop/cl-migrate-env/cl-migrate-env.bb create mode 100755 recipes-desktop/cl-migrate-env/files/cl-migrate-env diff --git a/recipes-desktop/cl-migrate-env/cl-migrate-env.bb b/recipes-desktop/cl-migrate-env/cl-migrate-env.bb new file mode 100644 index 0000000..dd71886 --- /dev/null +++ b/recipes-desktop/cl-migrate-env/cl-migrate-env.bb @@ -0,0 +1,32 @@ +# Simple recipe to add executable to run automated +# CompuLab Environment Migration Tool + +DESCRIPTION = "CompuLab Environment Migrate Tool" +LICENSE = "BSD3" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9" +MAINTAINER = "Kirill Kapranov " + +PR = "r0" + +SRC_URI = " \ + file://cl-migrate-env \ +" +S = "${WORKDIR}" + +do_install() { + sed -i -e "s/\(ENV_OFF=\)[[:alnum:]]*/\1${UBOOT_ENV_OFFSET}/" \ + -e "s/\(ENV_SIZE=\)[[:alnum:]]*/\1${UBOOT_ENV_SIZE}/" \ + ${S}/cl-migrate-env + + mkdir -p ${D}/usr/local/bin/ + install -m 0755 ${S}/cl-migrate-env ${D}/usr/local/bin/ +} + +FILES_${PN} = " \ + /usr/local/bin/* \ + /usr/share/* \ +" + +RDEPENDS_${PN} = "bash dialog util-linux cl-uboot" +PACKAGE_ARCH = "${MACHINE_ARCH}" +COMPATIBLE_MACHINE = "(ucm-imx8m-mini)" diff --git a/recipes-desktop/cl-migrate-env/files/cl-migrate-env b/recipes-desktop/cl-migrate-env/files/cl-migrate-env new file mode 100755 index 0000000..823d6eb --- /dev/null +++ b/recipes-desktop/cl-migrate-env/files/cl-migrate-env @@ -0,0 +1,54 @@ +#!/bin/sh -u + +readonly ENV_DEV_LEGACY=/dev/mmcblk2 +readonly ENV_OFF_LEGACY=0x400000 +readonly ENV_DEV=${1:-${ENV_DEV_LEGACY}} +readonly ENV_OFF=0x4400 +readonly ENV_SIZE=0x1000 + +readonly FW_CONF=$(mktemp /tmp/fw_XXXX.conf) +readonly ENV_FILE=$(mktemp /tmp/env_XXXX) + +trap "rm $ENV_FILE $FW_CONF" EXIT + +function move_env() +{ + echo $ENV_DEV $ENV_OFF $ENV_SIZE > $FW_CONF + local err_mesage=$(set -o pipefail;\ + fw_setenv --config $FW_CONF --script $ENV_FILE 2>&1\ + | sed -ne'/Warning:/p' -e '/Error:/p') + local retval=$? + if [[ $retval -eq 0 ]] && [[ -z "${err_mesage}" ]]; then + dialog --infobox "Environment migration successfull" 0 0 + else + dialog --msgbox "Environment migration ERROR $retval\n$err_mesage" 0 0 + fi +} + +######## MAIN ######## +echo $ENV_DEV_LEGACY $ENV_OFF_LEGACY $ENV_SIZE > $FW_CONF +err_count=$(set -o pipefail; fw_printenv -c $FW_CONF 2>&1 >$ENV_FILE \ + | awk 'BEGIN{i=0}/Warning:|Error:/{i++}END{print i}') +retval=$? + +if [[ $retval -eq 0 ]] && [[ $err_count -eq 0 ]]; then + while :; do + dialog --extra-button --extra-label View --ok-label Move \ + --yesno "\nA legacy environment found on ${ENV_DEV_LEGACY}@${ENV_OFF_LEGACY}\n\n\ +Move it to the new location ${ENV_DEV}@${ENV_OFF}?\n" 0 0 + btn_pressed=$? + case $btn_pressed in + 0) + move_env + break + ;; + 3) + dialog --textbox $ENV_FILE 0 0 + ;; + *) + dialog --infobox "Cancelled by User" 0 0 + break + ;; + esac + done +fi diff --git a/tools/setup-compulab-env b/tools/setup-compulab-env index e2b7c21..e9c009d 100755 --- a/tools/setup-compulab-env +++ b/tools/setup-compulab-env @@ -44,7 +44,7 @@ eof mod_local() { # Modify local.conf -CORE_IMAGE_EXTRA_INSTALL+=" dhcp-client memtester cl-uboot cl-deploy cl-launcher cl-stest cl-camera u-boot-fw-utils imx-gpu-viv-demos" +CORE_IMAGE_EXTRA_INSTALL+=" dhcp-client memtester cl-uboot cl-deploy cl-migrate-env cl-launcher cl-stest cl-camera u-boot-fw-utils imx-gpu-viv-demos" CORE_IMAGE_EXTRA_INSTALL+=" htop iotop tmux iperf3" IMAGE_FEATURES+=" package-management ssh-server-openssh " cat << eof | tee -a ${LOCAL_CONF} > /dev/null