首页 > 其他分享 >Android官方资料--Inside OTA Packages

Android官方资料--Inside OTA Packages

时间:2023-09-06 14:07:16浏览次数:66  
标签:... -- OTA Inside partition filename file expr size


Inside OTA Packages


IN THIS DOCUMENT

  1. Edify syntax
  2. Built-in functions


The system builds the updater binary frombootable/recovery/updater and uses it in an OTA package. The package itself is a .zip file (

ota_update.zip,

incremental_ota_update.zip) that contains the executable binary

META-INF/com/google/android/update-binary .

Updater contains several builtin functions and an interpreter for an extensible scripting language (edify) that supports commands for typical update-related tasks. Updater looks in the package .zip file for a script in the fileMETA-INF/com/google/android/updater-script.

Note: Using the edify script and/or builtin functions is not a common activity, but can be helpful if you need to debug the update file.

Edify syntax


An edify script is a single expression in which all values are strings. Empty strings are false in a Boolean context and all other strings are true. Edify supports the following operators (with the usual meanings):

(expr )
 expr + expr  # string concatenation, not integer addition
 expr == expr
 expr != expr
 expr && expr
 expr || expr
 ! expr
 if expr then expr endif
 if expr then expr else expr endif
 function_name(expr, expr,...)
 expr; expr

Any string of the characters a-z, A-Z, 0-9, _, :, /, . that isn't a reserved word is considered a string literal. (Reserved words are if else then endif.) String literals may also appear in double-quotes; this is how to create values with whitespace and other characters not in the above set. \n, \t, \", and \\ serve as escapes within quoted strings, as does \x##.

The && and || operators are short-circuiting; the right side is not evaluated if the logical result is determined by the left side. The following are equivalent:



e1 && e2 if e1 then e2 endif



The ; operator is a sequence point; it means to evaluate first the left side and then the right side. Its value is the value of the right-side expression. A semicolon can also appear after an expression, so the effect simulates C-style statements:

prepare();
do_other_thing("argument");
finish_up();

Built-in functions


Most update functionality is contained in the functions available for execution by scripts. (Strictly speaking these are macros rather than functions in the Lisp sense, since they need not evaluate all of their arguments.) Unless otherwise noted, functions return true on success and false on error. If you want errors to abort execution of the script, use the abort() and/or assert() functions. The set of functions available in updater can also be extended to provide device-specific functionality.

abort([msg])

Aborts execution of the script immediately, with the optional  msg. If the user has turned on text display,

msg appears in the recovery log and on-screen.

assert(expr[, expr, ...])

Evaluates each  expr in turn. If any is false, immediately aborts execution with the message "assert failed" and the source text of the failed expression.

apply_patch(src_filetgt_filetgt_sha1tgt_sizepatch1_sha1patch1_blob, [...])

Applies a binary patch to the  src_file to produce the 

tgt_file . If the desired target is the same as the source, pass "-" for 

tgt_file 

tgt_sha1 and 

tgt_size are the expected final SHA1 hash and size of the target file. The remaining arguments must come in pairs: a SHA1 hash (a 40-character hex string) and a blob. The blob is the patch to be applied when the source file's current contents have the given SHA1.


The patching is done in a safe manner that guarantees the target file either has the desired SHA1 hash and size, or it is untouched—it will not be left in an unrecoverable intermediate state. If the process is interrupted during patching, the target file may be in an intermediate state; a copy exists in the cache partition so restarting the update can successfully update the file.

Special syntax is supported to treat the contents of Memory Technology Device (MTD) partitions as files, allowing patching of raw partitions such as boot. To read an MTD partition, you must know how much data you want to read since the partition does not have an end-of-file notion. You can use the string "MTD:partition:size_1:sha1_1:size_2: sha1_2" as a filename to read the given partition. You must specify at least one (size, sha-1) pair; you can specify more than one if there are multiple possibilities for what you expect to read.


apply_patch_check(filenamesha1[, sha1, ...])

Returns true if the contents of  filename or the temporary copy in the cache partition (if present) have a SHA1 checksum equal to one of the given 

sha1 values. 

sha1 values are specified as 40 hex digits. This function differs from 

sha1_check(read_file(filename), sha1 [, ...]) in that it knows to check the cache partition copy, so 

apply_patch_check() will succeed even if the file was corrupted by an interrupted 

apply_patch() update.

apply_patch_space(bytes)

Returns true if at least  bytes of scratch space is available for applying binary patches.

concat(expr[, expr, ...])

Evaluates each expression and concatenates them. The + operator is syntactic sugar for this function in the special case of two arguments (but the function form can take any number of expressions). The expressions must be strings; it can't concatenate blobs. delete([filename, ...])

Deletes all the  filenames listed. Returns the number of files successfully deleted.

delete_recursive([dirname, ...])

Recursively deletes  dirnames and all their contents. Returns the number of directories successfully deleted.

file_getprop(filenamekey)

