Android 升级包的制作

本文介绍了如何制作Android升级包,包括升级包的作用、目录结构、制作步骤和升级脚本命令。通过创建指定目录结构,准备update-binary和updater-script文件,打包并签名,最后解释了升级脚本中涉及的关键函数及其用途。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    前段时间做了一个Android 的升级包,总结一下制作升级包的过程。

    先说明下升级包的作用吧,第一,当然是可以将新的功能添加到原来的版本上; 还有就是一种算是可选配置,例如 Google 的GMS(Google Mobile Service)包,因为并不是所有的版本都带有GMS服务,所以把GMS做成升级包提供给需要的客户。

    升级的时候,把升级包放到sd卡上,按住特殊的键开机进入recovery 模式,选择从SD卡升级,选择升级包就可以了。

    先来看一下一个完整的升级包的目录结构:

    


    主要有两部分,一部分是update-binary和updater-script , 另一部分是用于更新的文件。(CERT.RSA ,CERT.SF和 MANIFEST.MF是签名是产生的文件,不用管它)

    下面来制作升级包:

    1. 准备好升级的文件,如上图所示,建一个system 目录和一个META-INF/com/google/android/目录,然后按照更新后所在的位置建立目录结构。

    2. 准备update-binary 文件,这个文件是从 bootable/recovery/updater/编译出的,编译成out/target/product/xxxxxx/system/bin/updater  文件,把此文件拷贝过来命名成update-binary. 文件名“update-binary” 是在bootable/recovery/install.c中定义的,recovery 会执行这个文件完成升级。

    3.准备updater-script 文件,这是个文本文件,文件里写的是升级的命令, update-binary 执行时会解析这个文件,执行升级的命令。文件名"updater-script" 是在 bootable/recovery/updater/updater.c 中定义的。命令的格式在bootable/recovery/updater/install.c中有定义。

    一般的升级三个命令就够了:(1) mount system to /system. (2) extract system in zipfile to /system.  (3) unmount system.  (mount 命令会根据文件系统格式的不同有所不同)。

    4.打包 :zip -r update.zip system META-INF .

    5.签名:java –jar signapk.jar -w testkey.x509.pem  testkey.pk8 update.zip  update_signed.zip

    signapk.jar  out/host/linux-x86/framework/  目录下

    testkey.x509.pem  testkey.pk8 在 build/target/product/security/ 目录下


6.你可能会遇到下面的错误:

1).“E:signatureverification failed” means your signature is not correct.
2.)“E:Error in/tmp/sideload/package.zip(Status0)” means  this is an error of recovery, not the error of the zip.
3.)“E:Error in/tmp/sideload/package.zip(Status6)” means  this is an error of your updater-script , some command can not be parse correctly.
4.)“E:Error in/tmp/sideload/package.zip(Status 7)” means some command in your updater-script  is executed incorrectly and return an error. 

    7.升级Log信息:
   The recovery log is at  “/cache/recovery/last_log”

   8. 一些参考:

------------------------------------------------------------------------------------------------------updater-script command---------------------------------------------------------------------------------------------

Function Name: mount

Function Syntax: mount(fs_type, partition_type, location, mount_point)

Parameter Details:

fs_type = "yaffs2" | "ext4"
partition_type="MTD" | "EMMC"
location = partition | device
mount_point = target folder to mount FS.

Action: Mounts a filesystem to the defined mount point

Returns: The mount point if successful, null if failed

Function Name: is_mounted

Function Syntax: is_mounted(mount_point)

Parameter Details: mount_point = string, mount point to check if is mounted

Action: Checks if a filesystem is mounted.

Returns: The mount point if mounted, otherwise, returns null

Function Name: unmount

Function Syntax: unmount(mount_point)

Parameter Details: mount_point = string, mount point to unmount

Action: Unmounts the filesystem

Returns: The mount point that was dismounted if successful, otherwise it returns null

Function Name: format

Function Syntax: format(fs_type, partition_type, location)

Parameter Details:

fs_type = string,"yaffs2" | "ext4"
partition_type= string, "MTD" | "EMMC"
location = string, partition | device

Action: Formats a filesystem as specified

Function Name: delete

Function Syntax: delete(file1, file2, ..., fileN)

Parameter Details: string, file to delete

Action: Deletes a file.  Must specify at least one file; multiple files can be specified as multiple arguments

Function Name: delete_recursive

Function Syntax: delete_recursive(dir1, dir2,...,dirN)

Parameter Details: string, directory to recursively delete

Action: Deletes a folder and all of its contents.  At least 1 directory must be specified;  multiple directories can be specified as additional arguments.

Function Name: show_progress

Function Syntax: show_progress(frac, sec)

Parameter Details:

frac = fraction of progress completed
sec = total seconds

Action: Displays flashing progress in the recovery system

Function Name: set_progress

Function Syntax: set_prograss(frac)

Parameter Details: frac=fraction of progress

Function Name: package_extract_dir

Function Syntax: package_extract_dir(package_path, destination_path)

Parameter Details:

package_path = string, directory in package to extract
destination_path = string, target point to extract files to

