This commit is contained in:
刘可亮
2024-10-30 16:50:31 +08:00
parent 0ef85b55da
commit 661e71562d
458 changed files with 46555 additions and 12133 deletions

View File

@@ -1370,11 +1370,17 @@ def mkimage_prebuild(aic_root, prj_chip, prj_board, prj_kernel, prj_app, prj_def
TARGET_BIN = aic_pack_dir + 'bootloader.bin'
if prj_kernel == 'baremetal' and "bootloader" == prj_app:
POST_ACTION += '@cp -r ' + SOURCE_BIN + ' ' + TARGET_BIN + '\n'
from calc_linked_addr import calc_link_addr
calc_link_addr(aic_pack_dir + 'image_cfg.json',
'.config', aic_pack_dir + '.image_cfg.json.tmp')
else:
if len(MKFS_ACTION):
POST_ACTION += MKFS_ACTION
# packaged ddr files
POST_ACTION += '@cp -r ' + aic_pack_dir + '* ' + prj_out_dir + '\n'
if os.path.exists(aic_pack_dir + '.image_cfg.json.tmp'):
POST_ACTION += '@cp ' + aic_pack_dir + '.image_cfg.json.tmp ' \
+ prj_out_dir + 'image_cfg.json\n'
if platform.system() == 'Linux':
MAKE_DDR_TOOL = 'python3 ' + aic_script_dir + 'mk_private_resource.py'
elif platform.system() == 'Windows':

View File

@@ -0,0 +1,53 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2023-2024 ArtInChip Technology Co., Ltd
# Xiong Hao <hao.xiong@artinchip.com>
#
# Tool to calculate bootloader linked addr from .config file
#
import os
from menuconfig import get_config_val, get_text_base
def calc_link_addr(infile, config, outfile):
mem_auto_enable = 'CONFIG_AIC_BOOTLOADER_MEM_AUTO'
text_base_config = 'CONFIG_AIC_BOOTLOADER_TEXT_BASE'
text_load_config = 'CONFIG_AIC_BOOTLOADER_LOAD_BASE'
if get_config_val(config, mem_auto_enable) == 'y':
text_base = hex(get_text_base(config))
load_base = hex(int(text_base, 16) - 0x100)
else:
text_base = get_config_val(config, text_base_config)
load_base = hex(int(text_base, 16) - 0x100)
with open(infile, 'r') as f:
cfg = f.read()
cfg = cfg.replace(text_base_config, text_base)
cfg = cfg.replace(text_load_config, load_base)
with open(outfile, 'w') as f:
f.write(cfg)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Tool to calculate bootloader linked addr from .config file')
parser.add_argument('-i', '--infile', type=str, help='input image_cfg.json file')
parser.add_argument('-c', '--config', type=str, help='bootloader defconfig file')
parser.add_argument('-o', '--outfile', type=str, help='output image_cfg.jaon file')
args = parser.parse_args()
if args.infile is None:
print('Error, option --infile is required.')
sys.exit(1)
if args.config is None:
print('Error, option --config is required.')
sys.exit(1)
if args.outfile is None:
outname = '.' + os.path.basename(img) + '.tmp'
args.outfile = os.path.dirname(img) + '/' + outname
sys.exit(1)
calc_link_addr(args.infile, args.config, args.outfile)

View File

@@ -11,6 +11,8 @@ import sys
import platform
import argparse
import subprocess
import json
from collections import OrderedDict
def mkimage_get_resource_size(srcdir, cluster_siz):
@@ -45,6 +47,48 @@ def mkimage_get_part_size(outfile):
return size
def parse_image_cfg(cfgfile):
""" Load image configuration file
Args:
cfgfile: Configuration file name
"""
with open(cfgfile, "r") as f:
lines = f.readlines()
jsonstr = ""
for line in lines:
sline = line.strip()
if sline.startswith("//"):
continue
slash_start = sline.find("//")
if slash_start > 0:
jsonstr += sline[0:slash_start].strip()
else:
jsonstr += sline
# Use OrderedDict is important, we need to iterate FWC in order.
jsonstr = jsonstr.replace(",}", "}").replace(",]", "]")
cfg = json.loads(jsonstr, object_pairs_hook=OrderedDict)
return cfg
def check_is_nftl_part(outfile):
imgname = os.path.basename(outfile)
partjson = os.path.join(os.path.dirname(outfile), 'partition.json')
if not os.path.exists(partjson):
return False
cfg = parse_image_cfg(partjson)
nftl_value = cfg["partitions"].get("nftl")
if nftl_value is None:
return False
imgname = os.path.basename(outfile)
parts = imgname.split('.')
nftl_part = parts[0] + ':'
if nftl_part in nftl_value:
return True
return False
def run_cmd(cmdstr):
# print(cmdstr)
cmd = cmdstr.split(' ')
@@ -192,6 +236,15 @@ if __name__ == "__main__":
imgsiz = rsvd_siz + 2 * fat_siz + root_ent_cnt + data_region_sz
# Round to cluster alignment
imgsiz = cluster_siz * int(((imgsiz + cluster_siz - 1) / cluster_siz))
if check_is_nftl_part(args.outfile):
# Space reserved for bad block management in NFTL
NFTL_RESERVED = 51 * 64 * 2048
imgsiz = part_size - NFTL_RESERVED
if imgsiz < 0:
print('Error, partition size: {} is less than NFTL reserved: {}.'.format(part_size, NFTL_RESERVED))
sys.exit(1)
# Round to cluster alignment
imgsiz = cluster_siz * int(((imgsiz + cluster_siz - 1) / cluster_siz))
elif args.fullpart:
imgsiz = part_size
else: