Android Updater-scripts (edify script) function details

Source: Internet
Author: User
Tags sha1 hash symlink

This is a basic introduction to the edify language used by Android to run Updater-scripts.

Most edify names are functions. When these functions are called, data is returned to the script. Of course, you can also use these functionsReturn ValueFor example:

Ifelse (Mount ("yaffs2", "MTD", "system", "/system") = "system", ui_print ("successfully mounted! "), Ui_print (" Mount failed! ");

This command will try to mount the "MTD" partition named "system" to "/system ". If the mounting is successful, the script displays "successfully mounted !", Otherwise, "Mount failed!" is displayed !".

The following is an example of a function used in Updater-script of edify:

Function Name: Mount

Function syntax: Mount (fs_type, partition_type, location, mount_point)

Parameter Details: Fs_type ----------------- "yaffs2"Or"Ext4"

Partition_type ---------- "MTD"Or"Emmc"

Location ----------------- Partition)OrDevice)

Mount_poin ------------ target folder for mounting the File System (target folder to mount FS)

Description: Mount a file system to a specified mount point

Return Value: If the mounting succeeds, the mount point is returned. If the mounting fails, null is returned.

Function example: Mount ("MTD", "system", "/system"); mount the system partition and set the return Pointer "/System"

Mount ("vfat", "/dev/block/mmcblk1p2", "/system"); mount/dev/block/mmcblk1p2, return Pointer "/System"

Function Name: is_mounted

Function syntax: Is_mounted (mount_point)

Parameter Details: Mount_point ----------- string, check whether the mount point has been mounted

Description: Check whether the file system is mounted.

Return Value: If the mounting succeeds, the mount point is returned. If the mounting fails, null is returned.

Function example:

Function Name: unmount

Function syntax: Unmount (mount_point)

Parameter Details: Mount_point ----------- string. The mount point to be unmounted.

Description: Unmount the File System

Return Value: If the mounting is successfully removed, the mount point is returned. If the mounting fails, null is returned.

Function example: Unmount ("/system"); unmount/system partition

Function Name: Format

Function syntax: Format (fs_type, partition_type, location)

Parameter Details: Fs_type ----------------- string, data is "yaffs2" or "ext4"

Partition_type ---------- string, "MTD"Or"Emmc"

Location ----------------- string, partition)OrDevice)

Description: Format to the specified file system

Function example: Format ("MTD", "system"); format the system partition

Function Name: Delete

Function syntax: Delete (file1, file2,..., filen)

Parameter Details: String, the object to be deleted

Description: Delete an object. Specify at least one file. Multiple files can be specified as multiple parameters.

Function example: Delete ("/data/zipalign. log"); delete the file/data/zipalign. Log

Function Name: delete_recursive

Function syntax: Delete_recursive (dir1, dir2,..., dirn)

Parameter Details: String, the directory to be recursively deleted

Description: Delete a folder and all its contents. Specify at least one directory. multiple directories can be specified as multiple parameters.

Function example: Delete_recursive ("/data/Dalvik-Cache"); delete folders/data/Dalvik-Cache

Function Name: show_progress

Function syntax: Show_progress (frac, Sec)

Parameter Details: Frac ---------------------- progress completion value

SEC ---------------------- total number of seconds

Description: Display progress in the Recovery System

Function example: Show_progress (0.1, 10); operations under show_progress may be performed for 10 s. After completion, the progress bar advances to 0.1 (that is, 10%)

Function Name: set_progress

Function syntax: Set_prograss (frac)

Parameter Details: Frac --------------------- progress Value

Function example:

Function Name: package_extract_dir

Function syntax: Package_extract_dir (package_path, destination_path)

Parameter Details: Package_path ---------- string, directory to be extracted from the upgrade package

Destination_path -------- string to extract the target directory of the file

Description: Extract all files in the directory of the upgrade package to the specified target directory.