Reads the given  filename, interprets it as a properties file (e.g. 

/system/build.prop), and returns the value of the given 

key , or the empty string if 

key is not present.

format(fs_typepartition_typelocationfs_sizemount_point)


  • fs_type="yaffs2" and partition_type="MTD". Location must be the name of the MTD partition; an empty yaffs2 filesystem is constructed there. Remaining arguments are unused.
  • fs_type="ext4" and partition_type="EMMC". Location must be the device file for the partition. An empty ext4 filesystem is constructed there. If fs_size is zero, the filesystem takes up the entire partition. If fs_size is a positive number, the filesystem takes the first fs_size bytes of the partition. If fs_size is a negative number, the filesystem takes all except the last |fs_size| bytes of the partition.
  • fs_type="f2fs" and partition_type="EMMC". Location must be the device file for the partition. fs_size must be a non-negative number. If fs_size is zero, the filesystem takes up the entire partition. If fs_size is a positive number, the filesystem takes the first fs_size bytes of the partition.
  • mount_point should be the future mount point for the filesystem.


getprop(key)

Returns the value of system property  key (or the empty string, if it's not defined). The system property values defined by the recovery partition are not necessarily the same as those of the main system. This function returns the value in recovery.

greater_than_int(ab)

Returns true if and only if (iff)  a (interpreted as an integer) is greater than 

b (interpreted as an integer).

ifelse(conde1[, e2])

Evaluates  cond, and if it is true evaluates and returns the value of 

e1, otherwise it evaluates and returns 

e2(if present). The "if ... else ... then ... endif" construct is just syntactic sugar for this function.

is_mounted(mount_point)

Returns true iff there is a filesystem mounted at  mount_point.

is_substring(needlehaystack)

Returns true iff  needle is a substring of 

haystack.

less_than_int(ab)

Returns true iff  a (interpreted as an integer) is less than 

b (interpreted as an integer).

mount(fs_typepartition_typenamemount_point)

Mounts a filesystem of  fs_type at 

mount_point

partition_type must be one of:


  • MTD. Name is the name of an MTD partition (e.g., system, userdata; see 

/proc/mtd

  • EMMC.

Recovery does not mount any filesystems by default (except the SD card if the user is doing a manual install of a package from the SD card); your script must mount any partitions it needs to modify.


package_extract_dir(package_dirdest_dir)

Extracts all files from the package underneath  package_dir and writes them to the corresponding tree beneath 

dest_dir. Any existing files are overwritten.

package_extract_file(package_file[, dest_file])

Extracts a single  package_file from the update package and writes it to 

dest_file, overwriting existing files if necessary. Without the 

dest_file argument, returns the contents of the package file as a binary blob.

read_file(filename)

Reads  filename and returns its contents as a binary blob.

rename(src_filenametgt_filename)

Renames  src_filename to 

tgt_filename. It automatically creates the necessary directories for the

tgt_filename. Example: 

rename("system/app/Hangouts/Hangouts.apk", "system/priv-app/Hangouts/Hangouts.apk").

run_program(path[, arg, ...])

Executes the binary at  path, passing 

args. Returns the program's exit status.

set_metadata(filenamekey1value1[, key2 value2, ...])

Sets the keys of the given  filename to 

values. For example: 

set_metadata("/system/bin/netcfg", "uid", 0, "gid", 3003, "mode", 02750, "selabel", "u:object_r:system_file:s0", "capabilities", 0x0).

set_metadata_recursive(dirnamekey1value1[, key2value2, ...])

Recursively sets the keys of the given  dirname and all its children to 

values. For example:

set_metadata_recursive("/system", "uid", 0, "gid", 0, "fmode", 0644, "dmode", 0755, "selabel", "u:object_r:system_file:s0", "capabilities", 0x0).

set_progress(frac)

show_progress()call. 

frac must be in the range [0.0, 1.0]. The progress meter never moves backwards; attempts to make it do so are ignored.

sha1_check(blob[, sha1])

The  blob argument is a blob of the type returned by 

read_file() or the one-argument form of

package_extract_file() . With no 

sha1 arguments, this function returns the SHA1 hash of the blob (as a 40-digit hex string). With one or more 

sha1 arguments, this function returns the SHA1 hash if it equals one of the arguments, or the empty string if it does not equal any of them.

show_progress(fracsecs)

Advances the progress meter over the next  frac of its length over the 

secs seconds (must be an integer).

secs may be 0, in which case the meter is not advanced automatically but by use of the 

set_progress()function defined above.

sleep(secs)

Sleeps for  secs seconds (must be an integer).

stdout(expr[, expr, ...])

Evaluates each expression and dumps its value to stdout. Useful for debugging. symlink(target[, source, ...])

Creates all  sources as symlinks to 

target.

tune2fs(device[, arg, …])

Adjusts tunable parameters  args on 

device.

ui_print([text, ...])

Concatenates all  text arguments and prints the result to the UI (where it will be visible if the user has turned on the text display).

unmount(mount_point)

Unmounts the filesystem mounted at  mount_point.

wipe_block_device(block_devlen)

Wipes the  len bytes of the given block device 

block_dev.

wipe_cache()

Causes the cache partition to be wiped at the end of a successful installation. write_raw_image(filename_or_blobpartition)

Writes the image in  filename_or_blob to the MTD 

partition

filename_or_blob can be a string naming a local file or a blob-valued argument containing the data to write. To copy a file from the OTA package to a partition, use: 

write_raw_image(package_extract_file("zip_filename"), "partition_name");

Note: Prior to Android 4.1, only filenames were accepted, so to accomplish this the data first had to be unzipped into a temporary local file.

标签:...,--,OTA,Inside,partition,filename,file,expr,size
From: https://blog.51cto.com/u_16248677/7386102

相关文章

  • Androd 7.0编译错误合集
    1 error:ro.build.fingerprintcannotexceed91bytesbuild/tools/post_process_props.py.Changelinesasfollows:PROP_NAME_MAX=31#PROP_VALUE_MAX=91PROP_VALUE_MAX=128PROP_NAME_MAX=31#PROP_VALUE_MAX=91PROP_VALUE_MAX=128bionic/libc/include......
  • Spring源码分析(十一)ApplicationContext详细介绍(上)
    在前面的文章中,已经完成了官网关于IOC内容核心的部分。包括容器的概念,Spring创建bean的模型BeanDefinition的介绍容器的扩展点(BeanFactoryProcessor,FactoryBean,BeanPostProcessor)以及最重要的bean的生命周期等。接下来大概还有花三篇文章完成对官网中第一大节的其他内容,之所以要......
  • “指针跃动”受邀参加全球贸易服务峰会
    “指针跃动”受邀参加全球贸易服务峰会有“服”同享共赢未来引子在全球化日益盛行的今天,贸易不再仅仅是物质的交流,更涉及到服务、理念、文化和科技的共享。中国国际服务贸易交易会全球贸易服务峰会,就是这个趋势的集中体现。在这次峰会上,“指针跃动”受邀参加中国......
  • 液体颜色是否会影响光电液位传感器判断
    液体的颜色通常不会对红外水位开关的工作产生影响。红外水位开关是一种非机械式的传感器,它内置了红外发射管和接收管。红外发射管会发射出红外光,而接收管则用于接收光信号。当红外光照射到液体表面时,光会发生折射,如果液体中存在水,光会被吸收,不会反射回来。而如果液体中没有水,光会反......
  • 业务导向、架构领先,用友iuap加速数智化商业创新
    8月19日下午,由用友主办的“2023全球商业创新大会-企业数智化技术峰会”,在上海市召开。此次峰会以“升级企业数智化底座”为主题,揭秘用友BIP核心技术与平台能力,解析多维度场景下企业数智化底座升级路径,共享行业领先企业升级数智底座的领先实践。用友网络副总裁兼iuap应用平台部总经......
  • uni-app中页的刷新
    前端同学在日常搬砖中肯定会写一些下拉刷新上拉加载数据的列表,实现的方式也很多。今天我就从一个前端小白的角度去梳理一下这些上拉下拉的具体实现方式下拉刷新这个是非常简单的,在pages.json文件中,将想要开启下拉刷新页面中的enablePullDownRefresh选项改成true{"pa......
  • Android内存优化案例——不合适和高性能的写法(一)
    安卓内存优化是一个很重要的话题,有很多方面可以考虑,比如避免内存泄漏、减少内存抖动、优化图片加载、使用缓存和对象池等。下面我举一些代码案例,分别展示不合适的写法和高性能的写法。1.避免使用枚举类型。枚举类型会占用更多的内存,因为它是一个类对象,而不是一个基本类型。如果......
  • 数智合同,开启企业合同管理新征程!
    随着企业管理的不断升级,合同管理1.0时代针对合同文本、法律风险、审批流程的管理已经无法满足企业的需求。越来越多的企业经营者将企业的合同管理纳入到企业经营管理的核心范畴,合同管理已经开始进入到企业业务、法务、财务综合管理的深水区,也正步入“合同全生命周期运营(CLO)”2.0新......
  • Socks5代理IP:保障跨境电商的网络安全
    在数字化时代,跨境电商已成为全球商业的重要一环。然而,随着其发展壮大,网络安全问题也逐渐浮出水面。为了确保跨境电商的安全和隐私,Socks5代理IP技术成为了一项不可或缺的工具。本文将深入探讨Socks5代理IP在跨境电商中的应用,以及如何保障网络安全。1.了解Socks5代理IP1.1什么是Soc......
  • OPTIONS.info_dict的tool_extensions取值过程分析
    1 首先在build/core/envsetup.mk中有:board_config_mk:=\$(strip$(wildcard\$(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk\......