summaryrefslogtreecommitdiff
path: root/recipes-core
diff options
context:
space:
mode:
authorSerhii Voloshynov <serhii.voloshynov@globallogic.com>2023-06-06 11:25:02 +0300
committerJohn Klug <john.klug@multitech.com>2023-06-07 11:40:09 -0500
commit776d0e4e15cf0ac96730b15cdb505ccbd1e06371 (patch)
tree58fc1df728e2237b5fb32b16e9e9daf31020b4fa /recipes-core
parentf6f7a6b714dc36ab536720caff12aa30e2ffa85f (diff)
downloadmeta-mlinux-776d0e4e15cf0ac96730b15cdb505ccbd1e06371.tar.gz
meta-mlinux-776d0e4e15cf0ac96730b15cdb505ccbd1e06371.tar.bz2
meta-mlinux-776d0e4e15cf0ac96730b15cdb505ccbd1e06371.zip
failed to perform reset to factory defaults and user defaults when there is no space on /var/persistent GP-1997
Diffstat (limited to 'recipes-core')
-rw-r--r--recipes-core/multitech/overlayfs-init-jffs2/overlayfs.init55
1 files changed, 22 insertions, 33 deletions
diff --git a/recipes-core/multitech/overlayfs-init-jffs2/overlayfs.init b/recipes-core/multitech/overlayfs-init-jffs2/overlayfs.init
index 7a4d26d..5714fa3 100644
--- a/recipes-core/multitech/overlayfs-init-jffs2/overlayfs.init
+++ b/recipes-core/multitech/overlayfs-init-jffs2/overlayfs.init
@@ -12,9 +12,9 @@ TABLE=$'\n'"$(cat /proc/mtd)"
# Erase the file system
-DO_ERASE_PERSISTENT="/mnt/user/.persistent/mts_do_erase_persistent"
+DO_ERASE_PERSISTENT=$(u-boot printenv erase_persistent_f | cut -d '"' -f2 | grep -Eo '[0-9]+$' || true)
# Remove files not hidden
-DO_CLEAR_PERSISTENT="/mnt/user/.persistent/mts_do_clear_persistent"
+DO_ERASE_ALL_EXCEPT_PERSISTENT=$(u-boot printenv default_reset_f | cut -d '"' -f2 | grep -Eo '[0-9]+$' || true)
pid=$$
prefix="<3>overlayrootfs-generator[${pid}]: "
@@ -37,7 +37,7 @@ else
fi
fs="/dev /proc /sys /run /var/volatile /dev/pts /sys/kernel/debug /sys/kernel/config"
-
+
mnt_user() {
mkdir -p $MNT_USER
@@ -52,37 +52,27 @@ my_switch_root() {
for f in $fs ; do
if [[ -d $NEW_ROOT/$f ]] ; then
loginfo "my_switch_root: mount -o noatime,move --bind $f $NEW_ROOT/$f"
- mount -o noatime,move --bind $f $NEW_ROOT/$f
+ mount -o noatime,move --bind "$f" "$NEW_ROOT/$f"
else
# loginfo "my_switch_root: Skipping $NEW_ROOT/$f"
:
fi
done
- /sbin/pivot_root $NEW_ROOT $NEW_ROOT/orig
-}
-
-do_remove_old() {
- shopt -s dotglob
- rm -rf $MNT_USER/*.old
- shopt -u dotglob
+ /sbin/pivot_root "$NEW_ROOT" "$NEW_ROOT"/orig
}
-# select files for deletion
-do_clear_old() {
- # when "clear user data" is requested - mark all non-hidden files for deletion
+do_erase_all_except_persistent() {
+ # Delete all files and folders except for the "${MNT_USER}/.persistent" directory.
loginfo "Clearing user data. Persistent data will be left "
-
- for FILE_PATH in "$MNT_USER"/*; do
- FILE_NAME=$(basename "$FILE_PATH")
- # rename all files and folders that exist in /mnt/user
- mv "$FILE_PATH" "$MNT_USER/$FILE_NAME.old" 2>&1 | logpipe
- done
- do_remove_old
- rm -f $DO_CLEAR_PERSISTENT
+ #UPPERDIR has to be cleared except 'orig' folder
+ #erasing folders in ${UPPERDIR}
+ find ${UPPERDIR} -maxdepth 1 -type d | grep "${UPPERDIR}/" | grep -v orig | xargs rm -rf
+ #erasing rest (files, if they are there) in ${UPPERDIR}
+ rm ${UPPERDIR}/* >/dev/null 2>&1
}
# Most efficient way to clear UBIFS file system
-do_erase_old() {
+do_erase_persistent() {
loginfo "Erasing user data"
# Sys must be mounted to use ubifs utilities
mount -t sysfs sysfs /sys
@@ -98,12 +88,13 @@ do_rw_mount() {
mount -t tmpfs inittemp /mnt
mnt_user # user_data is now accessible
- do_remove_old
-
- if [[ -f $DO_ERASE_PERSISTENT ]] ; then
- do_erase_old
- elif [[ -f $DO_CLEAR_PERSISTENT ]] ; then
- do_clear_old
+ if [[ "$DO_ERASE_PERSISTENT" -eq 1 ]] ; then
+ do_erase_persistent
+ u-boot setenv default_reset_f
+ u-boot setenv erase_persistent_f 0
+ elif [[ "$DO_ERASE_ALL_EXCEPT_PERSISTENT" -eq 1 ]] ; then
+ do_erase_all_except_persistent
+ u-boot setenv default_reset_f
fi
mkdir -p $UPPERDIR $WORKDIR $OVERLAY $USER_ORIG ${MNT_USER}/.persistent
@@ -112,11 +103,9 @@ do_rw_mount() {
loginfo "/proc/mounts:"
cat /proc/mounts | grep overlay | logpipe
- mkdir -p ${OVERLAY}/var/persistent
-
- mount --bind ${MNT_USER}/.persistent ${OVERLAY}/var/persistent
loginfo "Switch root to $OVERLAY"
my_switch_root $OVERLAY
+ mount --bind /orig/mnt/user/.persistent/ /var/persistent
cat /proc/mounts | grep overlay | logpipe
mount -o remount,rw /
cat /proc/mounts | grep overlay | logpipe
@@ -126,7 +115,7 @@ do_rw_mount() {
cgroupmnts=$(sed -r -e 's/[^[:space:]]*[[:space:]]//' -e 's/[[:space:]]+.*//g' /proc/mounts | grep '^/orig')
for mp in ${cgroupmnts} ; do
if [[ $mp != /orig ]] && [[ -d $mp ]] ; then
- umount -l $mp >/dev/null 2>&1
+ umount -l "$mp" >/dev/null 2>&1
fi
done
}