summaryrefslogtreecommitdiff
path: root/recipes-core/initscripts
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2021-09-14 12:11:42 -0500
committerJohn Klug <john.klug@multitech.com>2021-10-05 14:28:44 -0500
commitc0391dcd8a519c61568bbeba13c9985dd62a3f96 (patch)
treec5501d681637d637214de9f9076f845a60a300db /recipes-core/initscripts
parent657fc2cdcdfdc9d1e5db99d710ebe5af528ce62f (diff)
downloadmeta-mlinux-c0391dcd8a519c61568bbeba13c9985dd62a3f96.tar.gz
meta-mlinux-c0391dcd8a519c61568bbeba13c9985dd62a3f96.tar.bz2
meta-mlinux-c0391dcd8a519c61568bbeba13c9985dd62a3f96.zip
Fix md5 test to avoid duplicate images, and add /var/volatile/do_wipe flag
Diffstat (limited to 'recipes-core/initscripts')
-rw-r--r--recipes-core/initscripts/initscripts-1.0/umountfs73
1 files changed, 64 insertions, 9 deletions
diff --git a/recipes-core/initscripts/initscripts-1.0/umountfs b/recipes-core/initscripts/initscripts-1.0/umountfs
index dd78a0e..c3d217e 100644
--- a/recipes-core/initscripts/initscripts-1.0/umountfs
+++ b/recipes-core/initscripts/initscripts-1.0/umountfs
@@ -9,8 +9,27 @@
# Description:
### END INIT INFO
+# The firmware upgrade script initializes the flash_upgrade directory
+# for doing the upgrade.
+#
+# If you wish to erase /var/volatile and any U-Boot environment, along
+# with user-data, do touch /var/volatile/do_wipe
+#
+# Note that /var/oem is not touched. /var/oem could be erased manually
+# as follows:
+#
+# Verify the partition:
+#
+# grep 'OEM Config' /proc/mtd
+#
+# Assuming /var/config is /dev/mtd7:
+#
+# umount -l /var/oem
+# flash_erase -j /dev/mtd7 0 0
+
PATH=/sbin:/bin:/usr/sbin:/usr/bin
upgrade_fname="/var/volatile/do_flash_upgrade"
+wipe_fname="/var/volatile/do_wipe"
umount_all() {
echo "Deactivating swap..."
@@ -119,6 +138,9 @@ flash_upgrade() {
local rootfs_mtd=
local kernel_mtd=
local uboot_mtd=
+ local ubootenv1_mtd=
+ local ubootenv2_mtd=
+ local userd_mtd=
local bootstrap_file=bstrap.bin
local config_file=config.jffs2
local oem_file=oem.jffs2
@@ -183,12 +205,30 @@ flash_upgrade() {
return
fi
+ ubootenv1_mtd="/dev/$(cat /proc/mtd | grep '\"u-Boot Config\"' | cut -d : -f 1)"
+ if [ ! -c "${uboot_mtd}" ]; then
+ echo "No valid MTD partition is labeled u-Boot"
+ return
+ fi
+
+ ubootenv2_mtd="/dev/$(cat /proc/mtd | grep '\"u-Boot Redundant Config\"' | cut -d : -f 1)"
+ if [ ! -c "${uboot_mtd}" ]; then
+ echo "No valid MTD partition is labeled u-Boot"
+ return
+ fi
+
rootfs_mtd="/dev/$(cat /proc/mtd | grep '\"Rootfs\"' | cut -d : -f 1)"
if [ ! -c "${rootfs_mtd}" ]; then
echo "No valid MTD partition is labeled Rootfs"
return
fi
+ userd_mtd="/dev/$(cat /proc/mtd | grep '\"User data\"' | cut -d : -f 1)"
+ if [ ! -c "${userd_mtd}" ]; then
+ echo "No valid MTD partition is labeled User data"
+ return
+ fi
+
cd /var/volatile
# rootfs should always be flashed last, so always keep it last here
@@ -245,7 +285,7 @@ flash_upgrade() {
if [[ ${flash_root} == /var/volatile ]] ; then
oldIFS="${IFS}"
- IFS=$'\n' rmlist=($(find ${flash_root} -xdev -maxdepth 1 -print | egrep -v "^${flash_root}$|^${flash_dir}$|^${flash_dir}/"))
+ IFS=$'\n' rmlist=($(find ${flash_root} -xdev -maxdepth 1 -print | egrep -v "^.*.md5$|^${flash_root}$|^${flash_dir}$|^${flash_dir}/"))
IFS="${oldIFS}"
((i=0))
while((i < ${#rmlist[@]})) ; do
@@ -304,16 +344,16 @@ flash_upgrade() {
fi
echo "Flashing ${dev} with ${file}..."
- flash_erase -j ${dev} 0 0
- tar -xO -f ${upgrade_file} ${file} | ${flash_dir}/nandwrite.static -p ${dev}
+ flash_erase ${extraopt} -j ${dev} 0 0
+ tar -xO -f ${upgrade_file} ${file} | ${flash_dir}/nandwrite.static ${extraopt} -p ${dev}
fi
done
else
if [ -f ${uboot_solo_file} ]; then
echo "Flashing ${uboot_mtd} (u-boot) with ${uboot_solo_file}..."
- flash_erase ${uboot_mtd} 0 0
- ${flash_dir}/nandwrite.static -p ${uboot_mtd} ${uboot_solo_file}
+ flash_erase ${extraopt} ${uboot_mtd} 0 0
+ ${flash_dir}/nandwrite.static ${extraopt} -p ${uboot_mtd} ${uboot_solo_file}
else
echo "u-boot file ${uboot_solo_file} not found"
fi
@@ -321,8 +361,8 @@ flash_upgrade() {
if [ -f ${kernel_solo_file} ]; then
echo "Flashing ${kernel_mtd} (uImage) with ${kernel_solo_file}..."
- flash_erase ${kernel_mtd} 0 0
- ${flash_dir}/nandwrite.static -p ${kernel_mtd} ${kernel_solo_file}
+ flash_erase ${extraopt} ${kernel_mtd} 0 0
+ ${flash_dir}/nandwrite.static ${extraopt} -p ${kernel_mtd} ${kernel_solo_file}
else
echo "uImage file ${kernel_solo_file} not found"
fi
@@ -330,13 +370,20 @@ flash_upgrade() {
if [ -f ${rootfs_solo_file} ]; then
echo "Flashing ${rootfs_mtd} (rootfs) with ${rootfs_solo_file}..."
- flash_erase -j ${rootfs_mtd} 0 0
- ${flash_dir}/nandwrite.static -p ${rootfs_mtd} ${rootfs_solo_file}
+ flash_erase ${extraopt} -j ${rootfs_mtd} 0 0
+ ${flash_dir}/nandwrite.static ${extraopt} -p ${rootfs_mtd} ${rootfs_solo_file}
else
echo "rootfs file ${rootfs_solo_file} not found"
fi
fi
+ if ((wipe == 1)) ; then
+ echo 'Wiping out all partitions except /var/oem'
+ flash_erase ${extraopt} -j ${config_mtd} 0 0
+ flash_erase ${extraopt} -j ${userd_mtd} 0 0
+ flash_erase ${extraopt} ${ubootenv1_mtd} 0 0
+ flash_erase ${extraopt} ${ubootenv2_mtd} 0 0
+ fi
echo "Rebooting..."
${flash_dir}/upgrade-reboot
@@ -348,6 +395,14 @@ flash_upgrade() {
# do flash on reboot if do_flash_upgrade exists
# and is owned by root
+wipe=0
+if [[ -f ${wipe_fname} ]] ; then
+ owner=$(stat -c%u "${wipe_fname}")
+ if ((${#owner} > 0)) && ((owner == 0)) ; then
+ wipe=1
+ extraopt="-q"
+ fi
+fi
if [[ -f ${upgrade_fname} ]] ; then
owner=$(stat -c%u "${upgrade_fname}")
if ((${#owner} > 0)) && ((owner == 0)) ; then