Skip to content
This repository has been archived by the owner. It is now read-only.

New installation/flashing method: CWM/TWRP flashable zips #109

Closed
ata2001 opened this Issue Jun 24, 2017 · 16 comments

Comments

Projects
None yet
6 participants
@ata2001
Copy link
Member

commented Jun 24, 2017

I'm working on implementing support for creating android recovery-flashable zips in pmbootstrap.

Why?

There are several reasons, why this would be useful, these are the ones, I find the most important.

  • It would allow end users to install postmarketOS on their devices without an external GNU/linux (or any) computer.
  • fastboot/heimdall(odin) access is often problematic with android devices, even after unlocking the bootloader.

How?

There's a file in android update zips called update-binary, what gets executed by the recovery with superuser permissions. I've realized, we can put a simple shell script in the place of that binary, so there's no need to compile that from the android sources.

The zip will contain the whole rootfs unencrypted, and the dynamic binaries necessary for encryption/installation.
The script will extract the needed binaries to /tmp/, encrypt (in case full disc encryption is enabled) and format the partition, mount it and copy the system files over.

When we'll have a touch-friendly framebuffer input method (see #59), that is going to be used to input the password.

There are two commands/options/arguments I plan to add to pmbootstrap:

  • pmbootstrap install --android-recovery-zip Generate a zip file for flashing with CWM compatible recoveries.
  • pmbootstrap flasher sideload Flash the zip using adb's sideload feature.

Current progress

I've made some progress with the installer script, it is now able to install the rootfs to the system partition, and handle full disk encryption.

You can find the scripts here.

The most important files:

https://github.com/ata2001/android-recovery-zip/blob/master/bin/pmos_install

https://github.com/ata2001/android-recovery-zip/blob/master/bin/pmos_install_functions

https://github.com/ata2001/android-recovery-zip/blob/master/bin/pmos_setpw

Instructions for creating a flashable zip for your device:

https://github.com/ata2001/android-recovery-zip/blob/master/README.md

Issues/Hacks

  • The recovery looks for the executable named META-INF/com/google/android/update-binary. Replacing that binary with a shell script works fine, as mentioned above. However I think the name update-binary is a bit confusing. So I moved the main install script to a different path, and put a simple script, that extracts and calls pmos_install in its place.

  • Since zip doesn't support every attribute needed for the rootfs, we need to include a tar.gz archive inside the zip. (TWRP has no support for tar.gz archives, see TeamWin/Team-Win-Recovery-Project#473) This may cause problems on devices with less memory.

  • Setting LD_LIBRARY_PATH has no effect, cryptsetup won't run unless the .so files are in /lib/. A workaround is to create symlinks. https://github.com/ata2001/android-recovery-zip/blob/master/bin/pmos_install#L17-L21

@ollieparanoid about the issue on Matrix:

there are other methods. you could patch the binaries with lddpatcher or how it is called looking it up and you could instead of directly calling the binaries execute the interpreting so file also looking it up with another library path as argument. I've done such hacks as I've tried to package cross-compilers from other distros in a very early stage, before I could get the Alpine cross-compilers working properly

"patchelf" is the program that allows you to edit the binaries to use another so path. but I think it won't work on arm (so it's useless for your case!). it is packaged for alpine, here's the homepage: https://nixos.org/patchelf.html
/lib/ld-musl-x86_64.so.1 is the program, that executes all dynamic executables. you can pass paths there. but you would need a wrapper for all binaries, that you need to call, so this also isn't a nice solution

He also suggested using a chroot.

  • pmos_setpw needs input from an interactive shell. That might not be possible in some recoveries. TWRP users can use the built-in terminal or adb shell.

Todo

  • Flash boot partition too
  • Install without full disk encryption
  • SD card install
  • Custom cipher
  • Integrate into pmbootstrap
  • Isorec flashing
  • Verify device codename
@ollieparanoid

This comment has been minimized.

Copy link
Member

commented Jun 24, 2017

