getprop("ro.product.device") == "surya" || abort("E3004: This package is for \"surya\" devices; this is a \"" + getprop("ro.product.device") + "\".");
ui_print("Source: POCO/surya_tr/surya:11/RKQ1.200826.002/V12.5.6.0.RJGTRXM:user/release-keys");
ui_print("Target: POCO/surya_tr/surya:11/RKQ1.200826.002/V12.5.7.0.RJGTRXM:user/release-keys");
ui_print("Verifying current system...");
getprop("ro.build.fingerprint") == "POCO/surya_tr/surya:11/RKQ1.200826.002/V12.5.6.0.RJGTRXM:user/release-keys" ||
    getprop("ro.build.fingerprint") == "POCO/surya_tr/surya:11/RKQ1.200826.002/V12.5.7.0.RJGTRXM:user/release-keys" ||
    abort("E3001: Package expects build fingerprint of POCO/surya_tr/surya:11/RKQ1.200826.002/V12.5.6.0.RJGTRXM:user/release-keys or POCO/surya_tr/surya:11/RKQ1.200826.002/V12.5.7.0.RJGTRXM:user/release-keys; this device has " + getprop("ro.build.fingerprint") + ".");
patch_partition_check(concat("EMMC:","/dev/block/bootdevice/by-name/boot",":134217728:83504a705a098c706a18ab64e1388cb12e089c5b"),
                      concat("EMMC:","/dev/block/bootdevice/by-name/boot",":134217728:b357292611dede0942ba1f2de63617508792b352")) ||
    abort(concat("E3005: \"",concat("EMMC:","/dev/block/bootdevice/by-name/boot",":134217728:83504a705a098c706a18ab64e1388cb12e089c5b"),"\" or \"",concat("EMMC:","/dev/block/bootdevice/by-name/boot",":134217728:b357292611dede0942ba1f2de63617508792b352"),"\" has unexpected contents."));
apply_patch_space(134217728) || abort("E3006: Not enough free space on /cache to apply patches.");
if (range_sha1(map_partition("system"), "98,1,32,44,54,56,60,88,89,21342,21343,21373,21374,27539,27540,28955,57975,57986,57987,60144,60145,62968,62969,63713,63714,65274,65275,65467,65468,65536,65552,66704,66705,71074,71075,72192,72193,74211,74212,74693,74694,77857,77858,78454,78455,78642,78643,79345,79346,79562,79564,79703,79707,79715,79716,79729,79733,79737,79738,81145,81151,81184,81185,81192,81198,81199,81200,81207,81213,81214,81215,84709,84713,84753,84754,84825,84827,84920,84924,84929,84930,85068,85069,85101,85107,85108,85109,85231,85237,85238,271506,271512,688142,688144,715392,717555,728925,729078,729079") == "83b2c769e2bfc6dbc680f8327508a047d43e69e0" || block_image_verify(map_partition("system"), package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat")) then
ui_print("Verified system image...");
else
check_first_block(map_partition("system"));
ifelse (block_image_recover(map_partition("system"), "98,1,32,44,54,56,60,88,89,21342,21343,21373,21374,27539,27540,28955,57975,57986,57987,60144,60145,62968,62969,63713,63714,65274,65275,65467,65468,65536,65552,66704,66705,71074,71075,72192,72193,74211,74212,74693,74694,77857,77858,78454,78455,78642,78643,79345,79346,79562,79564,79703,79707,79715,79716,79729,79733,79737,79738,81145,81151,81184,81185,81192,81198,81199,81200,81207,81213,81214,81215,84709,84713,84753,84754,84825,84827,84920,84924,84929,84930,85068,85069,85101,85107,85108,85109,85231,85237,85238,271506,271512,688142,688144,715392,717555,728925,729078,729079") && block_image_verify(map_partition("system"), package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat"), ui_print("system recovered successfully."), abort("E1004: system partition fails to recover"));
endif;
if (range_sha1(map_partition("vendor"), "498,1,34,45,49,54,55,135,143,149,150,156,157,402,406,411,412,415,419,422,425,428,429,434,438,442,443,446,447,1267,1268,1428,1434,3623,3624,12526,12527,12545,12546,13457,13459,13462,13465,13468,13470,13471,13472,13474,13476,13477,13478,13480,13482,13483,13484,13486,13488,13489,13490,13492,13494,13498,13500,13501,13502,13504,13506,13507,13508,13511,13513,13521,13523,13526,13528,13531,13533,13534,13535,13538,13540,13541,13542,13544,13546,13547,13548,13550,13552,13553,13554,13556,13558,13559,13560,13562,13564,13565,13566,13577,13578,13597,13598,13603,13604,13605,13606,13609,13610,13611,13612,13615,13616,13617,13618,13621,13622,13623,13624,13628,13629,13630,13631,13634,13635,13636,13637,13640,13641,13642,13643,13648,13649,13653,13654,13658,13659,13663,13664,13673,13674,13675,13676,13679,13680,13681,13682,13685,13686,13687,13688,13691,13692,13693,13694,13991,13992,14275,14276,15101,15107,22283,22284,22416,22417,22427,22428,29963,29964,30069,30070,30071,30072,30570,30572,30577,30579,30585,30587,30592,30594,30653,30655,32768,32804,33097,33098,33462,33463,33504,33505,33764,33765,33832,33833,38635,38636,39474,39475,39479,39481,39498,39499,39534,39535,39544,39545,39547,39548,39598,39599,39602,39603,39664,39665,39671,39672,39697,39698,39730,39731,39834,39835,40206,40207,40209,40211,40275,40276,40346,40347,40414,40415,40417,40418,40420,40421,40480,40482,40484,40485,40549,40550,40620,40621,40688,40689,40691,40692,40694,40703,40704,40705,40767,40768,40834,40835,40837,40838,40841,40845,40847,40848,40850,40852,40854,40856,40915,40916,40918,40920,40980,40981,40983,40984,41045,41046,41048,41049,41109,41110,41112,41113,41180,41181,41249,41250,41317,41318,41384,41385,41387,41388,41451,41452,41518,41519,41521,41522,41583,41584,41586,41587,41651,41652,41654,41655,41717,41718,41720,41721,41785,41786,41788,41789,41850,41851,41853,41854,41918,41919,41921,41922,41986,41987,41989,41990,42054,42055,42057,42058,42122,42123,42125,42126,42193,42194,42195,42196,42262,42263,42264,42265,42270,42271,42331,42332,42398,42399,42401,42402,42465,42466,42532,42533,42535,42536,42597,42598,42600,42601,42665,42666,42668,42669,42731,42732,42734,42735,42799,42800,42802,42803,42864,42865,42867,42868,42932,42933,42935,42936,43000,43001,43003,43004,43068,43069,43071,43072,43136,43137,43139,43140,43207,43208,43209,43210,43276,43277,43278,43279,43284,43286,43346,43347,43419,43420,43422,43423,43485,43486,43556,43557,43565,43569,43570,43571,43770,43771,43837,43838,43840,43841,43844,43849,45245,45246,45411,45412,45723,45724,45785,45786,45935,45936,46015,46016,46048,46049,46125,46126,46193,46194,46266,46267,46359,46360,46432,46433,46478,46479,46583,46584,46627,46628,46630,46631,46663,46664,46825,46826,46897,46898,46950,46951,47275,47276,47278,47279,47373,47374,47498,47499,47573,47574,47607,47608,47671,47672,47743,47744,48247,48249,48254,48256,48320,48321,48373,48374,48880,48881,49166,262162,262169,273662,274491,278843,278913,278914") == "aae2d32aae1f8abbf855724e8612638208af295d" || block_image_verify(map_partition("vendor"), package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat")) then
ui_print("Verified vendor image...");
else
check_first_block(map_partition("vendor"));
ifelse (block_image_recover(map_partition("vendor"), "498,1,34,45,49,54,55,135,143,149,150,156,157,402,406,411,412,415,419,422,425,428,429,434,438,442,443,446,447,1267,1268,1428,1434,3623,3624,12526,12527,12545,12546,13457,13459,13462,13465,13468,13470,13471,13472,13474,13476,13477,13478,13480,13482,13483,13484,13486,13488,13489,13490,13492,13494,13498,13500,13501,13502,13504,13506,13507,13508,13511,13513,13521,13523,13526,13528,13531,13533,13534,13535,13538,13540,13541,13542,13544,13546,13547,13548,13550,13552,13553,13554,13556,13558,13559,13560,13562,13564,13565,13566,13577,13578,13597,13598,13603,13604,13605,13606,13609,13610,13611,13612,13615,13616,13617,13618,13621,13622,13623,13624,13628,13629,13630,13631,13634,13635,13636,13637,13640,13641,13642,13643,13648,13649,13653,13654,13658,13659,13663,13664,13673,13674,13675,13676,13679,13680,13681,13682,13685,13686,13687,13688,13691,13692,13693,13694,13991,13992,14275,14276,15101,15107,22283,22284,22416,22417,22427,22428,29963,29964,30069,30070,30071,30072,30570,30572,30577,30579,30585,30587,30592,30594,30653,30655,32768,32804,33097,33098,33462,33463,33504,33505,33764,33765,33832,33833,38635,38636,39474,39475,39479,39481,39498,39499,39534,39535,39544,39545,39547,39548,39598,39599,39602,39603,39664,39665,39671,39672,39697,39698,39730,39731,39834,39835,40206,40207,40209,40211,40275,40276,40346,40347,40414,40415,40417,40418,40420,40421,40480,40482,40484,40485,40549,40550,40620,40621,40688,40689,40691,40692,40694,40703,40704,40705,40767,40768,40834,40835,40837,40838,40841,40845,40847,40848,40850,40852,40854,40856,40915,40916,40918,40920,40980,40981,40983,40984,41045,41046,41048,41049,41109,41110,41112,41113,41180,41181,41249,41250,41317,41318,41384,41385,41387,41388,41451,41452,41518,41519,41521,41522,41583,41584,41586,41587,41651,41652,41654,41655,41717,41718,41720,41721,41785,41786,41788,41789,41850,41851,41853,41854,41918,41919,41921,41922,41986,41987,41989,41990,42054,42055,42057,42058,42122,42123,42125,42126,42193,42194,42195,42196,42262,42263,42264,42265,42270,42271,42331,42332,42398,42399,42401,42402,42465,42466,42532,42533,42535,42536,42597,42598,42600,42601,42665,42666,42668,42669,42731,42732,42734,42735,42799,42800,42802,42803,42864,42865,42867,42868,42932,42933,42935,42936,43000,43001,43003,43004,43068,43069,43071,43072,43136,43137,43139,43140,43207,43208,43209,43210,43276,43277,43278,43279,43284,43286,43346,43347,43419,43420,43422,43423,43485,43486,43556,43557,43565,43569,43570,43571,43770,43771,43837,43838,43840,43841,43844,43849,45245,45246,45411,45412,45723,45724,45785,45786,45935,45936,46015,46016,46048,46049,46125,46126,46193,46194,46266,46267,46359,46360,46432,46433,46478,46479,46583,46584,46627,46628,46630,46631,46663,46664,46825,46826,46897,46898,46950,46951,47275,47276,47278,47279,47373,47374,47498,47499,47573,47574,47607,47608,47671,47672,47743,47744,48247,48249,48254,48256,48320,48321,48373,48374,48880,48881,49166,262162,262169,273662,274491,278843,278913,278914") && block_image_verify(map_partition("vendor"), package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat"), ui_print("vendor recovered successfully."), abort("E2004: vendor partition fails to recover"));
endif;
if (range_sha1(map_partition("system_ext"), "386,1,30,39,43,47,48,55,61,62,63,79,85,86,87,146,150,155,156,717,719,776,780,795,796,1185,1191,1205,1206,1213,1219,1220,1221,1450,1454,1463,1464,1495,1501,1502,1503,1699,1703,1707,1708,1712,1716,1721,1722,1727,1728,1736,1742,1743,1744,1768,1774,1775,1776,2512,2516,2534,2535,2541,2547,2548,2549,2561,2567,2568,2569,2580,2581,2587,2591,2595,2596,2601,2607,2611,2612,2621,2627,2628,2629,2642,2648,2649,2650,2662,2668,2669,2670,2673,2680,2688,2695,2762,2769,2775,2782,2814,2821,2841,2848,2867,2872,2890,2897,2915,2916,3121,3123,3151,3152,3164,3165,3166,3167,3168,3169,3177,3178,3201,3202,3247,3252,3255,3258,3261,3262,3766,3768,3772,3776,3781,3783,3788,3792,3793,3797,3798,3802,3803,3807,3808,3812,3813,3817,3818,3822,3823,3825,3832,3836,3837,3841,3842,3846,3847,3851,3852,3856,3857,3861,3862,3866,3867,3869,3870,3874,3875,3879,3880,3884,3885,3889,3890,3894,3895,3899,3900,3904,3905,3907,3911,3915,3916,3920,3921,3923,3924,3926,3927,3931,3932,3936,3937,3939,3940,3944,3945,3949,3950,3954,3955,3959,3960,3962,3963,3967,3968,3970,3974,3987,3992,4022,4025,4136,6541,6542,6677,7346,7599,7600,9665,9666,9724,9725,10507,10508,10558,10559,10868,10869,16050,16051,16123,16124,16132,16133,16268,16269,16273,16274,16327,16328,16338,16339,16372,16373,16392,16393,16445,16446,16591,16592,16667,16668,16814,16815,21565,21567,21706,21707,21732,21733,21829,21830,21881,21882,21893,21894,21944,21945,22020,22021,22084,22085,22347,22348,22852,22853,26727,26728,26784,26785,27209,27210,32768,32813,33291,65493,65536,65564,65591,65617,66062,66289,68966,68967,68968,68969,68973,68974,68985,68988,68990,68991,68998,68999,69004,69007,69008,69009,69015,69016,69023,69024,69027,69028,69033,69035,69036,69037,69040,69044,69046,69048,69050,69053,69056,69058,69094,69095,69096,69097,69103,69104,69107,69108,69111,69116,69120,69121,69123,69124,69127,69128,69133,69134,69142,69144,69146,69151,69156,69160,69163,69164,69165,69167,69168,69169,69180,69181,69195,69198,69200,69204,69206,69207,69214,70702,70704,70708,70860,70979,71633,71635,71659,98326,98327,115758,116110,117954,117992,117993") == "53f99fa241e2b1596f02ce21798309c671db36dd" || block_image_verify(map_partition("system_ext"), package_extract_file("system_ext.transfer.list"), "system_ext.new.dat", "system_ext.patch.dat")) then
ui_print("Verified system_ext image...");
else
check_first_block(map_partition("system_ext"));
ifelse (block_image_recover(map_partition("system_ext"), "386,1,30,39,43,47,48,55,61,62,63,79,85,86,87,146,150,155,156,717,719,776,780,795,796,1185,1191,1205,1206,1213,1219,1220,1221,1450,1454,1463,1464,1495,1501,1502,1503,1699,1703,1707,1708,1712,1716,1721,1722,1727,1728,1736,1742,1743,1744,1768,1774,1775,1776,2512,2516,2534,2535,2541,2547,2548,2549,2561,2567,2568,2569,2580,2581,2587,2591,2595,2596,2601,2607,2611,2612,2621,2627,2628,2629,2642,2648,2649,2650,2662,2668,2669,2670,2673,2680,2688,2695,2762,2769,2775,2782,2814,2821,2841,2848,2867,2872,2890,2897,2915,2916,3121,3123,3151,3152,3164,3165,3166,3167,3168,3169,3177,3178,3201,3202,3247,3252,3255,3258,3261,3262,3766,3768,3772,3776,3781,3783,3788,3792,3793,3797,3798,3802,3803,3807,3808,3812,3813,3817,3818,3822,3823,3825,3832,3836,3837,3841,3842,3846,3847,3851,3852,3856,3857,3861,3862,3866,3867,3869,3870,3874,3875,3879,3880,3884,3885,3889,3890,3894,3895,3899,3900,3904,3905,3907,3911,3915,3916,3920,3921,3923,3924,3926,3927,3931,3932,3936,3937,3939,3940,3944,3945,3949,3950,3954,3955,3959,3960,3962,3963,3967,3968,3970,3974,3987,3992,4022,4025,4136,6541,6542,6677,7346,7599,7600,9665,9666,9724,9725,10507,10508,10558,10559,10868,10869,16050,16051,16123,16124,16132,16133,16268,16269,16273,16274,16327,16328,16338,16339,16372,16373,16392,16393,16445,16446,16591,16592,16667,16668,16814,16815,21565,21567,21706,21707,21732,21733,21829,21830,21881,21882,21893,21894,21944,21945,22020,22021,22084,22085,22347,22348,22852,22853,26727,26728,26784,26785,27209,27210,32768,32813,33291,65493,65536,65564,65591,65617,66062,66289,68966,68967,68968,68969,68973,68974,68985,68988,68990,68991,68998,68999,69004,69007,69008,69009,69015,69016,69023,69024,69027,69028,69033,69035,69036,69037,69040,69044,69046,69048,69050,69053,69056,69058,69094,69095,69096,69097,69103,69104,69107,69108,69111,69116,69120,69121,69123,69124,69127,69128,69133,69134,69142,69144,69146,69151,69156,69160,69163,69164,69165,69167,69168,69169,69180,69181,69195,69198,69200,69204,69206,69207,69214,70702,70704,70708,70860,70979,71633,71635,71659,98326,98327,115758,116110,117954,117992,117993") && block_image_verify(map_partition("system_ext"), package_extract_file("system_ext.transfer.list"), "system_ext.new.dat", "system_ext.patch.dat"), ui_print("system_ext recovered successfully."), abort("E2004: system_ext partition fails to recover"));
endif;
if (range_sha1(map_partition("product"), "346,1,16,33,37,41,42,4814,4815,5238,5240,7277,7281,7374,7375,8377,8378,10075,10078,10084,10085,10126,10127,18540,18541,28348,28349,29024,29028,29994,29995,31337,31338,31472,31473,31528,31529,32768,32777,33152,33153,33515,33519,34038,34039,34051,34057,34058,34059,43810,43811,47682,47683,47933,47938,47950,47951,48015,48018,48211,48216,48473,48475,51957,51958,61800,61801,65536,65543,71351,71358,72834,72835,78210,78211,81360,81361,90912,90913,90920,90921,91050,91056,91057,91058,91071,91077,91078,91081,91083,91084,98304,98313,98613,98614,99854,99858,100871,100872,104720,104722,118205,118206,118275,118276,120497,120499,131072,131079,141004,141005,143013,143014,150315,150316,156687,156688,160677,160678,160979,160980,161032,161034,161043,161044,161138,161140,161929,161930,161937,161938,161944,161945,163840,163849,166283,166284,166517,166519,166529,166531,166577,166579,166589,166591,166600,166601,168419,168422,171807,171808,171971,171972,171973,171974,171975,171976,171992,171993,171996,171998,171999,172001,172017,172018,172030,172031,172070,172074,172078,172082,172083,172087,172088,172104,172519,172520,172891,172892,174377,174378,174467,174469,174472,174473,174476,174477,174480,174481,174484,174485,174488,174489,174492,174493,174507,174508,174514,174515,174521,174522,174528,174529,174535,174536,174542,174543,174582,174583,174604,174605,174612,174613,174634,174635,174652,174653,174659,174660,174678,174679,174686,174687,174706,174707,174722,174723,174728,174729,174749,174750,174757,174758,174779,174780,174797,174798,174804,174805,174808,174809,174812,174813,174816,174817,174820,174821,174824,174825,175418,175420,177866,177867,195204,195206,195207,195208,196348,196349,196608,196627,204567,204569,205619,205621,207861,207862,208036,208040,208088,208089,208104,208105,216665,216666,220201,220202,220251,220252,221821,221825,221893,221894,221924,221925,222061,222065,222073,222074,223462,223466,223501,223502,224234,224235,229376,229384,230682,230683,234904,234905,236432,236433,237097,237101,237117,237118,238691,238695,238720,238721,249553,249554,262144,262145,274702,274703,274728,274729,274932,274933,275410,275411,275650,275651,276390,276391,276970,276971,277148,277149,278124,278126,278599,278600,279241,279242,282165,282166,283102,283105,286439,286440,293751,298408,298480,298481") == "ff9071da33eba395f4a4f0633b7a98397506835f" || block_image_verify(map_partition("product"), package_extract_file("product.transfer.list"), "product.new.dat", "product.patch.dat")) then
ui_print("Verified product image...");
else
ifelse (block_image_recover(map_partition("product"), "346,1,16,33,37,41,42,4814,4815,5238,5240,7277,7281,7374,7375,8377,8378,10075,10078,10084,10085,10126,10127,18540,18541,28348,28349,29024,29028,29994,29995,31337,31338,31472,31473,31528,31529,32768,32777,33152,33153,33515,33519,34038,34039,34051,34057,34058,34059,43810,43811,47682,47683,47933,47938,47950,47951,48015,48018,48211,48216,48473,48475,51957,51958,61800,61801,65536,65543,71351,71358,72834,72835,78210,78211,81360,81361,90912,90913,90920,90921,91050,91056,91057,91058,91071,91077,91078,91081,91083,91084,98304,98313,98613,98614,99854,99858,100871,100872,104720,104722,118205,118206,118275,118276,120497,120499,131072,131079,141004,141005,143013,143014,150315,150316,156687,156688,160677,160678,160979,160980,161032,161034,161043,161044,161138,161140,161929,161930,161937,161938,161944,161945,163840,163849,166283,166284,166517,166519,166529,166531,166577,166579,166589,166591,166600,166601,168419,168422,171807,171808,171971,171972,171973,171974,171975,171976,171992,171993,171996,171998,171999,172001,172017,172018,172030,172031,172070,172074,172078,172082,172083,172087,172088,172104,172519,172520,172891,172892,174377,174378,174467,174469,174472,174473,174476,174477,174480,174481,174484,174485,174488,174489,174492,174493,174507,174508,174514,174515,174521,174522,174528,174529,174535,174536,174542,174543,174582,174583,174604,174605,174612,174613,174634,174635,174652,174653,174659,174660,174678,174679,174686,174687,174706,174707,174722,174723,174728,174729,174749,174750,174757,174758,174779,174780,174797,174798,174804,174805,174808,174809,174812,174813,174816,174817,174820,174821,174824,174825,175418,175420,177866,177867,195204,195206,195207,195208,196348,196349,196608,196627,204567,204569,205619,205621,207861,207862,208036,208040,208088,208089,208104,208105,216665,216666,220201,220202,220251,220252,221821,221825,221893,221894,221924,221925,222061,222065,222073,222074,223462,223466,223501,223502,224234,224235,229376,229384,230682,230683,234904,234905,236432,236433,237097,237101,237117,237118,238691,238695,238720,238721,249553,249554,262144,262145,274702,274703,274728,274729,274932,274933,275410,275411,275650,275651,276390,276391,276970,276971,277148,277149,278124,278126,278599,278600,279241,279242,282165,282166,283102,283105,286439,286440,293751,298408,298480,298481") && block_image_verify(map_partition("product"), package_extract_file("product.transfer.list"), "product.new.dat", "product.patch.dat"), ui_print("product recovered successfully."), abort("E2004: product partition fails to recover"));
endif;

# ---- start making changes here ----


# ---- radio update tasks ----

ui_print("Patching firmware images...");
package_extract_file("firmware-update/cmnlib64.mbn", "/dev/block/bootdevice/by-name/cmnlib64");
package_extract_file("firmware-update/imagefv.elf", "/dev/block/bootdevice/by-name/imagefv");
package_extract_file("firmware-update/cmnlib.mbn", "/dev/block/bootdevice/by-name/cmnlib");
package_extract_file("firmware-update/hyp.mbn", "/dev/block/bootdevice/by-name/hyp");
package_extract_file("firmware-update/km4.mbn", "/dev/block/bootdevice/by-name/keymaster");
package_extract_file("firmware-update/tz.mbn", "/dev/block/bootdevice/by-name/tz");
package_extract_file("firmware-update/aop.mbn", "/dev/block/bootdevice/by-name/aop");
package_extract_file("firmware-update/xbl_config.elf", "/dev/block/bootdevice/by-name/xbl_config");
package_extract_file("firmware-update/BTFM.bin", "/dev/block/bootdevice/by-name/bluetooth");
package_extract_file("firmware-update/uefi_sec.mbn", "/dev/block/bootdevice/by-name/uefisecapp");
package_extract_file("firmware-update/NON-HLOS.bin", "/dev/block/bootdevice/by-name/modem");
package_extract_file("firmware-update/qupv3fw.elf", "/dev/block/bootdevice/by-name/qupfw");
package_extract_file("firmware-update/abl.elf", "/dev/block/bootdevice/by-name/abl");
package_extract_file("firmware-update/devcfg.mbn", "/dev/block/bootdevice/by-name/devcfg");
package_extract_file("firmware-update/storsec.mbn", "/dev/block/bootdevice/by-name/storsec");
package_extract_file("firmware-update/xbl.elf", "/dev/block/bootdevice/by-name/xbl");
package_extract_file("firmware-update/cmnlib64.mbn", "/dev/block/bootdevice/by-name/cmnlib64bak");
package_extract_file("firmware-update/imagefv.elf", "/dev/block/bootdevice/by-name/imagefvbak");
package_extract_file("firmware-update/cmnlib.mbn", "/dev/block/bootdevice/by-name/cmnlibbak");
package_extract_file("firmware-update/hyp.mbn", "/dev/block/bootdevice/by-name/hypbak");
package_extract_file("firmware-update/km4.mbn", "/dev/block/bootdevice/by-name/keymasterbak");
package_extract_file("firmware-update/tz.mbn", "/dev/block/bootdevice/by-name/tzbak");
package_extract_file("firmware-update/aop.mbn", "/dev/block/bootdevice/by-name/aopbak");
package_extract_file("firmware-update/xbl_config.elf", "/dev/block/bootdevice/by-name/xbl_configbak");
package_extract_file("firmware-update/uefi_sec.mbn", "/dev/block/bootdevice/by-name/uefisecappbak");
package_extract_file("firmware-update/qupv3fw.elf", "/dev/block/bootdevice/by-name/qupfwbak");
package_extract_file("firmware-update/abl.elf", "/dev/block/bootdevice/by-name/ablbak");
package_extract_file("firmware-update/devcfg.mbn", "/dev/block/bootdevice/by-name/devcfgbak");
package_extract_file("firmware-update/xbl.elf", "/dev/block/bootdevice/by-name/xblbak");

# --- Start patching dynamic partitions ---


# Patch partition system

ui_print("Patching system image after verification.");
show_progress(0.600000, 0);
block_image_update(map_partition("system"), package_extract_file("system.transfer.list"), "system.new.dat", "system.patch.dat") ||
  abort("E1001: Failed to update system image.");

# Update dynamic partition metadata

assert(update_dynamic_partitions(package_extract_file("dynamic_partitions_op_list")));

# Patch partition vendor

ui_print("Patching vendor image after verification.");
show_progress(0.100000, 0);
block_image_update(map_partition("vendor"), package_extract_file("vendor.transfer.list"), "vendor.new.dat", "vendor.patch.dat") ||
  abort("E2001: Failed to update vendor image.");

# Patch partition system_ext

ui_print("Patching system_ext image after verification.");
show_progress(0.100000, 0);
block_image_update(map_partition("system_ext"), package_extract_file("system_ext.transfer.list"), "system_ext.new.dat", "system_ext.patch.dat") ||
  abort("E2001: Failed to update system_ext image.");

# Patch partition product

ui_print("Patching product image after verification.");
show_progress(0.100000, 0);
block_image_update(map_partition("product"), package_extract_file("product.transfer.list"), "product.new.dat", "product.patch.dat") ||
  abort("E2001: Failed to update product image.");

# --- End patching dynamic partitions ---

ui_print("Patching boot image...");
show_progress(0.100000, 10);
patch_partition(concat("EMMC:","/dev/block/bootdevice/by-name/boot",":134217728:83504a705a098c706a18ab64e1388cb12e089c5b"),
                concat("EMMC:","/dev/block/bootdevice/by-name/boot",":134217728:b357292611dede0942ba1f2de63617508792b352"),
                package_extract_file("boot.img.p")) ||
    abort(concat(        "E3008: Failed to apply patch to ",concat("EMMC:","/dev/block/bootdevice/by-name/boot",":134217728:b357292611dede0942ba1f2de63617508792b352")));

# ---- radio update tasks 2 ----

ui_print("Patching vbmeta dtbo logo binimages...");
package_extract_file("firmware-update/dtbo.img", "/dev/block/bootdevice/by-name/dtbo");
package_extract_file("firmware-update/vbmeta.img", "/dev/block/bootdevice/by-name/vbmeta");
package_extract_file("firmware-update/vbmeta_system.img", "/dev/block/bootdevice/by-name/vbmeta_system");
set_progress(1.000000);
