From 4fbdb4071c92c95bccfcbc923ec69477f70dad5c Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Fri, 1 Feb 2019 21:52:08 +0200 Subject: [PATCH] fwupdate: add cleanupgrade command --- board/common/overlay/etc/init.d/S00datapart | 5 +- board/common/overlay/sbin/fwupdate | 89 +++++++++++++++------ 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/board/common/overlay/etc/init.d/S00datapart b/board/common/overlay/etc/init.d/S00datapart index b1f25768eb..5c76f928fa 100755 --- a/board/common/overlay/etc/init.d/S00datapart +++ b/board/common/overlay/etc/init.d/S00datapart @@ -1,5 +1,8 @@ #!/bin/bash +DATA_OFFS="1024" # up to 1024MB reserved for boot + root + + test -n "${OS_VERSION}" || source /etc/init.d/base case "$1" in @@ -23,7 +26,7 @@ case "$1" in test -b ${data_dev} && exit 0 msg_begin "Creating data partition" - data_start=$((1024 * 2048)) # up to 1024MB reserved for boot + root + data_start=$((DATA_OFFS * 2048)) echo -e "n p 3 diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index 4e66f01bb5..2bdc879257 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -4,14 +4,15 @@ #### usage #### function exit_usage() { - echo "Usage: fwupdate versions [-j] (lists available versions, optionally outputting json)" - echo " fwupdate current (shows the current version" - echo " fwupdate download (downloads a firmware version)" - echo " fwupdate extract (extracts the downloaded firmware archive)" - echo " fwupdate flashboot (flashes the boot partition from extracted image)" - echo " fwupdate flashreboot (prepares for reboot + root partititon flash)" - echo " fwupdate status (shows the current firmware updating status; see below)" - echo " fwupdate upgrade (performs all the operations necessary for upgrading)" + echo "Usage: fwupdate versions [-j] (lists available versions, optionally outputting json)" + echo " fwupdate current (shows the current version" + echo " fwupdate download (downloads a firmware version)" + echo " fwupdate extract (extracts the downloaded firmware archive)" + echo " fwupdate flashboot (flashes the boot partition from extracted image)" + echo " fwupdate flashreboot (prepares for reboot + root partititon flash)" + echo " fwupdate status (shows the current firmware updating status; see below)" + echo " fwupdate upgrade (performs all the operations necessary for upgrading)" + echo " fwupdate cleanupgrade (same as upgrade, but remove data partition, preserving config files)" echo "" echo "Statuses:" echo " idle" @@ -35,6 +36,7 @@ fi SYS_VERSION_FILE=/etc/version SYS_BOARD_FILE=/etc/board +OS_CONF_FILE=/etc/init.d/os_conf MIN_FREE_DISK=$((500*1024)) # 500 MB VER_FILE=version @@ -58,6 +60,9 @@ XZCAT_PID_FILE=xzcat.pid DD_LOG_FILE=dd.log DD_PID_FILE=dd.pid +source ${OS_CONF_FILE} +source ${SYS_VERSION_FILE} + #### disk & partition devices #### @@ -77,8 +82,6 @@ fi #### versions #### function show_versions() { - source /etc/init.d/os_conf # we need this for the OS_ vars - board=$(cat ${SYS_BOARD_FILE}) show_json=$1 @@ -112,8 +115,6 @@ function show_versions() { } function show_current() { - source ${SYS_VERSION_FILE} - echo ${OS_VERSION} } @@ -144,8 +145,6 @@ function do_download() { fi fi - source /etc/init.d/os_conf # we need this for the OS_ vars - board=$(cat ${SYS_BOARD_FILE}) url=$1 version=$1 @@ -303,7 +302,7 @@ function extract_status() { #### flash boot #### -function flash_boot() { +function do_flash_boot() { echo "flashing boot..." rm -f ${FW_DIR}/${BOOT_READY_FILE} @@ -373,7 +372,7 @@ function flash_cleanup() { #### flash reboot #### -function flash_reboot() { +function do_flash_reboot() { echo "preparing for reboot..." board=$(cat ${SYS_BOARD_FILE}) @@ -397,6 +396,25 @@ function flash_reboot() { #### status #### +function new_version() { + cat ${FW_DIR}/${VER_FILE} +} + +function backup_conf() { + echo "backing up /data/etc..." + tar -acf /boot/backup-etc-${OS_VERSION}.tar.gz -C /data etc +} + +function remove_data_part() { + echo "removing data partition..." + fdisk ${DISK_DEV} >/dev/null <