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");
write_dtb_image(package_extract_file("dt.img"));
if check_path_access("/dev/block/by-name") != "0" then
ui_print("Partition update on legacy path ... ");
package_extract_file("recovery.img", "/dev/block/recovery");
package_extract_file("boot.img", "/dev/block/boot");
package_extract_file("vbmeta.img", "/dev/block/vbmeta");
else
ui_print("Partition update on latest path ... ");
package_extract_file("recovery.img", "/dev/block/recovery");
package_extract_file("boot.img", "/dev/block/boot");
package_extract_file("vbmeta.img", "/dev/block/vbmeta");
endif;
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: Amino/H200/H200:12/STTC.230104.002/25.6.2530.10R:user/release-keys");
set_bootloader_env("upgrade_step", "3");
format("ext4", "EMMC", "/dev/block/metadata", "0", "/metadata");
if get_update_stage() == "2" then
ui_print("DTB changed => writing super_empty_all.img to super block...");
package_extract_file("super_empty_all.img", "/dev/block/by-name/super");
else
ui_print("DTB 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_ext

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

# --- End patching dynamic partitions ---

package_extract_file("boot.img", "/dev/block/boot");
show_progress(0.100000, 10);
if get_bootloader_env("amino_dynamic_logo") != "1" then
ui_print("update logo.img...");
package_extract_file("logo.img", "/dev/block/by-name/logo");
else
ui_print("skip logo partition when dynamic logo is enabled");
endif;
ui_print("update dtbo.img...");
package_extract_file("dtbo.img", "/dev/block/by-name/dtbo");
if recovery_backup_exist() == "0" then
backup_data_cache(dtb, /cache/recovery/);
backup_data_cache(recovery, /cache/recovery/);
endif;
ui_print("update dtb.img...");
write_dtb_image(package_extract_file("dt.img"));
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");
delete_file("/cache/recovery/dtb.img");
delete_file("/cache/recovery/recovery.img");
if get_bootloader_env("amino_robustota") == "update_boot_img_ext4" then
delete_file("/cache/recovery/boot.img");
delete_file("/cache/recovery/vbmeta.img");
endif;
ui_print("update bootloader image...");
ui_print(get_bootloader_env("amino_target_bootloader"));
write_bootloader_image(package_extract_file(get_bootloader_env("amino_target_bootloader")));
if get_update_stage() == "2" then
set_update_stage("0");
endif;
set_bootloader_env("upgrade_step", "1");
set_bootloader_env("force_auto_update", "false");
endif;
set_progress(1.000000);