Action: Extract the all of the files in a directory in the package to the target specified.

Function Name: package_extract_file

Function Syntax:

package_extract_file(package_path)
or
package_extract_file(package_path, destination_path)

Parameter Details:

package_path = string, file in the package you want to extract
destination_path, target folder to extract the file to.

Action: Extracts a single file from your update package to the target specified

Function Name: file_getprop

Function Syntax: file_getprop(file, key)

Parameter Details:

file = string, filename to check
key = string, key in file to return the value of

Action: Checks for a value in a file?

Function Name: symlink

Function Syntax: symlink(target, src1, src2, ..., srcN)

Parameter Details:

target = string, the target of the symbolic link
srcX = the symbolic link to create that points to the target

Action: Unlinks any existing symbolic links before creating the new symbolic links.

Function Name: set_perm

Function Syntax: set_perm(uid, gid, mode, file1, file2, ..., fileN)

Parameter Details:

uid = user id
gid = group id
mode = permission mode
fileX = file to set permission on

Action: Sets permissions of a file or set of files specified.  At least one file must be specified (the first four parameters are required)

Function Name: set_perm_recursive

Function Syntax: set_perm_recursive(uid, gid, dirmode, filemode, dir1, dir2, ...dirN)

Parameter Details:

uid = user id
gid = group id
dirmode = permission to set to directories contained within the specified directory
filemode = permission to set to files contained within the specified directory
dirX = directory to set permission on

Action: Set permissions of a directory or set of directories and all files and folders within them.  At  least one directory must be specified (The first 5 parameters are required)

Function Name: getprop

Function Syntax: getprop(key)

Parameter Details: key = string, the property you want the system to return

Action: This function returns the value of the property specified.  This is used to query platform information from the build.props file.

Function Name: write_raw_image

Function Syntax: write_raw_image(file, partition)

Parameter Details:

file - string, the source .img file to be read from
partition - string, the destination partition to write the .img file to

Description: This function writes an img file to a partition.

Function Name: apply_patch

Function Syntax: apply_patch(srcfile, tgtfile, tgtsha1, tgtsize, sha1_1, patch_1, ..., sha1_x, patch1_x)

Parameter Details:

srcfile - string, source file to be patched (file to read in)
tgtfile - string, destination file to write the patched file to
tgtsha1 - string, sha1 hash of the target file as it should hash out after the patches apply properly
sha1_x - string, sha1 hash of the patch data that's to be written to the target file
patch1_x- string, actual patch to apply to the target file

Action: This function is used to apply patches to a file.  

Function Name: apply_patch_check

Function Syntax: apply_patch_check(file, sha1_1, ..., sha1_x)

Parameter Details:

file - string, file to check
sha1_x - hash to check for?

Action: Either checks if a file has been properly patched, or checks if a file can be patched.  Need to check the source code of the "applypatch_check" function that is called from here.

Function Name: apply_patch_space

Function Syntax: apply_patch_space(bytes)

Parameter Details: bytes = number of bytes to check for

Action: Checks the cache to verify that there is enough space to write the patched files to it and returns something.  Need to test this function to verify.

Function Name: read_file

Function Syntax: read_file(filename)

Parameter Details: filename - string, the filename to read the contents of

Action: This function returns the contents of a file.

Function Name: sha1_check

Function Syntax:

sha1_check(data)
or
sha1_check(data, sha1_hex, ..., sha1_hexN)

Parameter Details:

data - the contents of file to calculate the sha1 hash of - must be in the read_file format
sha1_hexN - A particular sha1_hex string that you want the file data to match

Action: If only data is specified, then the function returns the sha1_hex string of the data.  The optional parameters are used if you want to verify that the file you are checking for is one of a list of hashes.  It reutrns the hash it matches, or returns nothing if it doesn't match any of the mentioned hashses.

Function Name: ui_print

Function Syntax: ui_print(msg1, ..., msgN)

Parameter Details: msg - String, message to be outputted to the user during the patch process

Action: This function prints/echos a message to the console while the script is running.  At least 1 parameter needs to be specified, you can specify additional msg parameters and they will be concatenated to the output.

Function Name: run_program

Function Syntax: run_program(prog, arg1, .., argN)

Parameter Details:

prog - string, program to execute
argN - string, arguments for the program that is being executed
Description: Executes a program with the arguments specified.   Returns a string, I assume it is the buffer of the stdout of the program executed, need to test.

Function Name: ifelse

Function Syntax: ifelse(condition, truecondition, falsecondition)

Parameter Details:

condition - an expression to evaluate
truecondition - Edify script block to execute if true
falsecodnition - Edify script block to execute if false

Description: This is the if-then construct of the Edify scripting language.  The truecondition or falsecondition arguments can be a single edify command or a script block.  Script blocks can be formed by enclosing the parameter with parenthesis, and seperating the commands with semicolons\

Function Name: abort

Function Syntax: abort()

Parameter Details: no paremeters

Description: Aborts script execution.

Function Name: assert

Function Syntax: assert(condition)

Parameter Details: condition - boolean

Description: If condition evaluates to false, stops script execution, otherwise continues processing.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值