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. 13import sys 14import os 15 16 17def merge(file_first, file_second, file_out): 18 ret = open(file_out, 'wb') 19 with open(file_first, 'rb') as file_1: 20 for i in file_1: 21 ret.write(i) 22 with open(file_second, 'rb') as file_2: 23 for i in file_2: 24 ret.write(i) 25 ret.close() 26 27 28def move_file(src_path, dst_path, file_name): 29 src_file = os.path.join(src_path, file_name) 30 if not os.path.exists(dst_path): 31 os.mkdir(dst_path) 32 dst_file = os.path.join(dst_path, file_name) 33 shutil.move(src_file, dst_file) 34 35 36# instead of linux dd 37# max_size: number of k 38def python_dd(file_name, max_size): 39 file_size = os.path.getsize(file_name) 40 print(file_name, "size: ", file_size) 41 if file_size < max_size * 1024: 42 file_content = open(file_name, 'wb') 43 file_content.write(b'0' * (max_size * 1024 - file_size)) 44 45 46root_dir = sys.argv[1] 47bin_name = sys.argv[2] 48 49out_dir = os.path.join(root_dir, "output/ws63/acore/", bin_name) 50romboot_bin = os.path.join(root_dir, "/output/ws63/acore/ws63-romboot/romboot.bin") 51 52if not os.path.isfile(romboot_bin): 53 print("[*] romboot not found, codepoint files will not be one!") 54 sys.exit() 55 56python_dd(romboot_bin, 36) 57merge(romboot_bin, romboot_bin + "_rom.bin", romboot_bin + "_rompack.bin")