Android OTA Upgrade Package Production script detailed (one, parameter resolution)

Source: Internet
Author: User

Write in front:

"Build/tools/releasetools/ota_from_target_files-u lk.bin-n target.zip Update.zip" This is the order to make the whole package, it is clear that the LK upgrade is supported here. This series of posts mainly on the execution of the command process and the principle of a systematic analysis, involving/build/tools/releasetools/directory under a number of modules such as ota_from_target_files, common and so on. Because I understand the superficial python, the text involved in the Python syntax is mostly commented, in order to help some students interested in Python can read the corresponding statements.

The whole process looks a little cumbersome jumbled, hope that interested students can be patient to see, has been more familiar with the Python grammar of the students can select the part of interest as a reference.

One, execute the script

So first, we can see from the command that the whole package production process starts with the Ota_from_target_files module. The first way to execute the Ota_from_target_files module is to start with the following statement, as follows:

#__name__作为模块的内置属性, refers to the way the. py file is invoked;. py files are used in two ways: as modules are called and used directly. If it equals "__main__" it means direct execution. That is, if __name__ = = "__main__": After the statement is called as the module is not executed, directly using the code after the statement execution. And here it is obviously directly used.

if __name__ = = ' __main__ ':  try:    common. Closeinheritedpipes () "" "Mac system is a description file (PIPE), here to close the FDS before the beginning; Here are some adjustments based on the operating system currently in use" ""    Main (sys.argv[1:]) "" " This is the main method of compiling the script "" "  except common. Externalerror, E:    print    print "   ERROR:%s"% (e,)    print    sys.exit (1)
Here is the entry function for the script main (ARG)

def main (argv): "" Sets the user-defined Option into the OPTIONS variable. The options is a Python Class, which we understand as a C struct or a Java wrapper "" "Def Option_handler (O, a): If O in ("-B ","--board_config "): #  In is a Boolean operator that tests whether the left operand is contained in the right Ganso, which is used to determine whether the value passed in by the parameter o is contained in ("-B", "--board_config"), pass # deprecated elif O in ("-K",  "--package_key"): Options.package_key = a elif o in ("-I", "--incremental_from"): Options.incremental_source      = a elif o in ("-w", "--wipe_user_data"): Options.wipe_user_data = True elif o in ("-N", "--no_prereq"): Options.omit_prereq = True elif o in ("-E", "--extra_script"): Options.extra_script = a elif o in ("-a", "--ASL R_mode "): If A in (' On '," on "," true "," true "," yes "," yes "): Options.aslr_mode = True Else:optio Ns.aslr_mode = False elif o in ("--worker_threads"): Options.worker_threads = Int. (a) Elif O in ("2", "--two_st EP "): Options.two_step = True elif o in ("-R ","--preloader "): Options.preloader = a    Elif O in ("-L", "--logo"): Options.logo = a elif o in ("-U", "--uboot"): Options.uboot = a elif o in  ("-D", "--DSP"): OPTIONS.DSP = a elif o in ("-F", "--special_factory_reset"): Options.special_factory_reset = True elif o in ("-G", "--ubifs"): options.ubifs = True elif o in ("-T", "--tee"): Options.tee = A E Lif o in ("-Z", "--trustonic"): Options.trustonic = a else:return False return True

Second, parsing parameters

  #解析参数 args = common.                             Parseoptions (argv, __doc__, extra_opts= "B:k:i:d:wfgne:r:l:u:t:z:d:a:s:2",                                              extra_long_opts=["board_config=", "package_key=",                                              "Incremental_from=", "Wipe_user_data",                                              "Special_factory_reset", "Ubifs",                                              "No_prereq", "extra_script=",                                              "Preloader=", "logo=",                                              "Uboot=", "tee=",                                              "Trustonic=", "dsp=", "Worker_threads= "," aslr_mode= ", "Two_step",], Extra_option_handler=option_handle R
The above parsing parameters are actually encapsulated in the common.py module, here we explain to Extra_option_handler=option_handler simply, in Python, functions can be copied directly to a variable, option _handler is a method defined above, and here is not executed, but is directly assigned to the Extra_option_handler, and we need to note that the assignment does not execute the contents of Option_handler, but will be executed when the actual call. So since a variable can point to a function, a function can receive another function as a parameter.

So let's take a look at the process of function parsing, first the code:

#在python中, the Getopt module is specifically designed to handle command-line arguments, where args is a list of parameters that do not have "-" or "--", in the form of [' Target.zip ', ' update.zip '], and opts is a list containing the ancestors, Each meta-ancestor is parsed out of the format information, such as [('-U ', ' Lk.bin '), ('-N ', ' "), ('-I ', ' base.zip ')], and if you want to understand getopt specific logic refer to the use of getopt in this blog post python.

#解析参数def parseoptions (argv, docstring, extra_opts= "", extra_long_opts= (),  Extra_option_handler=none): "" "Parse the options in argv and return any arguments that aren ' t flags.  DocString is the calling module's docstring, to being displayed for errors and-h. Extra_opts and extra_long_opts is for flags defined by the caller, which is processed by passing them to Extra_option_  Handler. "" " try:opts, args = getopt.getopt (argv, "hvp:s:x:" + extra_opts, ["Help", "verbose", "path=", "Signapk_pat  H= "," extra_signapk_args= "," java_path= "," public_key_suffix= "," private_key_suffix= "," device_specific= ", "Extra="] + list (extra_long_opts)) #那么我们可以在这里添加log来查看opts, args value print ("Begin") for I in Range (Len (opts)): print ( Opts[i]) print ("************") for I in range (len (args)): print (Args[i]) print ("End") except Getopt. Getopterror, Err:usage (docstring) print "* *", str (ERR), "* *" Sys.exit (2) path_specified = False for O, a in opts:if O in ("-H", "--help"): Usage (docstring) sys.exit () Elif O in ("-V", "--verbose"): Options.verbose = True elif o in ("-P", "--path"): Options.search_path = a elif o in ("--si Gnapk_path ",): Options.signapk_path = a elif o in ("--extra_signapk_args ",): Options.extra_signapk_args = SHL Ex.split (a) elif O in ("--java_path",): Options.java_path = a elif o in ("--public_key_suffix",): OPTIONS. Public_key_suffix = a elif o in ("--private_key_suffix",): Options.private_key_suffix = a elif o in ("-S", "--d      Evice_specific "): Options.device_specific = a elif o in ("-X ","--extra "): key, value = A.split (" = ", 1)  Options.extras[key] = value Else:if Extra_option_handler is None or not Extra_option_handler (O, a): Assert                        False, "unknown option \"%s\ ""% (o,) #环境变量 os.environ["PATH"] = (Os.path.join (Options.search_path, "bin") + Os.pathsep+ os.environ["PATH"]) return args 

Here is the information for the specific log print:

Begin ('-u ', ' Lk.bin ') ('-n ', ') ' ('-i ', ' base.zip ') ******target.zipupdate.zipend
After the parameter parsing is complete, the execution process continues back to the main function in Ota_from_target_files. We followed the process and looked.

The following is a filter for the length of the return value of the completion parameter resolution, which is fixed at 2, whether the whole package or differential packet is made.

  If Len (args)! = 2:    common. Usage (__doc__)    sys.exit (1)
#这里没有额外的脚本, so the value of Options.extra_script is none.
  If Options.extra_script is not None:    options.extra_script = open (Options.extra_script). Read ()
Let's take a look at the decompression process.







Android OTA Upgrade Package Production script detailed (one, parameter resolution)

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.