From 67d0be88b1b2853b45e5371a72c2aaac5de2be18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Tue, 13 Nov 2018 20:52:39 +0100 Subject: [PATCH 1/4] [recovery] supported embedding the recovery inside regular initramfs In case the recovery needs to embeded inside the regular initramfs. --- droid-hal-device-img-boot.inc | 7 ++++++- jolla-init | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/droid-hal-device-img-boot.inc b/droid-hal-device-img-boot.inc index eb87368..0644d21 100644 --- a/droid-hal-device-img-boot.inc +++ b/droid-hal-device-img-boot.inc @@ -17,6 +17,8 @@ # battery_capacity_file: Path to read current battery charge from. # battery_capacity_threshold: Battery threshold for factory reset [0, 100]. # Default 0 (no threshold). +# embed_recovery: in case the recovery needs to embedded inside +# the regular initramfs # # Adding device specific files to initrd folder: # @@ -172,11 +174,14 @@ sed --in-place 's|@DISPLAY_BRIGHTNESS@|%{display_brightness}|' %{_local_initrd_d sed --in-place 's|@BATTERY_CAPACITY_FILE@|%{battery_capacity_file}|' %{_local_initrd_dir}/etc/sysconfig/recovery sed --in-place 's|@BATTERY_CAPACITY_THRESHOLD@|%{battery_capacity_threshold}|' %{_local_initrd_dir}/etc/sysconfig/recovery +sed -e 's/@embed_recovery@/%{?embed_recovery:1}%{!?embed_recovery:0}/g' initrd/jolla-init \ + %{_local_initrd_dir}/jolla-init + # Create a hybris-boot.img image from the zImage pushd %{_local_initrd_dir} ./mksfosinitrd.sh popd -%{mkbootimg_cmd} hybris-boot.img +%{mkbootimg_cmd} hybris-boot.img %{embed_recovery} pushd %{_local_initrd_dir} ./mksfosinitrd.sh recovery diff --git a/jolla-init b/jolla-init index 220b751..00b8a65 100755 --- a/jolla-init +++ b/jolla-init @@ -23,6 +23,10 @@ # IRC: Sage @ #mer & #nemomobile @ Freenode +# disable unneded shellcheck variables: +# shellcheck disable=SC2050 +# reason: warning isn't relevant as constants get replaced later + # Location of the device init script, if not set, few defaults are tried. INITBIN=/sbin/preinit @@ -34,15 +38,25 @@ ROOTMNTDIR="/rootfs" # for where to mount the root. MNTSCRIPT="/sbin/root-mount" +mkdir -p /proc +mount -t proc proc /proc + fail() { echo "initrd: Failed" > /dev/kmsg echo "initrd: $1" > /dev/kmsg - reboot2 recovery + if [ @embed_recovery@ = 1 ] ; then + exec ./recovery-init + else + reboot2 recovery + fi } -mkdir -p /proc -mount -t proc proc /proc +if [ @embed_recovery@ = 1 ] ; then + if ! grep -q skip_initramfs /proc/cmdline ; then + exec ./recovery-init + fi +fi mkdir -p /sys mount -t sysfs sys /sys From 217de25e355953954af00c6c926a9bf7a37a1b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Sun, 18 Nov 2018 17:39:31 +0100 Subject: [PATCH 2/4] [rpm] Disable recovery img when embed recovery is defined. MER#1987 --- droid-hal-device-img-boot.inc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/droid-hal-device-img-boot.inc b/droid-hal-device-img-boot.inc index 0644d21..45ab586 100644 --- a/droid-hal-device-img-boot.inc +++ b/droid-hal-device-img-boot.inc @@ -103,6 +103,7 @@ Requires: oneshot %description %{summary} +%if 0%{!?embed_recovery:1} %package -n droid-hal-%{device}-img-recovery Summary: Recovery boot image for Sailfish OS devices @@ -113,6 +114,7 @@ Requires: droid-config-flashing %description -n droid-hal-%{device}-img-recovery %{summary} +%endif %prep %setup -q -n %{name}-%{version} @@ -179,14 +181,15 @@ sed -e 's/@embed_recovery@/%{?embed_recovery:1}%{!?embed_recovery:0}/g' initrd/j # Create a hybris-boot.img image from the zImage pushd %{_local_initrd_dir} -./mksfosinitrd.sh +./mksfosinitrd.sh %{embed_recovery} popd -%{mkbootimg_cmd} hybris-boot.img %{embed_recovery} - +%{mkbootimg_cmd} hybris-boot.img +%if 0%{!?embed_recovery:1} pushd %{_local_initrd_dir} ./mksfosinitrd.sh recovery popd %{mkbootimg_cmd} hybris-recovery.img +%endif rm -rf %{_local_build_dir} @@ -195,7 +198,9 @@ rm -rf %{buildroot} # /boot install -D -m 644 hybris-boot.img %{buildroot}/boot/hybris-boot.img +%if 0%{!?embed_recovery:1} install -D -m 644 hybris-recovery.img %{buildroot}/boot/hybris-recovery.img +%endif # /lib/modules mkdir -p %{buildroot}/lib/modules @@ -209,9 +214,11 @@ touch %{buildroot}/lib/modules/%{kernelver}/{modules.order,modules.builtin} %defattr(644,root,root,-) /lib/modules/%{kernelver} +%if 0%{!?embed_recovery:1} %files -n droid-hal-%{device}-img-recovery %defattr(-,root,root,-) /boot/hybris-recovery.img +%endif %post # When doing install that is done during the image creation thus we don't add @@ -222,7 +229,9 @@ fi /sbin/depmod %{kernelver} || : +%if 0%{!?embed_recovery:1} %post -n droid-hal-%{device}-img-recovery if [ $1 -ne 1 ] ; then add-preinit-oneshot /var/lib/platform-updates/flash-recoveryimg.sh fi +%endif From d688cdb13f34fcacae969b9576335359549ac3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Thu, 29 Nov 2018 23:37:48 +0100 Subject: [PATCH 3/4] [initrd] Use [ instead of test with workarounds --- mksfosinitrd.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mksfosinitrd.sh b/mksfosinitrd.sh index 6c0c830..37c4cf5 100755 --- a/mksfosinitrd.sh +++ b/mksfosinitrd.sh @@ -52,7 +52,7 @@ chmod 0600 $FIX_FILE_PERMISSIONS TOOL_LIST="$TOOL_LIST $(cat tools.files 2> /dev/null)" -if test x"$1" = x"recovery"; then +if [ "$1" = "recovery" ]; then TOOL_LIST="$TOOL_LIST $RECOVERY_FILES $(cat recovery.files 2> /dev/null)" DEF_INIT="recovery-init" else @@ -72,7 +72,7 @@ check_files() { local FILES=$1 for f in $FILES; do - if test ! -e "$f"; then + if [ ! -e "$f" ]; then echo "File \"$f\" does not exist!" echo "Please install required RPM package or add \"$f\" manually" return 1 @@ -94,7 +94,7 @@ mkdir -p etc cp -a "$OLD_DIR"/etc/sysconfig etc # Copy recovery files -if test x"$1" = x"recovery"; then +if [ "$1" = "recovery" ]; then cp -a "$OLD_DIR"/usr/ "$OLD_DIR"/etc/ -t ./ fi From bb8089b5eab2a87c4c1310fb8e74f3e11abbb0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Thu, 29 Nov 2018 23:54:04 +0100 Subject: [PATCH 4/4] [initrd] Support adding recovery tools to regular initrd. MER#1987 --- droid-hal-device-img-boot.inc | 2 +- mksfosinitrd.sh | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/droid-hal-device-img-boot.inc b/droid-hal-device-img-boot.inc index 45ab586..7d7e732 100644 --- a/droid-hal-device-img-boot.inc +++ b/droid-hal-device-img-boot.inc @@ -181,7 +181,7 @@ sed -e 's/@embed_recovery@/%{?embed_recovery:1}%{!?embed_recovery:0}/g' initrd/j # Create a hybris-boot.img image from the zImage pushd %{_local_initrd_dir} -./mksfosinitrd.sh %{embed_recovery} +./mksfosinitrd.sh %{?embed_recovery:combined} popd %{mkbootimg_cmd} hybris-boot.img %if 0%{!?embed_recovery:1} diff --git a/mksfosinitrd.sh b/mksfosinitrd.sh index 37c4cf5..7d17d03 100755 --- a/mksfosinitrd.sh +++ b/mksfosinitrd.sh @@ -52,21 +52,28 @@ chmod 0600 $FIX_FILE_PERMISSIONS TOOL_LIST="$TOOL_LIST $(cat tools.files 2> /dev/null)" +OLD_DIR=$(pwd) +TMP_DIR=/tmp/sfosinitrd + if [ "$1" = "recovery" ]; then - TOOL_LIST="$TOOL_LIST $RECOVERY_FILES $(cat recovery.files 2> /dev/null)" - DEF_INIT="recovery-init" + DEF_INIT="recovery-init" else - # The default init script - DEF_INIT="jolla-init" + # The default init script + DEF_INIT="jolla-init" +fi + +if [ "$1" = "combined" ] || [ "$1" = "recovery" ] ; then + TOOL_LIST="$TOOL_LIST $RECOVERY_FILES $(cat recovery.files 2> /dev/null)" fi -# Remove duplicates. -TOOL_LIST="$(echo $TOOL_LIST | sort | uniq)" set -e -OLD_DIR=$(pwd) -TMP_DIR=/tmp/sfosinitrd +rm -rf "$TMP_DIR" +mkdir "$TMP_DIR" + +# Remove duplicates. +TOOL_LIST="$(echo $TOOL_LIST | sort | uniq)" check_files() { @@ -83,8 +90,10 @@ check_files() check_files "$TOOL_LIST" || exit 1 -rm -rf "$TMP_DIR" -mkdir "$TMP_DIR" +if [ "$1" = "combined" ] ; then + cp "$OLD_DIR"/recovery-init "$TMP_DIR"/. +fi + cd "$TMP_DIR" # Copy local files to be added to initrd. If you add more, add also to TOOL_LIST. @@ -94,7 +103,7 @@ mkdir -p etc cp -a "$OLD_DIR"/etc/sysconfig etc # Copy recovery files -if [ "$1" = "recovery" ]; then +if [ "$1" = "recovery" ] || [ "$1" = "combined" ]; then cp -a "$OLD_DIR"/usr/ "$OLD_DIR"/etc/ -t ./ fi