FORUMS

[Q] Is there an easy way to apply the patch files from the OTA on a PC?

1,983 posts
Thanks Meter: 879
 
By gee one, Senior Member on 3rd October 2011, 03:43 AM
Post Reply Email Thread
I'm looking for a way to apply the patch files to the TF system image on a PC. This is not about how to get the ota to flash- I got that covered. This is about repacking roms or making flashable updates that don't rely on stock firmware.

I found a few ways, but none of them seem "easy."

The dirty way- apply the OTA and grab the system image.

From the PC command line - Linux has diff/patch, but that doesn't work for some of the patches in "IMGDIFF2" format. Besides, I'm not sure I ever got the regular BSDIFF40 patches to work.

The git option- There is the apply_patch source code in github. This works great, but I have to run it on the TF. Is it possible to compile this to work on my ubuntu box?

Maybe there is some magic script out there called apply_ota?

Thanks in advance
3rd October 2011, 05:17 AM |#2  
Senior Member
Thanks Meter: 743
 
More
Quote:
Originally Posted by gee one

I'm looking for a way to apply the patch files to the TF system image on a PC. This is not about how to get the ota to flash- I got that covered. This is about repacking roms or making flashable updates that don't rely on stock firmware.

I found a few ways, but none of them seem "easy."

The dirty way- apply the OTA and grab the system image.

From the PC command line - Linux has diff/patch, but that doesn't work for some of the patches in "IMGDIFF2" format. Besides, I'm not sure I ever got the regular BSDIFF40 patches to work.

The git option- There is the apply_patch source code in github. This works great, but I have to run it on the TF. Is it possible to compile this to work on my ubuntu box?

Maybe there is some magic script out there called apply_ota?

Thanks in advance :)


I recently wrote some code for a ARM basestation (basically like a Freescale cell-phone board), and had to be able to supply some updates over time. Before the project ended, I'd also found bsdiff and bspatch and tested them on linux, where they worked fine (as long as you'd created either an ARM bsdiff/patch version or somehow took the big/little endianness of the hardware into account).

At first I thought it wasn't working but it seemed to do OK on standard cross-compiled-for-ARM files. (well, they still ran and performed the same stunt..).

The thing that worried me about this method is that they'd never have the same md5sum before as after, likely because they had a different amount of bytes. (e.g. you make your own before and after and build each, then create the patch file using bsdiff, then patch the old file using the patch file, and create a 'newtestfile', but look at the number of bytes (or md5sum it) difference between the original stage 2 file and the stage 1 + the patch file via bspatch).

Sorry that is pretty confusing the way I just tried to explain it.. I'll look this over again tomorrow and figure out if I said anything worthwhile ;)
3rd October 2011, 06:49 AM |#3  
gee one's Avatar
OP Senior Member
Flag linux command line
Thanks Meter: 879
 
More
For inputs, the applypatch binary takes the file names, sha1 checksums of the before and after, and the final target size. Chance are high that the patch would only work if everything went in and came out properly.

Code:
apply_patch("/system/framework/framework-res.apk", "-",
            99b382b5886e505508fa3f730d778a1bed4bc04e, 9761707,
            a4798fb8d61d08b6f067e522e67107f6dd556148, package_extract_file("patch/system/framework/framework-res.apk.p"));
I think that bsdiff/patch will generally work on most of the OTA (BSDIFF40 files), but some of the files are IMGDIFF2, which targets binary/data files.

The applypatch binary works on both and as far as I can tell, is the same binary that the TF uses. Here is a snippet from the AOSP recovery... TF binary included Use the binary on your TF, not applypatch.sh! I suppose you can put it in system/xbin/

It would resolve the issue if I could compile this to run on my desktop from ubuntu. Short of that, I'm working on a script for the TF to parse the updater script.
Attached Files
File Type: tar applypatch.tar - [Click for QR Code] (2.85 MB, 506 views)
The Following User Says Thank You to gee one For This Useful Post: [ View ] Gift gee one Ad-Free
3rd October 2011, 02:39 PM |#4  
Senior Member
Thanks Meter: 743
 
