1# Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import os 15import sys 16import shutil 17import subprocess 18 19current_path = os.path.dirname(os.path.realpath(__file__)) 20sdk_root_path = os.path.realpath(os.path.join(current_path, "../../../../../")) 21sys.path.append(os.path.join(sdk_root_path, 'tools/pkg')) 22from packet_create import packet_bin 23 24def get_file_size(file_path: str)->int: 25 try: 26 return os.stat(file_path).st_size 27 except BaseException as e: 28 print(e) 29 exit(-1) 30 31cmd_app = [os.path.join(sdk_root_path, "build.py"), "ws63-liteos-app"] 32cmd_mfg = [os.path.join(sdk_root_path, "build.py"), "ws63-liteos-mfg"] 33 34ret_app = subprocess.run(cmd_app, cwd=sdk_root_path) 35ret_mfg = subprocess.run(cmd_mfg, cwd=sdk_root_path) 36 37if ret_app.returncode != 0 or ret_mfg.returncode != 0: 38 print("build error!") 39 exit(-1) 40 41boot_bin_dir = os.path.join(sdk_root_path, "interim_binary", "ws63", "bin", "boot_bin") 42param_bin_dir = os.path.join(sdk_root_path, "output", "ws63", "acore", "param_bin") 43nv_bin_dir = os.path.join(sdk_root_path, "output", "ws63", "acore", "nv_bin") 44 45loadboot_bin = os.path.join(boot_bin_dir, "root_loaderboot_sign.bin") 46loadboot_bx = loadboot_bin + "|0x0|0x200000|0" 47 48# params 49params_bin = os.path.join(param_bin_dir, "root_params_sign.bin") 50params_bx = params_bin + f"|0x200000|{hex(get_file_size(params_bin))}|1" 51 52# flash boot 53flashboot_bin = os.path.join(boot_bin_dir, "flashboot_sign.bin") 54flashboot_bx = flashboot_bin + f"|0x202000|{hex(get_file_size(flashboot_bin))}|1" 55 56# nv 57nv_bin = os.path.join(nv_bin_dir, "ws63_all_nv.bin") 58nv_bx = nv_bin + f"|0x224000|{hex(get_file_size(nv_bin))}|1" 59 60app_bin_path = os.path.join(sdk_root_path, "output/ws63/acore/ws63-liteos-app/ws63-liteos-app-sign.bin") 61mfg_app_bin_path = os.path.join(sdk_root_path, "output/ws63/acore/ws63-liteos-mfg/ws63-liteos-mfg-sign.bin") 62 63app_templat_bx = app_bin_path + f"|0x22D000|{hex(get_file_size(app_bin_path))}|1" 64mfg_app_bx = mfg_app_bin_path + f"|0x42D000|{hex(0x1BA000)}|1" 65 66# 输出目录 67fwpkg_outdir = os.path.join(sdk_root_path, "output", "ws63", "fwpkg", "ws63-liteos-mfg-all") 68 69if os.path.exists(fwpkg_outdir): 70 shutil.rmtree(fwpkg_outdir) 71os.makedirs(fwpkg_outdir) 72 73packet_post_agvs = list() 74packet_post_agvs.append(loadboot_bx) 75packet_post_agvs.append(params_bx) 76packet_post_agvs.append(flashboot_bx) 77packet_post_agvs.append(nv_bx) 78packet_post_agvs.append(app_templat_bx) 79packet_post_agvs.append(mfg_app_bx) 80 81output_fwpkg_path = os.path.join(fwpkg_outdir, "mfg_app_sign.fwpkg") 82packet_bin(output_fwpkg_path, packet_post_agvs)