Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed recovery. Fixes MER#1987 #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions droid-hal-device-img-boot.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand Down Expand Up @@ -101,6 +103,7 @@ Requires: oneshot
%description
%{summary}

%if 0%{!?embed_recovery:1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, this %if never evaluates to true, because embed_recovery is now always defined (either to 1, or to 0). This also applies to all similar statements against embed_recovery below

%package -n droid-hal-%{device}-img-recovery

Summary: Recovery boot image for Sailfish OS devices
Expand All @@ -111,6 +114,7 @@ Requires: droid-config-flashing

%description -n droid-hal-%{device}-img-recovery
%{summary}
%endif

%prep
%setup -q -n %{name}-%{version}
Expand Down Expand Up @@ -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}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
20 changes: 17 additions & 3 deletions jolla-init
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
35 changes: 22 additions & 13 deletions mksfosinitrd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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

Expand Down