More
Quote:
Originally Posted by gee one

For inputs, the applypatch binary takes the file names, sha1 checksums of the before and after, and the final target size. Chance are high that the patch would only work if everything went in and came out properly.

Code:
apply_patch("/system/framework/framework-res.apk", "-",
            99b382b5886e505508fa3f730d778a1bed4bc04e, 9761707,
            a4798fb8d61d08b6f067e522e67107f6dd556148, package_extract_file("patch/system/framework/framework-res.apk.p"));
I think that bsdiff/patch will generally work on most of the OTA (BSDIFF40 files), but some of the files are IMGDIFF2, which targets binary/data files.

The applypatch binary works on both and as far as I can tell, is the same binary that the TF uses. Here is a snippet from the AOSP recovery... TF binary included :) Use the binary on your TF, not applypatch.sh! I suppose you can put it in system/xbin/

It would resolve the issue if I could compile this to run on my desktop from ubuntu. Short of that, I'm working on a script for the TF to parse the updater script.

I'm not sure I understand the intent. I've just awoken and that's probably part of the problem..

'applypatch' is part of the standard (say 10.04 ubuntu) repo and is in a package called makepatch. Did you want to be able to run it "from" a standard x86 Ubuntu dist but have it targeting "armle" files or just be able to run it both on Ubuntu & Android correctly?

The files I tested were a) both binaries in different stages of evolution, and b) both built for armle(droids) and x86_64 and didn't behave differently, worked, and the checksum could be pre-calculated.

I'm going to mess around with applypatch when I'm out of my morning coma and get back to this in a bit.

Hah -- I do wonder if there's already a script (maybe it's a binary though) that lives in the dm* app on the tf101 that just does this already. You may have been right about that. Something has to apply those OTA patches. There's a few mechanisms for detecting them but I hadn't thought about how they're applied.

I'm trying to think if there's any scenario where the market applies 'patches' rather than always downloads the next version in entirety. Not sure about that.

Anyway, I'll see if I can get anywhere with applypatch.

Edit:: After a little messing around :

I finally see what you are trying to do and why what I'm doing is totally useless for that. I'm going to spend a little time looking over the imgdiff2 (apk) deal, and probably end up now figuring out a thing. ;)
3rd October 2011, 06:27 PM |#5  
gee one's Avatar
OP Senior Member
Flag linux command line
Thanks Meter: 879
 
More
I'll look into the makepatch package later today. Maybe that might be what I'm looking for.

Just to be clear, the intent is to be able to patch a "stock" system without it actually running on the TF. For example, to take the stock 8.6.5.9 image, decompress system/ to the PC, apply the patches from the OTA, and then end up with a stock 8.6.5.13 image. This would all happen on the PC, not the TF. It would streamline the ROM cooking process and make it easier and faster to spit out a complete, flashable update that won't fail sha1 checks because of mods.



sent from my cyanogen(mod) vision
22nd September 2012, 12:41 AM |#6  
gee one's Avatar
OP Senior Member
Flag linux command line
Thanks Meter: 879
 
More
Zombie Thread Alert!!!

You have been warned....

OK, so my C-fu isn't strong enough to figure out how to cross compile the apply patch binary to run on a x86 computer. However, I did notice that the applypatch binary gets built in the aosp/generic_x86 build, specifically in the system/bin folder.

This will be an exectuble file that will run on a x86 linux based system and do the same thing that the applypatch binary does to the ota package during the ota update. In other words, you can apply the ota patch to a system image from the comfort of the linux command line without having to actually flash the ota. This will allow you to be the first one on your block to have the new system image without having to mess up whatever rom you are currently running.

