华为手表从出厂刷机包和OTA包中生成最终的boot.img

以华为Watch 2 2018为例,
出厂的刷机包 “HUAWEI WATCH 2 Modem_中国版升级_NWD1.170711.022_release.exe”, 这是一个fastboot刷机包

0. 编译 ApplyPatch

apt install libbz2-dev
git clone https://github.com/erfanoabdi/imgpatchtools
cd imgpatchtools
make

1. 从OTA升级包update.zip 获取相关文件和信息

META-INF/com/google/android/updater-script
...
ui_print("Source: huawei/sawshark_sw/sawshark:7.1.1/NWD1.170711.002/4172583:user/release-keys");
ui_print("Target: huawei/sawshark_sw/sawshark:7.1.1/N7I56C/4304100:user/release-keys");
...
apply_patch("EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8062181:ac228af93437500c11504bdaa7f0dcae261f8b90:8064229:3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96",
            "-", 3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96, 8064229,
            ac228af93437500c11504bdaa7f0dcae261f8b90,
            package_extract_file("patch/boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8062181:ac228af93437500c11504bdaa7f0dcae261f8b90:8064229:3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96");

可以看出原始的 boot.img的sha1为 ac228af93437500c11504bdaa7f0dcae261f8b90, 打好补丁后为 3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96

./ApplyPatch  boot.img  new.img  3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96  8064229  ac228af93437500c11504bdaa7f0dcae261f8b90 patch/boot.img.p

命令行选项

	file = source file from rom zip
	target = target file (use "-" to patch source file)
	tgt_sha1 = target SHA1 Sum after patching
	size = file size
	init_sha1 = file SHA1 sum
	patch = patch file (.p) from OTA zip

验证
sha1sum -b boot.img
ac228af93437500c11504bdaa7f0dcae261f8b90 *boot.img

sha1sum -b new.img
3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96 *new.img

以后的各版本

ui_print("Source: huawei/sawshark_sw/sawshark:7.1.1/N7I56C/4304100:user/release-keys");
ui_print("Target: huawei/sawshark_sw/sawshark:7.1.1/N7I92E/4403039:user/release-keys");
...
apply_patch("EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8064229:3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96:8064229:91a8457809ca7534d87b46ec44bf7991d3b53179",
            "-", 91a8457809ca7534d87b46ec44bf7991d3b53179, 8064229,
            3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96,
            package_extract_file("patch/boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8064229:3f29ba5b40328b1e3dc16515ff4a4e3bbe2ddb96:8064229:91a8457809ca7534d87b46ec44bf7991d3b53179");
-----
ui_print("Source: huawei/sawshark_sw/sawshark:7.1.1/N7I92E/4403039:user/release-keys");
ui_print("Target: huawei/sawshark_sw/sawshark:7.1.1/NWD1.171123.001/4467331:user/release-keys");
...
apply_patch("EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8064229:91a8457809ca7534d87b46ec44bf7991d3b53179:8064229:8d05322cc211052be5d0264f6e8671e0f5ea28e1",
            "-", 8d05322cc211052be5d0264f6e8671e0f5ea28e1, 8064229,
            91a8457809ca7534d87b46ec44bf7991d3b53179,
            package_extract_file("patch/boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8064229:91a8457809ca7534d87b46ec44bf7991d3b53179:8064229:8d05322cc211052be5d0264f6e8671e0f5ea28e1");
---------------------------------
ui_print("Source: huawei/sawshark_sw/sawshark:7.1.1/NWD1.171123.001/4467331:user/release-keys");
ui_print("Target: huawei/sawshark_sw/sawshark:8.0.0/OWDE.180122.014/4586409:user/release-keys");
...
apply_patch("EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8064229:8d05322cc211052be5d0264f6e8671e0f5ea28e1:8594662:07c12ecbf36151a617ff05677f4896405e421ebc",
            "-", 07c12ecbf36151a617ff05677f4896405e421ebc, 8594662,
            8d05322cc211052be5d0264f6e8671e0f5ea28e1,
            package_extract_file("patch/boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8064229:8d05322cc211052be5d0264f6e8671e0f5ea28e1:8594662:07c12ecbf36151a617ff05677f4896405e421ebc");
-------------------

ui_print("Source: huawei/sawshark_sw/sawshark:8.0.0/OWDE.180122.014/4586409:user/release-keys");
ui_print("Target: huawei/sawshark_sw/sawshark:8.0.0/OWDE.180215.020/4633085:user/release-keys");

....

apply_patch("EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8594662:07c12ecbf36151a617ff05677f4896405e421ebc:8594662:17625d3b58ca903ec0ad8cdf3c8fe872ad8e11d3",
            "-", 17625d3b58ca903ec0ad8cdf3c8fe872ad8e11d3, 8594662,
            07c12ecbf36151a617ff05677f4896405e421ebc,
            package_extract_file("patch/boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8594662:07c12ecbf36151a617ff05677f4896405e421ebc:8594662:17625d3b58ca903ec0ad8cdf3c8fe872ad8e11d3");
-----------------------------------
ui_print("Source: huawei/sawshark_sw/sawshark:8.0.0/OWDE.180215.020/4633085:user/release-keys");
ui_print("Target: huawei/sawshark_sw/sawshark:8.0.0/OWDE.180707.001.E1/4958530:user/release-keys");
....
apply_patch("EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8594662:17625d3b58ca903ec0ad8cdf3c8fe872ad8e11d3:8604902:4946f61ba431ec844dae06afe2e572f491a99a5a",
            "-", 4946f61ba431ec844dae06afe2e572f491a99a5a, 8604902,
            17625d3b58ca903ec0ad8cdf3c8fe872ad8e11d3,
            package_extract_file("patch/boot.img.p")) ||
    abort("E3008: Failed to apply patch to EMMC:/dev/block/platform/soc/7824900.sdhci/by-name/boot:8594662:17625d3b58ca903ec0ad8cdf3c8fe872ad8e11d3:8604902:4946f61ba431ec844dae06afe2e572f491a99a5a");


发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注