tzh
2024-08-14 a57e9b48676d47d3f6874b492fe8fb8ec26dfdbb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import tempfile
 
import common
import sparse_img
 
OPTIONS = common.OPTIONS
 
def AssertBootVersion(info):
  info.script.AppendExtra(
      'assert_boot_version(%s);'%(info.info_dict.get("boot_version", "0")))
 
def GetFex(name, tmpdir):
  path = os.path.join(tmpdir, "IMAGES", name)
  if os.path.exists(path):
    return common.File.FromLocalFile(name, path)
  else:
    print " %s is not exist " %(path)
    return None
 
def WriteRawFex(info, mount_point, fn):
  info.script.AppendExtra(
      'package_extract_file("%s","%s");'%(fn, mount_point))
 
VENDOR_PARTITIONS = [
    ('bootloader', 'boot-resource.fex'),
    ('env', 'env.fex'),
    ('vbmeta', 'vbmeta.img'),
    ('vbmeta_system', 'vbmeta_system.img'),
    ('vbmeta_vendor', 'vbmeta_vendor.img'),
]
 
def UpdateVendorPartitions(info):
  for partition, img in VENDOR_PARTITIONS:
    print('%-25s = %s' % (partition, img))
    img_block = GetFex(img, OPTIONS.target_tmp)
    if img_block:
      info.script.Print('Updating %s into %s partition...' % (img, partition))
      common.ZipWriteStr(info.output_zip, img, img_block.data)
      WriteRawFex(info, '/dev/block/by-name/' + partition, img)
 
def UpdateBoot(info):
  boot0_nand = GetFex("boot0_nand.fex", OPTIONS.target_tmp)
  if boot0_nand:
    common.ZipWriteStr(info.output_zip, "boot0_nand.fex", boot0_nand.data)
  boot0_sdcard = GetFex("boot0_sdcard.fex", OPTIONS.target_tmp)
  if boot0_sdcard:
    common.ZipWriteStr(info.output_zip, "boot0_sdcard.fex", boot0_sdcard.data)
  uboot = GetFex("u-boot.fex", OPTIONS.target_tmp)
  if uboot:
    common.ZipWriteStr(info.output_zip, "u-boot.fex", uboot.data)
  toc0 = GetFex("toc0.fex", OPTIONS.target_tmp)
  if toc0:
    common.ZipWriteStr(info.output_zip, "toc0.fex", toc0.data)
  toc1 = GetFex("toc1.fex", OPTIONS.target_tmp)
  if toc1:
    common.ZipWriteStr(info.output_zip, "toc1.fex", toc1.data)
  info.script.Print("Updating boot...")
  info.script.AppendExtra('burnboot();')
 
# only use in when mbr to gpt UDISK size need to be smaller
def ResizeUdisk(info):
  info.script.AppendExtra('resize2fs("%s");'%("/dev/block/by-name/UDISK"))
 
def FullOTA_Assertions(info):
  AssertBootVersion(info)
 
def FullOTA_InstallEnd(info):
  print("pack custom to OTA package...")
  UpdateVendorPartitions(info)
  UpdateBoot(info)
 
def IncrementalOTA_Assertions(info):
  AssertBootVersion(info)
 
def IncrementalOTA_InstallEnd(info):
  print("pack custom to OTA package...")
  UpdateVendorPartitions(info)
  UpdateBoot(info)
 
 
# The joint list of user image partitions of source and target builds.
# - Items should be added to the list if new dynamic partitions are added.
# - Items should not be removed from the list even if dynamic partitions are
#   deleted. When generating an incremental OTA package, this script needs to
#   know that an image is present in source build but not in target build.
USERIMAGE_PARTITIONS = [
    "product",
]
 
 
def GetUserImages(input_tmp, input_zip):
  return {partition: common.GetUserImage(partition, input_tmp, input_zip)
          for partition in USERIMAGE_PARTITIONS
          if os.path.exists(os.path.join(input_tmp,
                                         "IMAGES", partition + ".img"))}
 
 
def FullOTA_GetBlockDifferences(info):
  images = GetUserImages(info.input_tmp, info.input_zip)
  return [common.BlockDifference(partition, image)
          for partition, image in images.items()]
 
 
def IncrementalOTA_GetBlockDifferences(info):
  source_images = GetUserImages(info.source_tmp, info.source_zip)
  target_images = GetUserImages(info.target_tmp, info.target_zip)
 
  # Use EmptyImage() as a placeholder for partitions that will be deleted.
  for partition in source_images:
    target_images.setdefault(partition, common.EmptyImage())
 
  # Use source_images.get() because new partitions are not in source_images.
  return [common.BlockDifference(partition, target_image, source_images.get(partition))
          for partition, target_image in target_images.items()]