Sounds good! A few recommendations:

  • Make sure, that you compile all binaries, that you ship yourself, statically.
  • (You could use Alpine's busybox-static package, if you need it)
  • I recommend setting the password from withing the recovery. You could set it via telnet for now (like in the initfs), and when we have a framebuffer on screen keyboard (#59), we could use that instead (in the future)

What exactly would the new commands do? install --recovery could be a bit misleading I think, because that could sound like it would overwrite the recovery partition (but it generates the zip file instead?)

@ata2001

This comment has been minimized.

Copy link
Member Author

commented Jun 24, 2017

@ollieparanoid Added explanations, would --recovery-zip be better?

Edit: sorry, dash instead of underscore

@MartijnBraam

This comment has been minimized.

Copy link
Member

commented Jun 24, 2017

I think --android-update-zip

@ollieparanoid

This comment has been minimized.

Copy link
Member

commented Jun 24, 2017

Ah, adb sideload could do that? Nice! I'd also call it --android-(something)-zip, maybe --android-zip, because it is Android specific and pmOS doesn't only run on Android.

@ata2001

This comment has been minimized.

Copy link
Member Author

commented Jun 24, 2017

@MartijnBraam Thanks for the recommendation, but I believe we don't use the filename update.zip anymore in modern recoveries, and it has nothing to do with updating android.

What about --android-recovery-zip?

@PabloCastellano

This comment has been minimized.

Copy link
Member

commented Jul 2, 2017

I've started working on it and made some progress:

http://imgur.com/a/c2uUO

Looks like it works but cannot really test it because of #126

@ollieparanoid

This comment has been minimized.

Copy link
Member

commented Jul 4, 2017

We have a pmbootstrap flasher export command now.
I suggest adding the zip export like this:

  • Command line: pmbootstrap flasher export --android-recovery-zip
  • This builds the zip file in the native chroot (only, because --android-recovery-zip is specified), and exports it as symlink to the target folder (just like the other files get exported in "flasher export")

Relevant file: export.py

@drebrez

This comment has been minimized.

Copy link
Member

commented Jul 5, 2017

I'm considering to have a command like pmbootstrap flasher export --odin-zip which creates an Odin flashable file for samsung devices.
I need to figure out if it's possible to flash system partitions but for the kernel/initramfs partitions it works well.
The only drawback of using Odin is that it will increment the flash counter and void the warranty. Not sure if we have to consider that.

@ata2001

This comment has been minimized.

Copy link
Member Author

commented Jul 16, 2017

Made an update to the original post.

@ollieparanoid

This comment has been minimized.

Copy link
Member

commented Jul 17, 2017

Great progress and documentation! 👍

@drebrez

This comment has been minimized.

Copy link
Member

commented Jul 17, 2017

@ata2001 I'm going to test it very soon, good job.

You considered also writing the kernel/initramfs partitions?

@ata2001

This comment has been minimized.

Copy link
Member Author

commented Jul 18, 2017

@drebrez Thank you!

Yes, if it's feasible on a device, then we could do that from the recovery too.

Be careful when you test it! Read the scripts beforehand! I've only tried it on amami.

@tssk

This comment has been minimized.

Copy link
Contributor

commented Sep 7, 2017

@ata2001 Hello, I tried this to create ZIP for i9100 but it failed for me:

(026297) [00:25:15] (buildroot_armhf) create recovery zip
(026297) [00:25:15] (buildroot_armhf) % cd /var/lib/postmarketos-android-recovery-installer/ && mv /tmp/install_options install_options
(026297) [00:25:15] (buildroot_armhf) % cd /var/lib/postmarketos-android-recovery-installer/ && cp /mnt/rootfs_samsung-i9100/boot/boot.img-samsung-i9100 boot.img
cp: can't stat '/mnt/rootfs_samsung-i9100/boot/boot.img-samsung-i9100': No such file or directory
(026297) [00:25:15] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(026297) [00:25:15] NOTE: The failed command's output is above the ^^^ line in the logfile: /home/safarik/.local/var/pmbootstrap/log.txt
(026297) [00:25:15] ERROR: Command failed: (buildroot_armhf) % cd /var/lib/postmarketos-android-recovery-installer/ && cp /mnt/rootfs_samsung-i9100/boot/boot.img-samsung-i9100 boot.img

Is there something that I can do to make it work?

I am interested in it because I thought I might flash FACTORYFS (SYSTEM) with this ZIP from TWRP as flashing with heimdall does not work for me...

Thanks

@drebrez

This comment has been minimized.

Copy link
Member

commented Sep 13, 2017

@ata2001 any plan for supporting the isorec devices?
I have a device with isorec style, I can help you with the testing, or if you want I can try to adapt the scripts myself to support it.

@ata2001

This comment has been minimized.

Copy link
Member Author

commented Sep 15, 2017

@drebrez I will do it, but testing it on real samsung devices would be a really big help.

@drebrez

This comment has been minimized.

Copy link
Member

commented Sep 15, 2017

@ata2001 ok, ping me in chat if you need some info about this "isorec" style and let me know when you have something I can test 👍

@ata2001 ata2001 closed this Nov 20, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.