dts: stop generating CONFIG_FLASH_LOAD_{OFFSET,SIZE}
As a step to completing removing use of Kconfig defines in dts files we need to change how we configure/set CONFIG_FLASH_LOAD_{OFFSET,SIZE}. Previously we would set them based on how the chosen property 'zephyr,code-partition' was set to. If 'zephyr,code-partition' wasn't set we would default the values to 0. We had some generic overlay logic which would define 'zephyr,code-partition' based on CONFIG_BOOTLOADER_MCUBOOT. Going forward if the DTS has 'zephyr,code-partition' set we will generate DT_CODE_PARTITION_OFFSET & DT_CODE_PARTITION_SIZE defines. We will leave it to Kconfig to set CONFIG_FLASH_LOAD_OFFSET & CONFIG_FLASH_LOAD_SIZE. We introduce a python script that allows Kconfig to extract data from the DTS and thus we can utilize DT_CODE_PARTITION_OFFSET and DT_CODE_PARTITION_SIZE values to set defaults for CONFIG_FLASH_LOAD_OFFSET & CONFIG_FLASH_LOAD_SIZE. Signed-off-by: Kumar Gala <kumar.gala@linaro.org> Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
5977b3db2f
commit
87915cd36f
3 changed files with 87 additions and 6 deletions
|
@ -82,9 +82,9 @@ config HAS_FLASH_LOAD_OFFSET
|
|||
This option is selected by targets having a FLASH_LOAD_OFFSET
|
||||
and FLASH_LOAD_SIZE.
|
||||
|
||||
if !HAS_DTS
|
||||
config FLASH_LOAD_OFFSET
|
||||
hex "Kernel load offset"
|
||||
default $(dt_hex_val,DT_CODE_PARTITION_OFFSET) if BOOTLOADER_MCUBOOT
|
||||
default 0
|
||||
depends on HAS_FLASH_LOAD_OFFSET
|
||||
help
|
||||
|
@ -97,6 +97,7 @@ config FLASH_LOAD_OFFSET
|
|||
|
||||
config FLASH_LOAD_SIZE
|
||||
hex "Kernel load size"
|
||||
default $(dt_hex_val,DT_CODE_PARTITION_SIZE) if BOOTLOADER_MCUBOOT
|
||||
default 0
|
||||
depends on HAS_FLASH_LOAD_OFFSET
|
||||
help
|
||||
|
@ -106,7 +107,6 @@ config FLASH_LOAD_SIZE
|
|||
the device.
|
||||
|
||||
If unsure, leave at the default value 0.
|
||||
endif
|
||||
|
||||
config TEXT_SECTION_OFFSET
|
||||
hex
|
||||
|
|
|
@ -143,12 +143,12 @@ class DTFlash(DTDirective):
|
|||
# only compute the load offset if the code partition
|
||||
# is not the same as the flash base address
|
||||
load_offset = node['props']['reg'][0]
|
||||
load_defs['CONFIG_FLASH_LOAD_OFFSET'] = load_offset
|
||||
load_defs['DT_CODE_PARTITION_OFFSET'] = load_offset
|
||||
load_size = node['props']['reg'][1]
|
||||
load_defs['CONFIG_FLASH_LOAD_SIZE'] = load_size
|
||||
load_defs['DT_CODE_PARTITION_SIZE'] = load_size
|
||||
else:
|
||||
load_defs['CONFIG_FLASH_LOAD_OFFSET'] = 0
|
||||
load_defs['CONFIG_FLASH_LOAD_SIZE'] = 0
|
||||
load_defs['DT_CODE_PARTITION_OFFSET'] = 0
|
||||
load_defs['DT_CODE_PARTITION_SIZE'] = 0
|
||||
|
||||
insert_defs(node_address, load_defs, {})
|
||||
|
||||
|
|
81
scripts/kconfig/kconfigfunctions.py
Normal file
81
scripts/kconfig/kconfigfunctions.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
#
|
||||
# Copyright (c) 2018-2019 Linaro
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import os
|
||||
|
||||
# Types we support
|
||||
# 'string', 'int', 'hex', 'bool'
|
||||
|
||||
bin_dir = os.environ.get('PROJECT_BINARY_DIR')
|
||||
conf_file = os.path.join(bin_dir, 'include', 'generated',
|
||||
'generated_dts_board.conf') if bin_dir else None
|
||||
|
||||
dt_defines = {}
|
||||
if conf_file and os.path.isfile(conf_file):
|
||||
with open(conf_file, 'r', encoding='utf-8') as fd:
|
||||
for line in fd:
|
||||
if '=' in line:
|
||||
define, val = line.split('=')
|
||||
dt_defines[define] = val.strip()
|
||||
|
||||
def _dt_units_to_scale(unit):
|
||||
if not unit:
|
||||
return 0
|
||||
if unit in {'k', 'K'}:
|
||||
return 10
|
||||
if unit in {'m', 'M'}:
|
||||
return 20
|
||||
if unit in {'g', 'G'}:
|
||||
return 30
|
||||
|
||||
def dt_int_val(kconf, _, name, unit=None):
|
||||
"""
|
||||
This function looks up 'name' in the DTS generated "conf" style database
|
||||
and if its found it will return the value as an decimal integer. The
|
||||
function will divide the value based on 'unit':
|
||||
None No division
|
||||
'k' or 'K' divide by 1024 (1 << 10)
|
||||
'm' or 'M' divide by 1,048,576 (1 << 20)
|
||||
'g' or 'G' divide by 1,073,741,824 (1 << 30)
|
||||
"""
|
||||
if name not in dt_defines:
|
||||
return "0"
|
||||
|
||||
d = dt_defines[name]
|
||||
if d.startswith(('0x', '0X')):
|
||||
d = int(d, 16)
|
||||
else:
|
||||
d = int(d)
|
||||
d >>= _dt_units_to_scale(unit)
|
||||
|
||||
return str(d)
|
||||
|
||||
def dt_hex_val(kconf, _, name, unit=None):
|
||||
"""
|
||||
This function looks up 'name' in the DTS generated "conf" style database
|
||||
and if its found it will return the value as an hex integer. The
|
||||
function will divide the value based on 'unit':
|
||||
None No division
|
||||
'k' or 'K' divide by 1024 (1 << 10)
|
||||
'm' or 'M' divide by 1,048,576 (1 << 20)
|
||||
'g' or 'G' divide by 1,073,741,824 (1 << 30)
|
||||
"""
|
||||
if name not in dt_defines:
|
||||
return "0x0"
|
||||
|
||||
d = dt_defines[name]
|
||||
if d.startswith(('0x', '0X')):
|
||||
d = int(d, 16)
|
||||
else:
|
||||
d = int(d)
|
||||
d >>= _dt_units_to_scale(unit)
|
||||
|
||||
return hex(d)
|
||||
|
||||
|
||||
functions = {
|
||||
"dt_int_val": (dt_int_val, 1, 2),
|
||||
"dt_hex_val": (dt_hex_val, 1, 2),
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue