Here the steps to flash the system image using netcat:
1) pmbootstrap initfs hook_add debug-shell
2) pmbootstrap flasher flash_kernel
3) boot the device and it will show "missing boot partition"
4) telnet 172.16.42.1
5) nc -v -l -p 60000 > /dev/mmcblk0p12 <= change with the partition you prefer (fdisk -l to list)
6) in another terminal: pmbootstrap chroot
7) apk add pv
8) pv /home/pmos/rootfs/samsung-maguro.img | nc 172.16.42.1 60000
9) when transfer ends, ctrl+c in both terminals and reboot device
We can put it somewhere in the wiki or we can consider adding it as an alternative flasher method 馃槃
We can probably make a initramfs hook that justs starts the nc process on the phone. You also probably don't have to run flash_kernel, flasher boot should be enough.
@MartijnBraam the initfs hook that starts the nc process is a very good idea 馃憤
The only problem I see, is that right now we don't have any information about the partitions of the devices.
Is there a way to find the correct partition using the name (system)?
Hmm can't we just start NBD on the phone to export all the partitions on the phone to the host PC?
Nice! :D
@MartijnBraam: We could start the nc server in a hook. But then we can only directly start flashing the file, which is a bit inconvenient for proper integration into pmbootstrap's flasher abstraction. Also when we simply pass through the phone partitions (I think that is what NBD does?), we risk the host Linux mounting them which is not what we want during flashing. I would prefer to use the normal usb-shell hook and use it as outlined below.
@drebrez: If you're actually using this right now (for plasma mobile?) or we have another valid use case, implementing this in pmbootstrap makes a lot of sense to me.
Here is an idea for the implementation (Outdated, I've written a new version below!):
postmarketos-flasher-nc, that does the following:nc -v -l -p 60000 > $PARTITIONnc on the device againlist_devices, flash_system, flash_bootAs I see it, the best part is that this works with images of any size, and we do not need to care about simg etc. :+1:
with nbd they won't get mounted automatically, you can run a nbd client in the native chroot and use the block devices that creates to install it the same way the sdcard installer does.
@MartijnBraam cool, that would also be nice. then we wouldn't even need to generate an image file!
The process basically is: adding nbd-server to the initramfs and starting a server instance for every partition you want to export with:
$ nbd-server -C /dev/null 9000 /dev/mmcblk0p1 &
$ nbd-server -C /dev/null 9001 /dev/mmcblk0p2 &
Then on the hosts machine you create nbd devicenodes in the chroot for the amount of partitions you want to open and then start the nbd-clients
$ mknod /dev/nbd0 b 43 0
$ mknod /dev/nbd1 b 43 1
$ nbd-client 172.16.42.1 9000 /dev/nbd0 &
$ nbd-client 172.16.42.1 9001 /dev/nbd1 &
# Then do stuff on the phone's storage:
$ mkfs.ext4 /dev/nbd1
@MartijnBraam seems good, did you already tried if it works into the initramfs? I will try it next time I have to flash an image
I haven't tried anything yet on actual devices, this is just the stuff I researched about nbd (which I have used before but a long time ago)
@MartijnBraam I will test it on the actual device and if it works I will start working on integrating this functionality in pmbootstrap 馃憤
@MartijnBraam with nbd-server we will need to add additional libs into the initramfs, or we can use the first method (netcat) to add them just right before starting the install procedure
@ollieparanoid we don't have to depend on pv, since I didn't found a way to detect when the transfer is done, with pv I see a nice progress bar and I can safely close the connection when it reaches 100%.
Well, it doesn't seem like a big dependency. So if pv is packaged in Alpine and we get improved usability (progress bar!), then we don't need to re-invent the wheel in my opinion.
Reading through that thread again, I'd still prefer nc over nbd, since it has less dependencies and is easier to set up.
I think a streamlined nc flashing method would improve the flashing situation a lot. We wouldn't have to deal with strange/broken fastboot versions (ones that require sparse images or can't flash over a certain size #897) and especially it would work with Heimdall devices, where most of the time flashing anything other than the kernel + initramfs does not work at all.
My plan from above does not have a good way to start the flashing mode and I think having the user to manually install a hook just to enter that flashing mode isn't that good.
init_functions.sh: enter_pmos_flash_mode()PMOS_FLASH_MODE is not set, so we can execute it without building a new initramfs.postmarketOS flash mode is active\n https://postmarketos.org/flashmode) or something like thatflash_system and therefore get rid of all the quirks we havepmbootstrap flasher flash_system with python code:pv in the native chroot to get a nice progress barPMOS_FLASH_MODE parameter. (For heimdall-isorec devices, we must actually flash the kernel when changing the kernel parameter.)nc on the device, use pv to flash the system partition (and later also the extra partitions for LVM #60)If anyone wants to give it a try, I'll be happy to assist and otherwise I'll try to do it myself at some point in the future (after the 200 days of pmOS blog post though).
As always, feedback is welcome!
Please don't get rid of the normal fastboot system-flashing method. I am for adding an additional method but not for throwing out working code.
Maybe this came out wrong, I would only suggest to replace the method if we are sure, that we don't have any regressions. In general, I think it is good practice to throw out working code if we have something better, so we don't infinitely increase maintenance effort and have too many solutions to do the same task. But it should really cover all use-cases and not be a bad trade-off, that makes you feel like functionality was removed.
But for that specific case, we could look into how much work it would be to keep the current method (especially with the sparse images) around if there are people, that prefer to have both. Would that be acceptable for you?
Sounds good
@ollieparanoid what you think about starting triggerhappy in the initramfs and detect a pressed button?
triggerhappy is something like 50kb and we can detect the volume keys (almost every device have them) to start a "pmos flash/recovery" mode
@drebrez: Sounds good to me! :+1:
@z3ntu: btw: we have pmbootstrap flasher --method= for some time now, which should make it easy to have this new flash method side by side with the old one. After thinking about it again, I don't think we would save much by removing fastboot/heimdall/... support (and it wouldn't really be possible anyway, because we need that to boot/flash the initial kernel which is then able to boot pmOS flash mode).
If we don't put the code that runs on the PC in python, but create an aport with a shell script inside, then we can treat it like fastboot or any other flasher, thus reducing extra code paths.
Regarding the custom flasher protocol, @MayeulC noted in #postmarketOS that it would be a good idea to add some sort of checksum, to which @MartijnBraam replied:
you still need to make sure the connection wasn't aborted, so you'll need to send a checksum or the total image size first