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 <kirill.kapranov@compulab.co.il>
This commit is contained in:
Kirill Kapranov
2020-08-25 18:32:42 +03:00
parent dc95dee7f1
commit c856feed8a
3 changed files with 87 additions and 1 deletions
@@ -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 <kirill.kapranov@compulab.com>"
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)"
+54
View File
@@ -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
+1 -1
View File
@@ -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