diff --git a/droid-hal-device-img-boot.inc b/droid-hal-device-img-boot.inc index eb87368..7d7e732 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: # @@ -101,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 @@ -111,6 +114,7 @@ Requires: droid-config-flashing %description -n droid-hal-%{device}-img-recovery %{summary} +%endif %prep %setup -q -n %{name}-%{version} @@ -172,16 +176,20 @@ 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 +./mksfosinitrd.sh %{?embed_recovery:combined} popd %{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} @@ -190,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 @@ -204,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 @@ -217,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 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 diff --git a/mksfosinitrd.sh b/mksfosinitrd.sh index 6c0c830..7d17d03 100755 --- a/mksfosinitrd.sh +++ b/mksfosinitrd.sh @@ -52,27 +52,34 @@ chmod 0600 $FIX_FILE_PERMISSIONS TOOL_LIST="$TOOL_LIST $(cat tools.files 2> /dev/null)" -if test x"$1" = x"recovery"; then - TOOL_LIST="$TOOL_LIST $RECOVERY_FILES $(cat recovery.files 2> /dev/null)" - DEF_INIT="recovery-init" +OLD_DIR=$(pwd) +TMP_DIR=/tmp/sfosinitrd + +if [ "$1" = "recovery" ]; then + 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() { 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 @@ -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 test x"$1" = x"recovery"; then +if [ "$1" = "recovery" ] || [ "$1" = "combined" ]; then cp -a "$OLD_DIR"/usr/ "$OLD_DIR"/etc/ -t ./ fi