OPTIONS.info_dict的tool_extensions取值过程分析

1 首先在build/core/envsetup.mk中有:

board_config_mk := \
     $(strip $(wildcard \
         $(SRC_TARGET_DIR) /board/ $(TARGET_DEVICE) /BoardConfig .mk \
         $(shell  test  -d device &&  find  device -maxdepth 4 -path  '*/$(TARGET_DEVICE)/BoardConfig.mk' ) \
         $(shell  test  -d vendor &&  find  vendor -maxdepth 4 -path  '*/$(TARGET_DEVICE)/BoardConfig.mk' ) \
     ))
SRC_TARGET_DIR值为$(TOPDIR)build/target,TARGET_DEVICE取值xxx(机型名)

在build/target/xxx 和device、vendor等目录的xxx子目录下查找所有的BoardConfig.mk文件,而且device和vendor下必须符合xxx/BoardConfig.mk的形式,

对于xxx,只在****/xxx/下存在名为xxx的子目录,因此最终board_config_mk就代表这个文件

对board_config_mk取值的错误情况做出判断后,然后直接通过 include $(board_config_mk)将这个BoardConfig.mk文件include进来,假设这个文件中定义了 TARGET_RELEASETOOLS_EXTENSIONS := device/***/xxx

 

2  根据在 ota升级包编译过程中firmware如何添加进来 中的分析可知,BUILT_TARGET_FILES_PACKAGE是编译target-file.zip的目标

在build/core/Makefile中有

ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
# default to common dir for device vendor
$(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_DEVICE_DIR)/.. /common
else
$(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
endif

 因此编译target-file.zip的过程中,如果之前在BoardConfig.mk中定义了TARGET_RELEASETOOLS_EXTENSIONS为device/****/xxx那么tool_extensions就取值device/****/xxx,如果之前没有定义TARGET_RELEASETOOLS_EXTENSIONS,那么这个值就是device/****/xxx/../common

 

3  在build/core/Makefile接下来,在构建target BUILT_TARGET_FILES_PACKAGE下面要执行的命令行中,还有:

build/core/Makefile
1712
$(hide)  echo  "tool_extensions=$(tool_extensions)"  >> $(zip_root) /META/misc_info .txt

根据在 ota升级包编译过程中firmware如何添加进来 中的分析,zip_root就是用来产生target-files.zip的中间文件夹,在这里取值就是out/target/product/xxx/obj/PACKAGING/target_files_intermediates/xxx-target_files-eng.username

因此这里向文件out/target/product/xxx/obj/PACKAGING/target_files_intermediates/mido-target_files-eng.username/META/misc_info.txt中输入了 tool_extensions=$(tool_extensions)这一行,$(tool_extensions)代表tool_extensions的值

 

4 在之后执行build/tools/releasetools/ota_from_target_files.py时,在main中有:

build/tools/releasetools/ota_from_target_files.py
1764
1765
1766
OPTIONS.input_tmp, input_zip  =  common.UnzipTemp(args[ 0 ])
OPTIONS.target_tmp  =  OPTIONS.input_tmp
OPTIONS.info_dict  =  common.LoadInfoDict(input_zip)

根据在 ota升级包编译过程中firmware如何添加进来 中的分析,input_zip代表用zipfile.ZipFile打开的target-files.zip文件。

这里调用同目录下common.py中的LoadInfoDict,按行加载misc_info.txt中保存的元数据

build/tools/releasetools/common.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def  LoadInfoDict(input_file):
   """Read and parse the META/misc_info.txt key/value pairs from the
   input target files and return a dict."""
   def  read_helper(fn):
     if  isinstance (input_file, zipfile.ZipFile):
       return  input_file.read(fn)
     else :
       path  =  os.path.join(input_file,  * fn.split( "/" ))
       try :
         with  open (path) as f:
           return  f.read()
       except  IOError as e:
         if  e.errno  = =  errno.ENOENT:
           raise  KeyError(fn)
   =  {}
   try :
     =  LoadDictionaryFromLines(read_helper( "META/misc_info.txt" ).split( "\n" ))
   except  KeyError:
     # ok if misc_info.txt doesn't exist
     pass
   # backwards compatibility: These values used to be in their own
   # files.  Look for them, in case we're processing an old
   # target_files zip.
   if  "mkyaffs2_extra_flags"  not  in  d:
     try :
       d[ "mkyaffs2_extra_flags" =  read_helper(
           "META/mkyaffs2-extra-flags.txt" ).strip()
     except  KeyError:
       # ok if flags don't exist
       pass
   if  "recovery_api_version"  not  in  d:
     try :
       d[ "recovery_api_version" =  read_helper(
           "META/recovery-api-version.txt" ).strip()
     except  KeyError:
       raise  ValueError( "can't find recovery API version in input target-files" )
   if  "tool_extensions"  not  in  d:
     try :
       d[ "tool_extensions" =  read_helper( "META/tool-extensions.txt" ).strip()
     except  KeyError:
       # ok if extensions don't exist
       pass
   if  "fstab_version"  not  in  d:
     d[ "fstab_version" =  "1"
   try :
     data  =  read_helper( "META/imagesizes.txt" )
     for  line  in  data.split( "\n" ):
       if  not  line:
         continue
       name, value  =  line.split( " " 1 )
       if  not  value:
         continue
       if  name  = =  "blocksize" :
         d[name]  =  value
       else :
         d[name  +  "_size" =  value
   except  KeyError:
     pass
   def  makeint(key):
     if  key  in  d:
       d[key]  =  int (d[key],  0 )
   makeint( "recovery_api_version" )
   makeint( "blocksize" )
   makeint( "system_size" )
   makeint( "vendor_size" )
   makeint( "userdata_size" )
   makeint( "cache_size" )
   makeint( "recovery_size" )
   makeint( "boot_size" )
   makeint( "fstab_version" )
   d[ "fstab" =  LoadRecoveryFSTab(read_helper, d[ "fstab_version" ])
   d[ "build.prop" =  LoadBuildProp(read_helper)
   return  d

在LoadInfoDict中建立字典d,read_helper("META/misc_info.txt")会读取target-files.zip的META下的misc_info.txt,然后在LoadDictionaryFromLines中按key/value对的形式逐行解析读取到的内容,因此在这里就可以获得d["tool_extensions"] = device/****/xxx 或者 device/****/xxx/../common

如果misc_info.txt中读取tool_extensions失败,接下来还会尝试从META/tool-extensions.txt中读取。最后返回ota_from_target_files.py的main,将字典d传给OPTIONS.info_dict

 

5  在ota_from_target_files.py的main中,接下来有:

build/tools/releasetools/ota_from_target_files.py
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
if  OPTIONS.device_specific  is  None :
   from_input  =  os.path.join(OPTIONS.input_tmp,  "META" "releasetools.py" )
   if  os.path.exists(from_input):
     print  "(using device-specific extensions from target_files)"
     print  "releasetools.py exists"
     print (from_input)
     OPTIONS.device_specific  =  from_input
   else :
     print  "releasetools.py don't exists"
     # device/qcom/common
     OPTIONS.device_specific  =  OPTIONS.info_dict.get( "tool_extensions" None )
if  OPTIONS.device_specific  is  not  None :
   OPTIONS.device_specific  =  os.path.abspath(OPTIONS.device_specific)

这里首先从产生target-files.zip的中间文件夹是out/target/product/xxx/obj/PACKAGING/target_files_intermediates/xxx-target_files-eng.username/META下读取releasetools.py,如果这个文件不存在,就从上一部获得的字典 OPTIONS.info_dict中查找tool_extensions这个键的值,最终赋值给OPTIONS.device_specific。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值