Android OTA upgrade Package production script in detail (iv, Generate upgrade script updater-script)

Source: Internet
Author: User
Tags symlink

Updater-script Introduction:

Updater-script is the script file that we use to upgrade, which is used primarily to control the main logic of the upgrade process. The exact location is located in the/meta-info/com/google/android/directory of the update package, which is generated when we make the upgrade package.

Updater-script Generation:

So how is the upgrade script Updater-script produced, we look at a statement in Ota_from_target_file, which has been introduced before.

The module Edify_generator #在/build/tools/releasetools/directory is used as an abstract script generator to generate edify scripts. The edify script here refers to the updater-script-upgrade installation script, which is a text file. Edify is a simple scripting language for installing CyanogenMod and other software from a. zip file. The edify script is not necessarily used to update the firmware. It can be used to replace/Add/Remove specific files, even format partitions. Typically, the edify script runs when the user chooses "brush write zip" in recovery mode.
Script = Edify_generator. Edifygenerator (3, options.info_dict)

So how to automatically build each script instruction or script statement in Updater-script, here we give you a few examples as a reference:

① Compare update package timestamp, only allow upgrade of old version

The following code is a statement in Ota_from_target_files

  #下面这段代码我们可以理解为不允许降级, that is, the Assert statement in the script so that the update zip package can only be used to upgrade older versions.  if not options.omit_prereq:    ts = getbuildprop ("RO.BUILD.DATE.UTC", options.info_dict) #得到系统编译世界时间    ts_ Text = Getbuildprop ("Ro.build.date", options.info_dict) #得到编译日期    script. Assertolderbuild (TS, Ts_text)
