Skip to content

Commit

Permalink
Change init-script and updater-script to work with SafeStrap on Motor…
Browse files Browse the repository at this point in the history
…ola Droid 4

Change-Id: I21ee96319995ea9597ba4ee2f5366d68ca2faf00
  • Loading branch information
NotKit committed Mar 15, 2017
1 parent 0a6adf8 commit 7dee946
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ endif
HYBRIS_BOOT_PART := $(shell /usr/bin/perl -w -e '$$fs=shift; if ($$ARGV[0]) { while (<>) { next unless /^$$fs\s|\s$$fs\s/;for (split) {next unless m(^/dev); print "$$_\n"; }}} else { print "ERROR: *fstab* not found\n";}' /boot $(HYBRIS_FSTABS) | sort -u)
HYBRIS_DATA_PART := $(shell /usr/bin/perl -w -e '$$fs=shift; if ($$ARGV[0]) { while (<>) { next unless /^$$fs\s|\s$$fs\s/;for (split) {next unless m(^/dev); print "$$_\n"; }}} else { print "ERROR: *fstab* not found\n";}' /data $(HYBRIS_FSTABS) | sort -u)

HYBRIS_BOOT_PART := /dev/null

$(warning ********************* /boot appears to live on $(HYBRIS_BOOT_PART))
$(warning ********************* /data appears to live on $(HYBRIS_DATA_PART))

Expand Down
64 changes: 57 additions & 7 deletions init-script
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ echo "Running Mer Boat Loader"

BOOTLOGO=%BOOTLOGO%
ALWAYSDEBUG=%ALWAYSDEBUG%
DATA_PARTITION=%DATA_PART%
DATA_PARTITION=/dev/mmcblk1p24
DEFAULT_OS=%DEFAULT_OS%

SAFESTRAP_PARTITION=/dev/mmcblk1p25
REAL_DATA_PARTITION=/dev/mmcblk1p24
SYSTEM_PARTITION=/dev/mmcblk1p20
PREINSTAL_PARTITION=/dev/mmcblk1p22
WEBTOP_PARTITION=/dev/mmcblk1p23

set_welcome_msg(){
cat <<EOF > /etc/issue.net
Welcome to the Mer/SailfishOS Boat loader debug init system.
Expand Down Expand Up @@ -137,20 +143,64 @@ bootsplash() {


mount_stowaways() {
echo "########################## mounting safestrap"
# mount safestrap partition
mkdir /ss
mount -t vfat -o uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020 $SAFESTRAP_PARTITION /ss

SLOT_LOC=$(cat /ss/safestrap/active_slot)

if [ "$SLOT_LOC" = "stock" ]; then
# umount /ss
elif [ "$SLOT_LOC" = "safe" ]; then
mv /dev/block/system /dev/block/systemorig
mv /dev/block/userdata /dev/block/userdataorig

SYSTEM_PARTITION=$PREINSTAL_PARTITION
DATA_PARTITION=$WEBTOP_PARTITION

# umount /ss
else
# setup loopbacks
DATA_PARTITION=$(losetup -f)
losetup $DATA_PARTITION /ss/safestrap/$SLOT_LOC/userdata.img

SYSTEM_PARTITION=$(losetup -f)
losetup $SYSTEM_PARTITION /ss/safestrap/$SLOT_LOC/system.img
fi
echo "########################## mounting stowaways"
if [ ! -z $DATA_PARTITION ]; then
data_subdir="$(get_opt data_subdir)"

mkdir /data
mkdir /target
mkdir /data
mkdir /target

mount $DATA_PARTITION /data

if [ ! -d "/data/${data_subdir}/.stowaways/${DEFAULT_OS}" ]; then
# Try mounting real data partition as fallback
umount /data
mount $REAL_DATA_PARTITION /data

if [ ! -d "/data/${data_subdir}/.stowaways/${DEFAULT_OS}" ]; then
echo "Failed to find /data/${data_subdir}/.stowaways/${DEFAULT_OS}" >> /diagnosis.log
fi
fi

mount $DATA_PARTITION /data
mount --bind /data/${data_subdir}/.stowaways/${DEFAULT_OS} /target
mkdir /target/data # in new fs
mount --bind /data/${data_subdir} /target/data
mount --bind /data/${data_subdir}/.stowaways/${DEFAULT_OS} /target
mkdir /target/data # in new fs
mount --bind /data/${data_subdir} /target/data
mkdir /target/ss
mount --bind /ss /target/ss
else
echo "Failed to mount /target, device node '$DATA_PARTITION' not found!" >> /diagnosis.log
fi

if [ ! -z $SYSTEM_PARTITION ]; then
mkdir /target/system
mount $SYSTEM_PARTITION -o ro /target/system
fi

mount
}

Expand Down
14 changes: 9 additions & 5 deletions updater-script
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ ui_print(" Version: %VERSION%");
ui_print(" Image: %IMAGE_FILE%");
ui_print(" Size: %IMAGE_SIZE%");
ui_print(" Partitions:");
ui_print(" /boot -> %BOOT_PART%");
ui_print(" /data -> %DATA_PART%");
ui_print(" /data -> /dev/block/userdata");
ui_print("========================================");
ui_print("");

%ASSERT_DEVICE%

ui_print("Device check succeeded, mounting filesystems ...");
mount("ext4", "EMMC", "%DATA_PART%", "/data");
mount("ext4", "EMMC", "/dev/block/userdata", "/data");
mount("ext3", "EMMC", "/dev/block/system", "/system");

ui_print("Copying filesystem archive ...");
package_extract_file("%IMAGE_FILE%", "/data/sailfishos-rootfs.tar.bz2");
Expand All @@ -26,11 +26,15 @@ ui_print("Running installation script ...");
%SET_PERMISSIONS%
run_program("/tmp/updater-unpack.sh") == "0" || abort("Failed to extract filesystem!");

ui_print("Flashing hybris-boot.img ...");
package_extract_file("hybris-boot.img", "%BOOT_PART%");
ui_print("Replacing /system/etc/kexec/kernel...");
package_extract_file("kernel", "/system/etc/kexec/kernel");

ui_print("Replacing /system/etc/kexec/ramdisk.img...");
package_extract_file("ramdisk.img", "/system/etc/kexec/ramdisk.img");

ui_print("Unmounting filesystems ...");
unmount("/data");
unmount("/system");

ui_print("Done!");

0 comments on commit 7dee946

Please sign in to comment.