Function example: Package_extract_dir ("system", "/system"); release all files and subfolders in the system folder of the RoM package to/System

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 to be extracted from the upgrade package

Destination_path ------- string to extract the target directory of the file

Description: Extract a single file from the update package to the specified target directory.

Function example: Package_extract_file ("my.zip", "/system" decompress the my.zip file in the ROM package to/System

Function Name: file_getprop

Function syntax: File_getprop (file, key)

Parameter Details: File ---------------------- string, file name to be checked

Key ---------------------- string, return the key name of the file in the data

Description: Get the file property value in the format of "key" = "value"

Function example:

Function Name: symlink

Function syntax: Symlink (target, src1, src2,..., srcn)

Parameter Details: Target ------------------- string, the target of the symbolic link

Srcx --------------------- string, the target point of the symbolic link to be created

Description: Disconnect an existing symbolic link before creating a new symbolic link.

Function example: Symlink ("toolbox", "/system/bin/PS"); creates a symbolic link to the Toolbox/system/bin/PS

Function Name: set_perm

Function syntax: Set_perm (UID, GID, mode, file1, file2,..., filen)

Parameter Details: Uid ---------------------- user ID)

GID ---------------------- user group ID (group ID)

Mode -------------------- permission Mode)

Filex ----------------------- file to set permission on)

Description: Set permissions for a single file or a series of files. specify at least one file. The first four parameters are required.

Function example: Set_perm (0,2000, 0550, "system/etc/init. goldfish. sh "); set the ETC/init. goldfish. the user of SH is root, the user group is shell, and the owner and user group members can read and execute operations. Other users have no operation permissions)

Here, 0 indicates that the user is root.
2000 indicates that the user group is shell.
Let's describe the 0550 data set. The last three digits of the data set are 550, which represent the permissions of "Owner \ group user \ other users, that is, we have three lines in "user \ group \ others" In re management. We use XXX to indicate the permissions of these three groups, where:
× = 4 read permission
× = 2 Write Permission
× = 1 execution permission
First, we must understand the meaning of the property represented by numbers: 0 indicates no permission, 1 indicates executable permission, 2 indicates writable permission, 4 indicates readable permission, and then add it. Therefore, the format of the numeric attribute should be three Octal numbers from 0 to 7.
For example, if you want the owner of a file to have the "read/write" permissions, you need to set 4 (readable) + 2 (writable) to 6 (read/write ). If the rwx attribute is required, 4 + 2 + 1 = 7; if the RW-attribute is required, 4 + 2 = 6; if the R-x attribute is required, 4 + 1 = 5.
Commands for modifying permissions:
Set_perm 0 0 0600 ××× (only the owner has read and write permissions)
Set_perm 0 0 0644 ××× (the owner has the read and write permissions, and the group user only has the read permission)
Set_perm 0 0 0700 ××× (only the owner has read, write, and execute permissions)
Set_perm 0 0 0666 ××× (everyone has read and write permissions)
Set_perm 0 0 0777 ××× (everyone has the permission to read, write, and execute)

Function Name: set_perm_recursive

Function syntax: Set_perm_recursive (UID, GID, dirmode, filemode, dir1, dir2,... dirn)

Parameter Details: Uid ---------------------- user ID)

GID ---------------------- user group ID (group ID)

Dirmode ---------------- specify the directory permission

Filemode --------------- specify the permissions of files in the directory

Dirx ----------------------- target of the permission

Description: Set permissions for all files in a single directory or a series of directories. At least one directory is specified, and five parameters are required.

Function example: Set_perm_recursive 0 0 0755 0644 system: app; set the user in the system/APP folder of the mobile phone and the file to root and the user group to root, the app folder permission allows the owner to read, write, and execute operations. Other users can read and execute operations. The object permission allows the owner to perform read and write operations, other users can perform read Operations

Function Name: getprop

Function syntax: Getprop (key)

Parameter Details: Key --------------------- string, which indicates the attribute to be returned by the system.

