HAL_PART_LIST_FILE="background_copy.list"
CONFIG_FILE="update.cfg"
SET_UPGRADE_STATUS="/usr/bin/device_board_set_upgrade_status"
+DO_RW_UPDATE_FILE="$FOTA_UPDATE_PREFIX/opt/.do_rw_update"
TRUE=0
FALSE=1
log "$1" "$LOG_FILE"
}
+untrap() {
+ trap '' ERR
+}
+
+retrap() {
+ trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
+}
+
unpack_file() {
ARCHIVE_NAME="$1"
FILE_NAME="$2"
set_upgrade_status -1
exit 1
}
+
+mount_partition() {
+ local GPT_LABEL="$1"
+ local DST="$2"
+ local MOUNT_OPTIONS="$3"
+ local SRC
+ if ! SRC="$(/usr/bin/blkid-print "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB" |\
+ /bin/sed -E 's|(part_nr: [0-9]+ )\((.*)\): (.*)|\3|')"; then
+ flog "[Error] Unable to find $GPT_LABEL partition on $EMMC_DEVICE device for $NEXT_AB slot"
+ return 1
+ fi
+ local MOUNTED="$(/bin/findmnt -n -o TARGET "$SRC" | /bin/head -n 1 || echo "")"
+ if [ "$MOUNTED" != "" ]; then
+ MOUNT_OPTIONS="bind,${MOUNT_OPTIONS}"
+ SRC="$MOUNTED"
+ fi
+ if ! /bin/mkdir -p "$DST"; then
+ flog "[Error] Unable to mkdir for mount destination: $DST"
+ return 1
+ fi
+ if ! /bin/mount -o "$MOUNT_OPTIONS" "$SRC" "$DST"; then
+ flog "[Error] Unable to mount $SRC to $DST, options: $MOUNT_OPTIONS"
+ return 1
+ fi
+ CLEANUP_PARTITION+=("$DST")
+ return 0
+}
+
+cleanup_partitions() {
+ # umount in reverse order
+ for (( idx=${#CLEANUP_PARTITION[@]}-1 ; idx>=0 ; idx-- )) ; do
+ local DST="${CLEANUP_PARTITION[idx]}"
+ if [ "$DST" == "" ]; then
+ flog "[Error] Partition for cleanup is empty, idx: $idx, partition count: ${#CLEANUP_PARTITION[@]}"
+ continue
+ fi
+ if ! /bin/umount "$DST"; then
+ flog "[Error] Unable to umount $DST"
+ fi
+
+ done
+ CLEANUP_PARTITION=()
+}
FOTA_UPDATE_PREFIX="/run/upgrade-sysroot"
VERSION_FILE="$FOTA_UPDATE_PREFIX/opt/etc/version"
-DO_RW_UPDATE_FILE="$FOTA_UPDATE_PREFIX/opt/.do_rw_update"
SCRIPT_NAME="upgrade-fota.sh"
LOG_FILE="/tmp/update-fota.log"
-untrap() {
- trap '' ERR
-}
-
-retrap() {
- trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
-}
-
-mount_partition() {
- GPT_LABEL="$1"
- DST="$2"
- MOUNT_OPTIONS="$3"
- if ! SRC="$(/usr/bin/blkid-print "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB" |\
- /bin/sed -E 's|(part_nr: [0-9]+ )\((.*)\): (.*)|\3|')"; then
- flog "[Error] Unable to find $GPT_LABEL partition on $EMMC_DEVICE device for $NEXT_AB slot"
- return 1
- fi
- MOUNTED="$(/bin/findmnt -n -o TARGET "$SRC" | /bin/head -n 1 || echo "")"
- if [ "$MOUNTED" != "" ]; then
- MOUNT_OPTIONS="bind,${MOUNT_OPTIONS}"
- SRC="$MOUNTED"
- fi
- if ! /bin/mkdir -p "$DST"; then
- flog "[Error] Unable to mkdir for mount destination: $DST"
- return 1
- fi
- if ! /bin/mount -o "$MOUNT_OPTIONS" "$SRC" "$DST"; then
- flog "[Error] Unable to mount $SRC to $DST, options: $MOUNT_OPTIONS"
- return 1
- fi
- CLEANUP_PARTITION+=("$DST")
- return 0
-}
-
cleanup() {
- # umount in reverse order
- for (( idx=${#CLEANUP_PARTITION[@]}-1 ; idx>=0 ; idx-- )) ; do
- _DST="${CLEANUP_PARTITION[idx]}"
- if [ "$_DST" == "" ]; then
- flog "[Error] Partition for cleanup is empty, idx: $idx, partition count: ${#CLEANUP_PARTITION[@]}"
- continue
- fi
- if ! /bin/umount "$_DST"; then
- flog "[Error] Unable to umount $_DST"
- fi
-
- done
- CLEANUP_PARTITION=()
+ cleanup_partitions
cleanup_files
}
. "${FOTA_DIR}"/upgrade-common.inc
DOWNLOAD_DELTA=$1
-DO_RW_UPDATE_FILE="$FOTA_UPDATE_PREFIX/opt/.do_rw_update"
SCRIPT_NAME="upgrade-full.sh"
LOG_FILE="/tmp/upgrade-trigger.log"
-CONFIG_FILE="update.cfg"
-HAL_UPGRADE_CFG_DIR="/hal/etc/upgrade/"
-HAL_PART_LIST_FILE="background_copy.list"
if [ "$#" != "1" ] || [ ! -f "$1" ]; then
log "[Error] Usage: $0 path_to_upgrade.tar[.gz]" "$LOG_FILE"
flog "[Info] Using <$DELTA_TAR> delta file."
+mount() {
+ mkdir -p "$FOTA_UPDATE_PREFIX/opt"
+ if ! mount_partition system-data "$FOTA_UPDATE_PREFIX/opt" "rw"; then
+ critical_flog "[Error] Unable to mount opt"
+ return 1
+ fi
+}
+
+cleanup() {
+ cleanup_partitions
+ cleanup_files
+}
+
cleanup_files() {
rm -f -- "$DELTA_TAR"
rm -f -- "$FOTA_DIR/$SCRIPT_NAME"
rm -f -- "$FOTA_DIR/$CONFIG_FILE"
rm -f -- "$FOTA_DIR/upgrade-common.inc"
rm -f -- "$FOTA_DIR/upgrade-trigger.sh"
+ rm -f -- "$FOTA_DIR/upgrade-apply"
}
reboot_to_fota() {
critical_flog "[Error] Failed to switch board slot to $NEXT_AB"
exit 1
fi
- cleanup_files
+ cleanup
/bin/sync
flog "[Info] Rebooting to fota"
if ! /sbin/reboot fota; then
unpack_file "$DELTA_TAR" "$CONFIG_FILE"
upgrade_images "$DOWNLOAD_DELTA"
set_upgrade_status 80
+mount
reboot_to_fota
-cleanup_files
+cleanup
SCRIPT_NAME="upgrade-partial.sh"
LOG_FILE="/tmp/upgrade-partial.log"
-CONFIG_FILE="update.cfg"
-
-untrap() {
- trap '' ERR
-}
-
-retrap() {
- trap 'echo "Aborting due to errexit on ${0##*/}:$LINENO. Exit code: $?" >&2' ERR
-}
check_args() {
DOWNLOAD_DELTA="$1"
FOTA_UPDATE_PREFIX="/run/upgrade-sysroot"
-mount_partition() {
- GPT_LABEL="$1"
- DST="$2"
- MOUNT_OPTIONS="$3"
- if ! SRC="$(/usr/bin/blkid-print "$EMMC_DEVICE" "$GPT_LABEL" "$NEXT_AB" |\
- /bin/sed -E 's|(part_nr: [0-9]+ )\((.*)\): (.*)|\3|')" || [ "$SRC" == "" ]; then
- flog "[Info] Unable to find $GPT_LABEL partition on $EMMC_DEVICE device for $NEXT_AB slot"
- return 1
- fi
- MOUNTED="$(/bin/findmnt -n -o TARGET "$SRC" | /bin/head -n 1 || echo "")"
- if [ "$MOUNTED" != "" ]; then
- MOUNT_OPTIONS="bind,${MOUNT_OPTIONS}"
- SRC="$MOUNTED"
- fi
- if ! /bin/mkdir -p "$DST"; then
- flog "[Error] Unable to mkdir for mount destination: $DST"
- return 1
- fi
- if ! /bin/mount -o "$MOUNT_OPTIONS" "$SRC" "$DST"; then
- flog "[Error] Unable to mount $SRC to $DST, options: $MOUNT_OPTIONS"
- return 1
- fi
- CLEANUP_PARTITION+=("$DST")
- return 0
-}
-
cleanup() {
- # umount in reverse order
- for (( idx=${#CLEANUP_PARTITION[@]}-1 ; idx>=0 ; idx-- )) ; do
- _DST="${CLEANUP_PARTITION[idx]}"
- if [ "$_DST" == "" ]; then
- flog "[Error] Partition for cleanup is empty, idx: $idx, partition count: ${#CLEANUP_PARTITION[@]}"
- continue
- fi
- if ! /bin/umount "$_DST"; then
- flog "[Error] Unable to umount $_DST"
- fi
-
- done
- CLEANUP_PARTITION=()
+ cleanup_partitions
cleanup_files
}