Skip to content

Commit 7f7a8cb

Browse files
committed
soc: nordic: uicr: Add support for uicr.PROTECTEDMEM
Add support for PROTECTEDMEM. Signed-off-by: Sebastian Bøe <[email protected]>
1 parent 921dee4 commit 7f7a8cb

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

scripts/ci/check_compliance.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,8 @@ def check_no_undef_outside_kconfig(self, kconf):
12641264
"FOO_SETTING_1",
12651265
"FOO_SETTING_2",
12661266
"GEN_UICR_GENERATE_PERIPHCONF", # Used in specialized build tool, not part of main Kconfig
1267+
"GEN_UICR_PROTECTEDMEM", # Used in specialized build tool, not part of main Kconfig
1268+
"GEN_UICR_PROTECTEDMEM_SIZE_BYTES", # Used in specialized build tool, not part of main Kconfig
12671269
"GEN_UICR_SECONDARY", # Used in specialized build tool, not part of main Kconfig
12681270
"GEN_UICR_SECONDARY_GENERATE_PERIPHCONF", # Used in specialized build tool, not part of main Kconfig
12691271
"GEN_UICR_SECONDARY_PROCESSOR_VALUE", # Used in specialized build tool, not part of main Kconfig

soc/nordic/common/uicr/gen_uicr.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
ENABLED_VALUE = 0xFFFF_FFFF
2626
DISABLED_VALUE = 0xBD23_28A8
2727

28+
KB_4 = 4096
29+
2830

2931
class ScriptError(RuntimeError): ...
3032

@@ -255,6 +257,16 @@ def main() -> None:
255257
type=lambda s: int(s, 0),
256258
help="Absolute flash address of the UICR region (decimal or 0x-prefixed hex)",
257259
)
260+
parser.add_argument(
261+
"--protectedmem",
262+
action="store_true",
263+
help="Enable protected memory region in UICR",
264+
)
265+
parser.add_argument(
266+
"--protectedmem-size-bytes",
267+
type=int,
268+
help="Protected memory size in bytes (must be divisible by 4096)",
269+
)
258270
parser.add_argument(
259271
"--secondary",
260272
action="store_true",
@@ -339,6 +351,16 @@ def main() -> None:
339351
uicr.VERSION.MAJOR = UICR_FORMAT_VERSION_MAJOR
340352
uicr.VERSION.MINOR = UICR_FORMAT_VERSION_MINOR
341353

354+
# Handle protected memory configuration
355+
if args.protectedmem:
356+
if args.protectedmem_size_bytes % KB_4 != 0:
357+
raise ScriptError(
358+
f"Protected memory size ({args.protectedmem_size_bytes} bytes) "
359+
f"must be divisible by 4096"
360+
)
361+
uicr.PROTECTEDMEM.ENABLE = ENABLED_VALUE
362+
uicr.PROTECTEDMEM.SIZE4KB = args.protectedmem_size_bytes // KB_4
363+
342364
# Process periphconf data first and configure UICR completely before creating hex objects
343365
periphconf_hex = IntelHex()
344366
secondary_periphconf_hex = IntelHex()

soc/nordic/common/uicr/gen_uicr/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ endfunction()
4848
if(CMAKE_VERBOSE_MAKEFILE)
4949
endif()
5050

51+
set(protectedmem_args)
5152
set(periphconf_args)
5253
set(periphconf_elfs)
5354
set(merged_hex_file ${APPLICATION_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.hex)
@@ -60,6 +61,12 @@ set(secondary_periphconf_hex_file ${APPLICATION_BINARY_DIR}/zephyr/secondary_per
6061
dt_nodelabel(uicr_path NODELABEL "uicr" REQUIRED)
6162
dt_reg_addr(UICR_ADDRESS PATH ${uicr_path} REQUIRED)
6263

64+
# Handle protected memory configuration
65+
if(CONFIG_GEN_UICR_PROTECTEDMEM)
66+
list(APPEND protectedmem_args --protectedmem)
67+
list(APPEND protectedmem_args --protectedmem-size-bytes ${CONFIG_GEN_UICR_PROTECTEDMEM_SIZE_BYTES})
68+
endif()
69+
6370
if(CONFIG_GEN_UICR_GENERATE_PERIPHCONF)
6471
# gen_uicr.py parses all zephyr.elf files. To find these files (which
6572
# have not been built yet) we scan sibling build directories for
@@ -135,6 +142,7 @@ add_custom_command(
135142
--out-merged-hex ${merged_hex_file}
136143
--out-uicr-hex ${uicr_hex_file}
137144
${periphconf_args}
145+
${protectedmem_args}
138146
${secondary_args}
139147
DEPENDS ${periphconf_elfs} ${secondary_periphconf_elfs}
140148
WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}

soc/nordic/common/uicr/gen_uicr/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ config GEN_UICR_GENERATE_PERIPHCONF
1010
When enabled, the UICR generator will populate the
1111
periphconf_partition partition.
1212

13+
config GEN_UICR_PROTECTEDMEM
14+
bool "Enable UICR.PROTECTEDMEM"
15+
help
16+
When enabled, the UICR generator will configure the
17+
protected memory region.
18+
19+
config GEN_UICR_PROTECTEDMEM_SIZE_BYTES
20+
int "Protected memory size in bytes"
21+
default 4096
22+
depends on GEN_UICR_PROTECTEDMEM
23+
help
24+
Size of the protected memory region in bytes.
25+
This value must be divisible by 4096 (4 kiB).
26+
1327
config GEN_UICR_SECONDARY
1428
bool "Enable UICR.SECONDARY.ENABLE"
1529

0 commit comments

Comments
 (0)