Description: This function is used to return the value of the specified attribute. It is used to query the mobile phone information from the build. Props file.

Function example:

Function Name: write_raw_image

Function syntax: Write_raw_image (file, partition)

Parameter Details: File ---------------------- string, IMG source file to be read

Partition ----------------- string, destination partition of the imgfile to be written

Description: This function is used to write imgfiles to partitions.

Function example: Write_raw_image ("/tmp/boot. IMG", "Boot") writes the boot package in the yaffs2 format to the boot partition directly.

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 be read)

Tgtfile ------------------- string, the target file to be written into the patch file

Tgtsha1 ----------------- string, sha1 hash value of the target file written to the patch file

Sha1_x ------------------ string, sha1 hash value of the patch data to be written to the target file

Patch1_x ---------------- string, patch actually applied to the target file

Description: This function is used to patch files.

Function example:

Function Name: apply_patch_check

Function syntax: Apply_patch_check (file, sha1_1,..., sha1_x)

Parameter Details: File ---------------------- string, the file to be checked

Sha1_x ------------------ hash value to be checked

Description: Check whether the file has been patched or not. Check the source code of the "applypatch_check" function call.

Function example:

Function Name: apply_patch_space

Function syntax: Apply_patch_space (bytes)

Parameter Details: Bytes ------------------- check the byte number

Description: Check the cache to determine whether there is sufficient space to write the patch file and return some data.

Function example:

Function Name: read_file

Function syntax: Read_file (filename)

Parameter Details: Filename ---------------- string, file name of the content to be read

Description: This function returns the File Content

Function example:

Function Name: shaexterncheck

Function syntax: Sha1_check (data)OrShaexterncheck (data, shaexternhex,..., shaexternhexn)

Parameter Details: Data --------------------- content of the file to calculate the sha1 hash value-must be in the read-only file format

Shaw.hexn -------------- the specific hexadecimal sha1_hex hash string to be matched for file data

Description: If only the data parameter is specified, this function returns the hexadecimal sha1_hex hash string of the Data parameter. Other parameters are used to check whether the file you are checking is a hash value in the list. It returns a matched hash value, or returns NULL if it does not match any hash value.

Function example:

Function Name: ui_print

Function syntax: Ui_print (msg1,..., msgn)

Parameter Details: MSG ---------------------- string, the information output to the user during processing

Description: Information displayed on the console when the script is running. You must specify at least one parameter. You can specify additional MSG parameters and they will be connected and lost.

Function example: Ui_print ("It's ready! "); Screen print it's ready!

Function Name: run_program

Function syntax: Run_program (prog, arg1,..., argn)

Parameter Details: Prog -------------------- string, the program to be executed

Argn -------------------- string, the running parameters of the program to be executed

Description: Execute the program with the specified parameter

Function example: Run_program ("/system/xbin/installbusybox. Sh"); run the installbusybox. Sh script file.

Function Name: ifelse

Function syntax: Ifelse (condition, truecondition, falsecondition)

Parameter Details: Condition ---------------- expression to be computed

Truecondition ----------- edify script block executed when the value is true

Falsecodnition ----------- edify script block executed when the value is false

Description: This is the edify script language of the if-then structure. The statement can be a single edify command or script block under true or non-conditions. The script block can be defined by parentheses and separated by semicolons.

Function example:

Function Name: Abort

Function syntax: Abort ()

Parameter Details: No Parameters

Description: Abort Script Execution

Function example:

Function Name: assert

Function syntax: Assert (condition)

Parameter Details: Condition --------------- Boolean

Description: If the calculated result of the condition parameter is false, stop the script execution. Otherwise, continue the script execution.

Function example: Assert (package_extract_file ("boot. IMG ","/tmp/boot. IMG "), write_raw_image ("/tmp/boot. IMG "," Boot "), delete ("/tmp/boot. IMG "))

Run package_extract_file. If no error is returned, run write_raw_image. If no error is returned, run Delete.

Related Article

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.