1#!/usr/bin/env python3 2# coding=utf-8 3 4''' 5* Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 6* Licensed under the Apache License, Version 2.0 (the "License"); 7* you may not use this file except in compliance with the License. 8* You may obtain a copy of the License at 9* 10* http://www.apache.org/licenses/LICENSE-2.0 11* 12* Unless required by applicable law or agreed to in writing, software 13* distributed under the License is distributed on an "AS IS" BASIS, 14* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15* See the License for the specific language governing permissions and 16* limitations under the License. 17* 18* Description: hupg main build scripts 19''' 20 21import os 22import time 23import sys 24import make_upg_file as MAKE_IMAGE 25from packet_create import packet_bin 26from scons_utils import scons_get_cfg_val 27import shutil 28 29root_path = os.path.join(os.getcwd(), '..', '..') if getattr(sys, 'frozen', False) else os.path.join(os.path.dirname(__file__), '..', '..') 30print('execute ota_builder with exe...') if getattr(sys, 'frozen', False) else print('execute ota_builder with python...') 31class ImageBuild: 32 def __init__(self, app_name="Hi3861_demo", sign_alg=0x3F, kernel_file_ver=0, flashboot_file_ver=0, chip_product="Hi3861", usr_realtive_output='', ota_mode=0): 33 self.__app_name = app_name 34 self.__bootBinPath = os.path.join(root_path, usr_realtive_output, 'build', 'flashboot', 'Hi3861_flash_boot.bin') 35 self.__kernelBinPath = os.path.join(root_path, usr_realtive_output, 'output', 'bin', '%s_non_rom.bin'%self.__app_name) 36 self.__normalNvPath = os.path.join(root_path, 'build', 'build_tmp', 'nv', '%s_normal.hnv'%app_name) 37 self.__factoryNvPath = os.path.join(root_path, 'build', 'build_tmp', 'nv', '%s_factory.hnv'%app_name) 38 self.__pktPath = os.path.join(root_path, usr_realtive_output, 'output', 'bin') 39 self.__key_dir_path = os.path.join(root_path, 'tools', 'sign_tool') 40 self.__lzma_tool_path = os.path.join(root_path, r'tools', r'lzma_tool', r'lzma_tool') 41 self.__build_tmp_path = os.path.join(root_path, usr_realtive_output, 'output', 'bin') 42 self.__image_id = 0x3C78961E 43 self.__kernel_file_ver = kernel_file_ver 44 self.__flashboot_file_ver = flashboot_file_ver 45 self.__encrypt_flag = 0x42 46 self.__sign_alg = sign_alg 47 self.__boot_bin_max_size = 32*1024 #32K 48 self.__kernel_1st_bin_max_size = 912*1024 #912K 49 self.__kernel_2nd_bin_max_size = 968*1024 #968K 50 self.__kernel_bin_max_size = self.__kernel_1st_bin_max_size 51 self.__kernel_upg_max_size = (912 + 968) * 1024 52 self.__factory_bin_max_size = 600*1024 #600K 53 self.__chip_product_name = chip_product 54 self.__file_attr_encrypt = 0x2 # encrypt 55 self.__kernel_file_attr_ota = 0x4 # compression ota 56 self.__flashboot_file_attr_ota = 0x4 # compression ota 57 self.__ota_mode = ota_mode #0:compression ota; 1: dual partition ota 58 59 def set_file_attr_encrypt(self, attr_encrypt): 60 self.__file_attr_encrypt = attr_encrypt 61 62 def set_kernel_file_attr_ota(self, attr_ota): 63 if attr_ota == 'A': 64 attr_ota = 1 65 elif attr_ota == 'B': 66 attr_ota = 2 67 self.__kernel_file_attr_ota = attr_ota 68 69 def set_flashboot_file_attr_ota(self, attr_ota): 70 self.__flashboot_file_attr_ota = attr_ota 71 72 def set_chip_product_name(self, name): 73 self.__chip_product_name = name 74 75 def set_kernel_max_size(self, signature): 76 if signature == 'A': 77 self.__kernel_bin_max_size = self.__kernel_1st_bin_max_size 78 elif signature == 'B': 79 self.__kernel_bin_max_size = self.__kernel_2nd_bin_max_size 80 elif signature == 0: 81 self.__kernel_bin_max_size = self.__kernel_upg_max_size 82 elif signature == 4: 83 self.__kernel_bin_max_size = self.__factory_bin_max_size 84 else: 85 sys.exit("[ERR]signature err: < %s >, from: %s"%(signature, os.path.realpath(__file__))) 86 87 def set_src_path(self, boot_bin_path = None, kernel_bin_path = None, normal_nv_path = None, factory_nv_path = None): 88 self.__bootBinPath = boot_bin_path if boot_bin_path is not None else self.__bootBinPath 89 self.__kernelBinPath = kernel_bin_path if kernel_bin_path is not None else self.__kernelBinPath 90 self.__normalNvPath = normal_nv_path if normal_nv_path is not None else self.__normalNvPath 91 self.__factoryNvPath = factory_nv_path if factory_nv_path is not None else self.__factoryNvPath 92 93 def set_pkt_path(self, pkt_dir_path): 94 self.__pktPath = pkt_dir_path 95 96 def set_build_temp_path(self, build_temp_path): 97 self.__build_tmp_path = build_temp_path 98 99 def set_app_name(self, app_name): 100 self.__app_name = app_name 101 102 def set_image_id(self, image_id): 103 self.__image_id = image_id 104 105 def set_kernel_file_ver(self, file_version): 106 self.__kernel_file_ver = file_version 107 108 def set_flashboot_file_ver(self, file_version): 109 self.__flashboot_file_ver = file_version 110 111 def get_kernel_file_ver(self): 112 return self.__kernel_file_ver 113 114 def get_flashboot_file_ver(self): 115 return self.__flashboot_file_ver 116 117 def set_encrypt_flag(self, encrypt_flag): 118 self.__encrypt_flag = encrypt_flag 119 120 def set_sign_alg(self, sign_alg): 121 self.__sign_alg = sign_alg 122 123 def dual_partion_ota_work(self, signature = None): 124 self.BuildUpgBoot() 125 #制作升级文件和烧写文件先后顺序不能调整 126 #self.set_encrypt_flag(0xFF) #顺序不能调整,需要在编译flupgbin结束后设置 127 self.BuildUpgBin() 128 self.BuildHiburnBin() 129 130 def compress_ota_work(self, signature = None): 131 app_name = self.__app_name 132 pkt_dir_path = self.__pktPath 133 ota_ori_file = os.path.join(pkt_dir_path, '%s_ota_tmp.bin'%app_name) 134 self.BuildUpgBoot() 135 #制作升级文件和烧写文件先后顺序不能调整 136 self.BuildUpgBin(target = ota_ori_file) 137 self.BuildHiburnBin(ota_file = ota_ori_file) 138 #self.set_encrypt_flag(0xFF) #顺序不能调整,需要在编译upgbin结束后设置 139 self.BuildCompressUpgBin(ota_file = ota_ori_file) 140 141 def BuildUpgBoot(self, target = None, source = None): 142 app_name = self.__app_name 143 pkt_dir_path = self.__pktPath 144 file_attr = (self.__file_attr_encrypt << 6) + self.__flashboot_file_attr_ota 145 146 #bootupg配置 147 flash_boot_file = self.__bootBinPath 148 if not os.path.exists(flash_boot_file): 149 print("flash_boot_file from: ", flash_boot_file) 150 sys.exit("[ERR]flash boot file is not exist, from: %s"%os.path.realpath(__file__)) 151 152 # 构造输出文件名 # 153 image_file = os.path.join(pkt_dir_path, '%s_flash_boot_ota.bin'%app_name) if target is None else target 154 print("********************package boot upgrade file********************") 155 MAKE_IMAGE.make_bootupg(self.__image_id, self.__flashboot_file_ver, self.__encrypt_flag, flash_boot_file, image_file, self.__key_dir_path, self.__boot_bin_max_size, self.__sign_alg, self.__chip_product_name, file_attr) 156 return image_file 157 158 def BuildUpgBin(self, target = None): 159 app_name = self.__app_name 160 pkt_dir_path = self.__pktPath 161 file_attr = (self.__file_attr_encrypt << 6) + self.__kernel_file_attr_ota 162 163 #升级文件配置 164 kernel_file = self.__kernelBinPath 165 normal_nv_file = self.__normalNvPath 166 if not os.path.exists(normal_nv_file): 167 print("normal_nv_file from: ", normal_nv_file) 168 sys.exit("[ERR]normal nv file is not exist, from: %s"%os.path.realpath(__file__)) 169 170 if not os.path.exists(kernel_file): 171 print("kernel_file from: ", kernel_file) 172 sys.exit("[ERR]kernel file is not exist, from: %s"%os.path.realpath(__file__)) 173 174 # 构造输出文件名 # 175 image_file = os.path.join(pkt_dir_path, '%s_ota.bin'%app_name) if target is None else target 176 print("********************package kernel&nv upgrade file********************") 177 MAKE_IMAGE.make_hupg(self.__image_id, self.__kernel_file_ver, self.__encrypt_flag, kernel_file, normal_nv_file, image_file, self.__key_dir_path, self.__kernel_bin_max_size, self.__sign_alg, self.__chip_product_name, file_attr) 178 return image_file 179 180 def BuildUpgBurnBin(self, target = None): 181 app_name = self.__app_name 182 pkt_dir_path = self.__build_tmp_path 183 file_attr = (self.__file_attr_encrypt << 6) + self.__kernel_file_attr_ota 184 185 #升级文件配置 186 kernel_file = self.__kernelBinPath 187 normal_nv_file = self.__normalNvPath 188 if not os.path.exists(normal_nv_file): 189 print("normal_nv_file from: ", normal_nv_file) 190 sys.exit("[ERR]normal nv file is not exist, from: %s"%os.path.realpath(__file__)) 191 192 if not os.path.exists(kernel_file): 193 print("kernel_file from: ", kernel_file) 194 sys.exit("[ERR]kernel file is not exist, from: %s"%os.path.realpath(__file__)) 195 196 # 构造输出文件名 # 197 image_file = os.path.join(pkt_dir_path, '%s_ota_unencrypt.bin'%app_name) if target is None else target 198 print("********************package kernel&nv upgrade file********************") 199 MAKE_IMAGE.make_hupg(self.__image_id, self.__kernel_file_ver, 0x42, kernel_file, normal_nv_file, image_file, self.__key_dir_path, self.__kernel_bin_max_size, self.__sign_alg, self.__chip_product_name, file_attr) 200 return image_file 201 202 def BuildHiburnBin(self, burn_bin = None, ota_file = None): 203 app_name = self.__app_name 204 pkt_dir_path = self.__pktPath 205 ota_mode = self.__ota_mode 206 207 #烧写文件配置 208 flash_boot_file = self.__bootBinPath 209 factory_nv_file = self.__factoryNvPath 210 normal_nv_file = self.__normalNvPath 211 if ota_mode == 1: 212 upg_file = self.BuildUpgBurnBin() 213 else: 214 upg_file = os.path.join(pkt_dir_path, '%s_%s.%s'%(app_name, 'ota', 'bin')) if ota_file is None else ota_file 215 216 if not os.path.exists(flash_boot_file): 217 print("flash_boot_file from: ", flash_boot_file) 218 sys.exit("[ERR]flash boot file is not exist, from: %s"%os.path.realpath(__file__)) 219 220 if not os.path.exists(factory_nv_file): 221 print("factory_nv_file from: ", factory_nv_file) 222 sys.exit("[ERR]factory nv file is not exist, from: %s"%os.path.realpath(__file__)) 223 224 if not os.path.exists(normal_nv_file): 225 print("normal_nv_file from: ", normal_nv_file) 226 sys.exit("[ERR]normal nv file is not exist, from: %s"%os.path.realpath(__file__)) 227 228 if not os.path.exists(upg_file): 229 print("ota file from: ", upg_file) 230 sys.exit("[ERR]ota file is not exist, from: %s"%os.path.realpath(__file__)) 231 232 # 构造输出文件名 # 233 image_file = os.path.join(pkt_dir_path, '%s_burn.bin'%app_name) if burn_bin is None else burn_bin 234 print("********************package hiburn file********************") 235 MAKE_IMAGE.make_hbin(flash_boot_file, factory_nv_file, normal_nv_file, upg_file, image_file) 236 return image_file 237 238 def BuildCompressUpgBin(self, compress_ota_bin = None, ota_file = None): 239 app_name = self.__app_name 240 pkt_dir_path = self.__pktPath 241 file_attr = (self.__file_attr_encrypt << 6) + self.__kernel_file_attr_ota 242 243 #制作压缩升级文件依赖文件 244 upg_file = os.path.join(pkt_dir_path, '%s_%s.%s'%(app_name, 'ota', 'bin')) if ota_file == None else ota_file 245 246 if not os.path.exists(upg_file): 247 print("compress ota file from: ", upg_file) 248 sys.exit("[ERR]ota file is not exist, from: %s"%os.path.realpath(__file__)) 249 250 # 构造输出文件名 # 251 image_file = os.path.join(pkt_dir_path, '%s_ota.bin'%app_name) if compress_ota_bin == None else compress_ota_bin 252 print("********************package compress upgrade file********************") 253 MAKE_IMAGE.make_compress_hupg(self.__image_id, self.__kernel_file_ver, self.__encrypt_flag, upg_file, image_file, self.__key_dir_path, self.__kernel_upg_max_size, self.__sign_alg, self.__lzma_tool_path, self.__build_tmp_path, self.__chip_product_name, file_attr) 254 return image_file 255 256# main function # 257if __name__ == '__main__': 258 args = len(sys.argv) 259 list = ['boot_ota', 'ota', 'burn_bin', 'ota_compress', 'factory_bin'] 260 if args >= 6 and sys.argv[1] in list: 261 type = sys.argv[1] 262 app_name = sys.argv[2] 263 sign_alg = int(sys.argv[3], 16) 264 kernel_file_ver = int(sys.argv[4]) 265 flashboot_file_ver = int(sys.argv[5]) 266 target = sys.argv[6] 267 usr_output = sys.argv[7].split('=')[1] if len(sys.argv[7].split('='))==2 else '' 268 ota_flag = 1 if scons_get_cfg_val('CONFIG_COMPRESSION_OTA_SUPPORT') != 'y' else 0 269 chip_product = 'Hi3861' if scons_get_cfg_val('CONFIG_TARGET_CHIP_HI3861') == 'y' else 'Hi3861L' 270 fu = ImageBuild(app_name, sign_alg, kernel_file_ver, flashboot_file_ver, chip_product, usr_realtive_output=usr_output, ota_mode=ota_flag) 271 fu.set_pkt_path(os.path.join(root_path, usr_output, 'output', 'bin')) 272 bootBinPath = os.path.join(root_path, usr_output, 'output', 'bin', '%s_boot_signed.bin'%chip_product) 273 fu.set_src_path(bootBinPath) 274 fu.set_file_attr_encrypt(0x1) if scons_get_cfg_val('CONFIG_FLASH_ENCRYPT_SUPPORT') != 'y' else None 275 fu.set_flashboot_file_attr_ota(0x3) if scons_get_cfg_val('CONFIG_COMPRESSION_OTA_SUPPORT') != 'y' else None 276 fu.set_encrypt_flag(0x42) 277 278 version_bin = bytearray(8) 279 boot_ver_bytes = flashboot_file_ver.to_bytes(4, byteorder = 'little', signed = True) 280 kernel_ver_bytes = kernel_file_ver.to_bytes(4, byteorder = 'little', signed = True) 281 version_bin[0:4] = boot_ver_bytes 282 version_bin[4:8] = kernel_ver_bytes 283 version_file = os.path.join(os.path.dirname(target), '%s_vercfg.bin'%app_name) 284 285 if type == 'boot_ota': 286 print('boot_ota') 287 fu.BuildUpgBoot(target) 288 elif type == 'ota': 289 print('ota') 290 kernelBinPath = sys.argv[8] 291 sign = sys.argv[9] 292 fu.set_src_path(kernel_bin_path = kernelBinPath) 293 fu.set_kernel_max_size(sign) if scons_get_cfg_val('CONFIG_COMPRESSION_OTA_SUPPORT') != 'y' else fu.set_kernel_max_size(0) 294 fu.set_kernel_file_attr_ota(sign) if scons_get_cfg_val('CONFIG_COMPRESSION_OTA_SUPPORT') != 'y' else None 295 if (scons_get_cfg_val('CONFIG_COMPRESSION_OTA_SUPPORT') != 'y') and (scons_get_cfg_val('CONFIG_FLASH_ENCRYPT_SUPPORT') == 'y'): 296 fu.set_encrypt_flag(0xFF) 297 fu.BuildUpgBin(target) 298 elif type == 'factory_bin': 299 print('factory_bin') 300 kernelBinPath = sys.argv[8] 301 fu.set_src_path(kernel_bin_path = kernelBinPath) 302 fu.set_kernel_max_size(0x4) 303 fu.set_kernel_file_attr_ota('A') 304 fu.BuildUpgBin(target) 305 elif type == 'burn_bin': 306 print('burn_bin') 307 ota_bin = None if scons_get_cfg_val('CONFIG_COMPRESSION_OTA_SUPPORT') != 'y' else sys.argv[8] 308 fu.set_src_path(kernel_bin_path = sys.argv[8]) if scons_get_cfg_val('CONFIG_COMPRESSION_OTA_SUPPORT') != 'y' else None 309 fu.set_build_temp_path(build_temp_path = os.path.join(root_path, 'build', 'build_tmp', 'cache')) 310 fu.BuildHiburnBin(target, ota_bin) 311 with open(version_file, 'wb+') as fp: 312 fp.write(version_bin) 313 314 hilink_enable = False 315 if (scons_get_cfg_val('CONFIG_HILINK') == 'y'): 316 hilink_enable = True 317 318 burn_for_erase_bin = os.path.join(root_path, 'build', 'basebin', 'burn_for_erase_4k.bin') 319 allinone = os.path.join(os.path.dirname(target), '%s_allinone.bin'%app_name) 320 loader_bin = os.path.join(os.path.dirname(target), '%s_loader_signed.bin'%chip_product) 321 efuse_bin = os.path.join(root_path, 'build', 'basebin', 'efuse_cfg.bin') 322 efuse_bin = None if not os.path.exists(efuse_bin) else efuse_bin 323 boot_b = os.path.join(os.path.dirname(target), "%s_boot_signed_B.bin"%(chip_product)) 324 boot_b_size = os.path.getsize(boot_b) 325 factory_bin_path = os.path.join(root_path, 'build', 'libs', 'factory_bin') 326 factory_bin = os.path.join(factory_bin_path, '%s_factory.bin'%app_name) 327 #证书安全存储示例 328 tee_cert1_file = os.path.join(root_path, 'build', 'basebin', 'tee_cert1.bin'); 329 tee_cert2_file = os.path.join(root_path, 'build', 'basebin', 'tee_cert2.bin'); 330 tee_key_file = os.path.join(root_path, 'build', 'basebin', 'tee_key.bin'); 331 tee_cert_key_bin_max = 12*1024; #必须为4KB证书倍,需匹配分区表确定烧写地址和大小 332 tee_total_file_cnt = 3; #3个文件:2个证书,1个key。 333 burn_tee_cert = False 334 if ((os.path.exists(tee_cert1_file)) and (os.path.exists(tee_cert2_file)) and (os.path.exists(tee_key_file))): 335 burn_tee_cert = True 336 337 burn_bin_ease_size = 0x200000; 338 if (hilink_enable == True): 339 burn_bin_ease_size = 0x200000 - 0x8000 - 0x1000 - 0x2000 340 if (burn_tee_cert == True): 341 burn_bin_ease_size = 0x200000 - 0x8000 - 0x1000 - 0x2000 - 0x5000 342 343 if os.path.exists(factory_bin): 344 list = ['%s|0|0|0'%loader_bin, '%s|0|0|3'%efuse_bin, '%s|0|%d|1'%(target, burn_bin_ease_size), '%s|%d|%d|6'%(factory_bin, 0x14D000, 0x96000)] if efuse_bin!=None else ['%s|0|0|0'%loader_bin, '%s|0|%d|1'%(target, burn_bin_ease_size), '%s|%d|%d|6'%(factory_bin, 0x14D000, 0x96000)] 345 shutil.copytree(factory_bin_path, os.path.join(os.path.dirname(target), 'factory_bin')) 346 else: 347 list = ['%s|0|0|0'%loader_bin, '%s|0|0|3'%efuse_bin, '%s|0|%d|1'%(target, burn_bin_ease_size)] if efuse_bin!=None else ['%s|0|0|0'%loader_bin, '%s|0|%d|1'%(target, burn_bin_ease_size)] 348 349 if ((hilink_enable == True) or (burn_tee_cert == True)): 350 list.append('%s|%d|%d|1'%(burn_for_erase_bin, 0x200000 - 0x8000 - 0x1000, 0x1000)) 351 352 #list.append('%s|%d|%d|1'%(boot_b, 0x200000 - boot_b_size, boot_b_size)); 353 354 if (burn_tee_cert == True): 355 cert_key_bin = bytearray(tee_cert_key_bin_max) 356 tee_cert1_size = os.path.getsize(tee_cert1_file) 357 tee_cert2_size = os.path.getsize(tee_cert2_file) 358 tee_key_size = os.path.getsize(tee_key_file) 359 total_cert_key_size = tee_cert1_size + tee_cert2_size + tee_key_size 360 if (total_cert_key_size > tee_cert_key_bin_max - 4 - 4 - 4*tee_total_file_cnt): 361 print('[ERROR]: cert total len bigger than tee_cert_key_bin_max!!!') 362 sys.exit(1) 363 else: 364 with open(tee_cert1_file, 'rb') as fp: 365 tee_cert1_bin = fp.read() 366 with open(tee_cert2_file, 'rb') as fp: 367 tee_cert2_bin = fp.read() 368 with open(tee_key_file, 'rb') as fp: 369 tee_key_bin = fp.read() 370 371 #填充头部结构 372 start_flag = 0xDEADBEEF 373 start_flag_bytes = start_flag.to_bytes(4, byteorder = 'little', signed = False) 374 cert_key_bin[0:4] = start_flag_bytes #填充魔术字 375 tee_total_file_cnt_bytes = tee_total_file_cnt.to_bytes(4, byteorder = 'little', signed = True) 376 cert_key_bin[4:8] = tee_total_file_cnt_bytes #填充总的文件数 377 #填充各文件的大小 378 cert_key_bin[8:12] = tee_cert1_size.to_bytes(4, byteorder = 'little', signed = True) 379 cert_key_bin[12:16] = tee_cert2_size.to_bytes(4, byteorder = 'little', signed = True) 380 cert_key_bin[16:20] = tee_key_size.to_bytes(4, byteorder = 'little', signed = True) 381 #填充各文件 382 cert_key_bin[20:20 + tee_cert1_size] = tee_cert1_bin 383 cert_key_bin[20 + tee_cert1_size:20 + tee_cert1_size + tee_cert2_size] = tee_cert2_bin 384 cert_key_bin[20 + tee_cert1_size + tee_cert2_size:20 + tee_cert1_size + tee_cert2_size + tee_key_size] = tee_key_bin 385 #写文件 386 cert_bin_file = os.path.join(root_path, "output", "bin", '%s_tee_cert_key.bin'%app_name) 387 with open(cert_bin_file, 'wb+') as fp: 388 fp.write(cert_key_bin) 389 list.append('%s|%d|%d|1'%(cert_bin_file, 0x200000 - 0x8000 - 0x1000 - 0x2000 - 0x5000, tee_cert_key_bin_max)) 390 391 if (sign_alg != 0x3F): #only need write ver file in secure boot mode. 392 list.append('%s|0|0|7'%version_file) 393 packet_bin(allinone, list) 394 if os.path.exists(factory_bin_path): 395 shutil.rmtree(factory_bin_path) 396 elif type == 'ota_compress': 397 print('ota_compress') 398 ota_bin = sys.argv[8] 399 fu.set_kernel_file_attr_ota(0x4) 400 fu.set_kernel_max_size(0) #(912+968)KB 401 fu.set_build_temp_path(build_temp_path = os.path.dirname(ota_bin)) 402 if scons_get_cfg_val('CONFIG_FLASH_ENCRYPT_SUPPORT') == 'y': 403 fu.set_encrypt_flag(0xFF) 404 fu.BuildCompressUpgBin(target, ota_bin) 405 elif args == 5 or args == 3: 406 sign_alg = int(sys.argv[1], 16) 407 dual_ota_flag = sys.argv[2] 408 flashboot_file_ver = 0 if args != 5 else int(sys.argv[3]) 409 kernel_file_ver = 0 if args != 5 else int(sys.argv[4]) 410 lib_path = os.path.join(root_path, 'build', 'scripts') 411 sys.path.append(lib_path) 412 from hi_config_parser import UsrCfgParser 413 414 class BaseCfgParser(UsrCfgParser): 415 def get_default_config_file(self): 416 return os.path.join(root_path, 'platform', 'os', 'Huawei_LiteOS', '.config') 417 418 options = BaseCfgParser().do_parse() 419 chip_product = options.get('LOSCFG_COMPILER_CHIP_VER') 420 app_name = chip_product + '_demo' 421 if app_name: 422 app_name = app_name.strip('"') 423 424 t1 = time.time() 425 print("&&&&&&&&&&&&&args", sign_alg, dual_ota_flag, flashboot_file_ver, kernel_file_ver) 426 fu = ImageBuild(app_name, sign_alg, kernel_file_ver, flashboot_file_ver, chip_product, ota_mode=int(dual_ota_flag)) 427 fu.set_encrypt_flag(0x42) 428 if int(dual_ota_flag) == 0: 429 fu.set_kernel_max_size(0) 430 fu.compress_ota_work() 431 else: 432 fu.set_kernel_file_attr_ota('A') #kernelA 433 fu.set_flashboot_file_attr_ota(0x3) #kernelA|kernelB 434 fu.dual_partion_ota_work() 435 436 print ("Package finish!! \r\n") 437 print('TOTAL TIME:%ss'%str(time.time() - t1)) 438 else: 439 print('[ERROR]: build ota parameters err!!!') 440 sys.exit(1) 441