Of course, this might all be moot if we don't see another ota for our tf. Come on ASUS, just one more so I can test this out on a live update.

OK, so if you read this far, repo sync your aosp source and build the generic_x86 branch. The binary is aosp/target/product/generic_x86/system/bin/applypatch_static

edit: then after you've done that, use a script to parse the updater-script to extract the patching commands and then she-bang! I'll post mine a little later- I've got to get some flowers for tonight
8th October 2012, 11:38 PM |#7  
bgcngm's Avatar
Recognized Developer
Flag Lisbon
Thanks Meter: 20,455
 
Donate to Me
More
Any luck with that? I'm also searching for a way to apply an OTA update to a ROM using Ubuntu.
9th October 2012, 12:00 AM |#8  
gee one's Avatar
OP Senior Member
Flag linux command line
Thanks Meter: 879
 
More
Quote:
Originally Posted by bgcngm

Any luck with that? I'm also searching for a way to apply an OTA update to a ROM using Ubuntu.

Yeah, it works like a charm. The binary is compiled in the aosp/generic_x86 build. There is no need to flash, you can just pull it out of the system/bin folder after compiling the source. You can probably use an "mmm" command to make just files you want, but I'm not sure which package it's in. Then, I use a script that converts the OTA patch commands in the updater-script to a script file that runs on my linuxbox that calls the binary and patches the ROM under linux/ubuntu.
9th October 2012, 12:09 AM |#9  
bgcngm's Avatar
Recognized Developer
Flag Lisbon
Thanks Meter: 20,455
 
Donate to Me
More
Do you mind sharing your applypatch binary? I don't have AOSP source on my Ubuntu installation right now, so if you don't mind sharing I wouldn't need to build it from sources...
9th October 2012, 01:10 AM |#10  
gee one's Avatar
OP Senior Member
Flag linux command line
Thanks Meter: 879
 
More
Quote:
Originally Posted by bgcngm

Do you mind sharing your applypatch binary? I don't have AOSP source on my Ubuntu installation right now, so if you don't mind sharing I wouldn't need to build it from sources...

I attached the applypatch binary- it should work on most x86 linux distros, maybe.

As I stated in my earlier post, the binary is built with the x86 build. I'm not so good with the build system, but I think the code is from the bootable/recovery/applypatch. I included the relevant notices for that code.

In the OTA updater-script, there will be a bunch of applypatch commands- you might have to change the name/permissions of the binary, but that syntax should be what you are looking for.

Enjoy!
Attached Files
File Type: gz applypatch.tar.gz - [Click for QR Code] (1.80 MB, 491 views)
The Following 4 Users Say Thank You to gee one For This Useful Post: [ View ] Gift gee one Ad-Free
9th October 2012, 08:07 AM |#11  
bgcngm's Avatar
Recognized Developer
Flag Lisbon
Thanks Meter: 20,455
 
Donate to Me
More
Thank you very much for your time. It seems we are almost the only one trying this. The thing is that I really need to get this done because OTA update is failing for me by running it the usual way.

I've tried your binary and it works under my Ubuntu installation, however I was trying to manually patch just one file and got this:

Code:
[email protected]:~/Desktop/system/app$ applypatch_static ./ApplicationsProvider.apk - d9023cd58fd055e1ca3c8f8492b2c36aba923c6a 6184 69bea5d5a62980c611b903de8243d980f30e5fb5:../../patch/system/app/ApplicationsProvider.apk.p 

applying patch to ./ApplicationsProvider.apk
target 6184 bytes; free space 1080520704 bytes; retry 1; enough 1
chown of "./ApplicationsProvider.apk.patch" failed: Operation not permitted
I got that chown error message although ApplicationsProvider.apk.patch was created. Is this the patched file?

EDIT: Nevermind, I forgot to run the command as superuser.

EDIT2: Would it be too much if I ask you also to share the script that converts OTA commands from updater-script into the correct syntax to run on Ubuntu?
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes