(!less_than_int(1743037667, getprop("ro.build.date.utc"))) || abort("E3003: Can't install this package (Thu Mar 27 09:07:47 CST 2025) over newer build (" + getprop("ro.build.date") + ").");
getprop("ro.product.device") == "sti6130d350" || abort("E3004: This package is for \"sti6130d350\" devices; this is a \"" + getprop("ro.product.device") + "\".");
if ota_zip_check() == "1" then
ui_print("ota_zip_check() == 1");
if recovery_backup_exist() == "0" then
package_extract_file("dt.img", "/cache/recovery/dtb.img");
package_extract_file("recovery.img", "/cache/recovery/recovery.img");
endif;
set_bootloader_env("upgrade_step", "3");
ui_print("update bootloader.img...");
write_bootloader_image(package_extract_file("bootloader.img"));
set_bootloader_env("recovery_from_flash", "defenv_reserv;saveenv;reset");
write_dtb_image(package_extract_file("dt.img"));
package_extract_file("recovery.img", "/dev/block/by-name/recovery");
delete_file("/cache/recovery/dtb.img");
delete_file("/cache/recovery/recovery.img");
reboot_recovery();
else
ui_print("else case, ota_zip_check() != 1");
ui_print("Target: Dynalink/sti6130d350/sti6130d350:14/UKG3.240613.001/20250327:user/release-keys");
set_bootloader_env("upgrade_step", "3");
if get_update_stage() == "2" then
ui_print("partition table changed => writing super_empty_all.img to super block...");
package_extract_file("super_empty_all.img", "/dev/block/by-name/super");
else
ui_print("partition table NOT changed...");
endif;
delete_file("/cache/recovery/dynamic_partition_metadata.UPDATED");

# --- Start patching dynamic partitions ---


# Update dynamic partition metadata

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

# Patch partition system

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

# Patch partition vendor

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

# Patch partition product

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

# Patch partition odm

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

# Patch partition system_dlkm

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

# --- End patching dynamic partitions ---

package_extract_file("boot.img", "/dev/block/by-name/boot");
show_progress(0.100000, 10);
ui_print("update logo.img...");
package_extract_file("logo.img", "/dev/block/by-name/logo");
ui_print("update dtbo.img...");
package_extract_file("dtbo.img", "/dev/block/by-name/dtbo");
ui_print("update odm_ext.img...");
package_extract_file("odm_ext.img", "/dev/block/by-name/odm_ext");
if recovery_backup_exist() == "0" then
backup_data_cache(recovery, /cache/recovery/);
endif;if recovery_backup_exist() == "0" then
backup_data_cache(dtb, /cache/recovery/);
endif;
ui_print("update recovery.img...");
package_extract_file("recovery.img", "/dev/block/by-name/recovery");
ui_print("update vbmeta.img...");
package_extract_file("vbmeta.img", "/dev/block/by-name/vbmeta");
ui_print("update dtb.img...");
write_dtb_image(package_extract_file("dt.img"));
delete_file("/cache/recovery/dtb.img");
delete_file("/cache/recovery/recovery.img");
ui_print("update bootloader.img...");
write_bootloader_image(package_extract_file("bootloader.img"));
if get_update_stage() == "2" then
format("ext4", "EMMC", "/dev/block/by-name/param", "0", "/param");
set_update_stage("0");
endif;
if get_update_state("/cache/recovery/state") == "3" then
format("ext4", "EMMC", "/dev/block/by-name/metadata", "0", "/metadata");
set_update_state("/cache/recovery/state", "0");
endif;
set_bootloader_env("upgrade_step", "1");
set_bootloader_env("force_auto_update", "false");
endif;
set_progress(1.000000);