The following are the relevant methods in the corresponding Edify_generator module:

  def assertolderbuild (self, timestamp, timestamp_text): "" "asserts that the build on the    device is older (or the same as ) the    given timestamp.    "" " Self.script.append (        ' (' (!less_than_int (%s, Getprop ("RO.BUILD.DATE.UTC")) | | '         abort (' can\ ' t install this package (%s) over newer '         build ("+ Getprop (" ro.build.date ") +"). ")         % (timestamp, timestamp_text))
So what we can see from the code above is that this is appended to the Updater-script:

' (!less_than_int (%s, Getprop ("RO.BUILD.DATE.UTC"))) | | '         abort (' can\ ' t install this package (%s) over newer '         build ("+ Getprop (" ro.build.date ") +"). ")         % (timestamp, timestamp_text)

So this is actually the case in the script, such as:

(!less_than_int (1413536309, Getprop ("RO.BUILD.DATE.UTC"))) | | Abort ("Can ' t install this package (Fri Oct 16:58:29 CST) over newer build (" + Getprop ("ro.build.date") + ").");

So this is what we do when we execute the Updater-script script. The specific logic is to terminate the installation update when the version in the update package is lower than the version in the current phone. So how does it work when it's installed, and we'll describe it later in detail.

② Show Progress

  #在升级脚本中生成显示进度的语句, this is actually the addition of a statement (show_progress) parameter in the script that represents the percentage of time that will take up in the overall time. Parameter two is used to control the display speed. such as Show_progress (0.1), show_progress the following operation may be 10s, completed after the progress bar 0.1 (that is, 10%)  script. ShowProgress (0.5, 0)
Then the ShowProgress (0.05,0) in the Edify_generator module is called:

def setprogress (self, Frac): "" "Set the position of the    progress bar within the chunk defined by the most    recent S Howprogress call.  ' Frac ' should is in    [0,1].    "" " Self.script.append ("set_progress (%f);"% (Frac,))

and the actual logic in Updater-script is as follows:

Show_progress (0.500000, 0);

③ Formatting partitions

  #如果命令中有参数要求擦除data分区数据, the format partition statement is generated in the upgrade script, and the partition is described by a mount point, in the following format: (/data)  if Options.wipe_user_data:    script. Formatpartition ("/data")

Then the formatpartition () function in the Edify_generator module is called:

  def formatpartition (self, Partition): "" "    Format the given partition, specified by it mount point (eg,    "/system ") ."""    reserve_size = 0    fstab = self.info.get ("Fstab", None)    #wschen 2012-11-12     if partition = = "/custom":      Self.script.append (' Format ' ("Ext4", "EMMC", "/dev/block/mmcblk", "0", "/custom");    Elif fstab:      p = fstab[partition] self.script.append (' Format ('%s ', '%s ', '%s ', '%s ', '%s '      ); '%                         (p.fs_type , Common. Partition_types[p.fs_type],                          p.device, P.length, P.mount_point))

④ Mount Partition

Script. Mount ("/system")
Then this calls the mount () function in the Edify_generator module:

  def mount (self, Mount_point): "" "mount the partition with the    given mount_point." " #根据指定的挂载点挂载分区    fstab = Self.info.get ("Fstab", None)    #wschen 2012-11-12 #这里挂载定制分区custom, not described in detail, A detailed description of the    if mount_point = = "/custom":      self.script.append (' Mount ("Ext4", "EMMC", "/dev/block/") will be followed for the upgrade of the custom partition. Mmcblk ","/custom ");      Self.mounts.add (mount_point)    elif fstab:      p = fstab[mount_point]      self.script.append (' Mount ('%s ', '%s ', ' %s ","%s "); '%                         (p.fs_type, Common. Partition_types[p.fs_type],                          p.device, P.mount_point)      Self.mounts.add (P.mount_point)

⑤ Release folder contents to the specified folder, note that the folder that is released here refers to the corresponding folder in the OTA package, which is the update bundle, which is the first parameter in the following function

    Script. Unpackpackagedir ("Recovery", "/system")    script. Unpackpackagedir ("System", "/system")
Then this calls the Unpackpackagedir () function in the Edify_generator module

  def unpackpackagedir (self, SRC, DST): "" "    Unpack a given directory from the OTA to the given    destination Directory.    "" " Self.script.append (' Package_extract_dir ('%s ', '%s '); '% (SRC, DST))

⑥ Creating Symbolic Links

symlinks = Copysystemfiles (Input_zip, Output_zip)    script. Makesymlinks (symlinks)
The corresponding makesymlinks () function in the Edify_generator module

  def makesymlinks (self, symlink_list): "" "    Create symlinks, given a list of (dest, link) pairs.    " " By_dest = {}    for D, L-symlink_list:      By_dest.setdefault (d, []). Append (l)    for dest, links in sorted (by_dest. Iteritems ()):      cmd = (' Symlink ('%s ', '% (dest,) + ', ' + ')             . Join ([' "' + i + '" ' for I in sorted (links)]) + "      ) Self.script.append (Self._wordwrap (cmd))

⑦ permission settings

          Script. SetPermissions ("/" +item.name, Item.uid, Item.gid,                                Item.mode, Item.selabel, item.capabilities)

Specific functions such as:

  def setpermissions (self, FN, UID, GID, mode, Selabel, capabilities): "" "    Set file ownership and permissions.    " " If not Self.info.get ("Use_set_metadata", False):      self.script.append (' Set_perm (%d,%d, 0%o, '%s '); '% (UID, GID, mode , FN))    else:      if capabilities is none:capabilities = "0x0"      cmd = ' set_metadata ("%s", "UID",%d, "GID",%d, "Mo De ", 0%o, '           " capabilities ",%s '% (FN, UID, GID, mode, capabilities)      if Selabel is not None:        cmd + = '," Selab El ","%s "'% (selabel)      cmd + = '); '      Self.script.append (CMD)

⑧ Write partition

  Script. Writerawimage ("/Boot", "boot.img")
The specific corresponding function is as follows:

def writerawimage (self, Mount_point, fn): "" "Write the given package file into the partition for the given Mount POI    NT. "" " Fstab = self.info["Fstab"] if fstab:p = fstab[mount_point] Partition_type = common.        Partition_types[p.fs_type] args = {' device ': P.device, ' fn ': fn} if fn = = "Boot.img" and P.device = = "Boot": Self.script.append (' Assert (Package_extract_file ("% (FN) S", "/tmp/% (FN) s"), \ n ' write_raw_im Age ("/tmp/% (FN) S", "bootimg"), \ n ' ' Delete ("/tmp/% (FN) S")); % args) elif Partition_type = = "MTD": Self.script.append (' Write_raw_image (Package_extract_file ("% (            FN) S "),"% (device) S "); ' % args) elif Partition_type = = "EMMC": Self.script.append (' Package_extract_file ("% (FN) s", "% (Devic e) S "); '% args" else:raise valueerror ("don ' t know how to write \"%s\ "Partitions"% (P.fs_type,))

The following post Updater-script simple syntax for everyone to refer to:

1. Mount
Grammar:
Mount (type, location, Mount_point), where it is mounted, where type= "MTD" location= "<partition>" mounts the YAFFS2 file system partition;
Type= "Vfat" location= "/dev/block/<whatever>" mount the device. such as: Mount ("MTD", "System", "/system"), mount the system partition, set the return pointer "/system"
Mount ("Vfat", "/dev/block/mmcblk1p2", "/system");
Mount/DEV/BLOCK/MMCBLK1P2, return pointer "/system"
2, Unmount
Grammar:
Unmount (mount_point); Mount_point is the pointer that is set by mount. The function corresponds to the mount, unloading the partition or device. This function is used with mount. such as; Unmount ("/system");
Uninstalling the/system partition
3. Format
Grammar:
Format (type, location), here type= "MTD" Location=partition (partition), formatting the partition represented by the location parameter. such as: Format ("MTD", "System"), formatted system partition
4. Delete
Grammar:
Delete (<path>), remove files under path path, such as delete ("/data/zipalign.log"), delete files/data/zipalign.log
5, Delete_recursive
Grammar:
Delete_recursive (<path>); Delete folder under path path, such as Delete_recursive ("/data/dalvik-cache"); Delete Folder/data/dalvik-cache
6, Show_progress
Grammar:
Show_progress (<fraction>,<duration>); This was previously introduced to show the progress bar, the progress bar will go forward according to <duration> <fraction> such as Show_progress (0.1, ten); show_progress the following operation may be 10s, complete the progress bar forward 0.1 (that is, 10%)
7, Package_extract_dir
Grammar:
Package_extract_dir (Package_path, Destination_path); Release folder Package_path to Destination_path such as: Package_extract_dir (" System ","/system "); free all files and subfolders under the System folder in the ROM package to/system
8, Package_extract_file
Grammar:
Package_extract_file (Package_path, destination_path); This means extracting package_path files to Destination_path, such as Package_extract_dir ("My.zip", "/system"); Unzip the My.zip file in the ROM package to/system
9, Symlink
Grammar:
Symlink (&LT;TARGET&GT;, <src1>, <src2>,...); Indicates the establishment of a pointer to the target symbolic link src1,src2, ... such as Symlink ("toolbox", "/system/bin/ps"); Establish symbolic links to Toolbox/system/bin/ps
10, Set_perm
Grammar:
Set_perm (&LT;UID&GT;, <gid>,<mode>, <path>); set permissions, set <path> file user uid, user group GID, permission mode ; such as: Set_perm (1002, 1002, 0440, "/system/etc/dbus.conf"); settings file/system/etc/ The owner of the dbus.conf is 1002, the owning user group is 1002, the permissions are: The owner has read permissions, the owning user group has Read permissions, and no other permissions.
11, Set_perm_recursive
Grammar:
Set_perm_recursive (<uid>,<gid>,<dir-mode>,<file-mode>,<path>); Indicates permission to set files within folders and folders such as: set_perm_recursive (+, 0771, 0644, "/data/app"), setting the owner of the/data/app and the permissions of the owning user group to the 1000,app folder are: The owner and the owning group have full permissions. The other has execute permission, the file permission under the App folder is: The owner has read and write permission, the owning group has the reading permission, the other has Read permission.
12, Ui_print
Grammar:
Ui_print ("str"); This refers to the screen printout "str", such as: Ui_print ("It's ready!"); Screen printing it ' s ready!
13, Run_program
Grammar:
Run_program (<path>); means run <path> script. such as: Run_program ("/sbin/busybox", "Mount", "/system");
14, Write_raw_image
Grammar:
Write_raw_image (&LT;PATH&GT;, partition); write <path> to partition partition: Write_raw_image ("/tmp/boot.img", "boot") Writes the boot package in YAFFS2 format directly to the boot partition
15. Assert
Grammar:
ASSERT (<sub1>,<sub2>,<sub3>), where execution sub1 does not return an error, executes SUB2 if SUB2 does not return an error, executes SUB3, and so on, such as: Assert (Package_ Extract_file ("Boot.img", "/tmp/boot.img"),
Write_raw_image ("/tmp/boot.img", "boot"),
Delete ("/tmp/boot.img")), execute Package_extract_file, execute write_raw_image If no error is returned, execute delete[1 if write_raw_image is not faulted]

Android OTA upgrade Package production script in detail (iv, Generate upgrade script updater-script)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.