Skip to content

Commit 7c9275c

Browse files
SebastianBoecfriedt
authored andcommitted
soc: nordic: uicr: Add support for uicr.PROTECTEDMEM
Add support for PROTECTEDMEM. Signed-off-by: Sebastian Bøe <[email protected]>
1 parent 9f45d2c commit 7c9275c

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
@@ -1266,6 +1266,8 @@ def check_no_undef_outside_kconfig(self, kconf):
12661266
"FOO_SETTING_1",
12671267
"FOO_SETTING_2",
12681268
"GEN_UICR_GENERATE_PERIPHCONF", # Used in specialized build tool, not part of main Kconfig
1269+
"GEN_UICR_PROTECTEDMEM", # Used in specialized build tool, not part of main Kconfig
1270+
"GEN_UICR_PROTECTEDMEM_SIZE_BYTES", # Used in specialized build tool, not part of main Kconfig
12691271
"GEN_UICR_SECONDARY", # Used in specialized build tool, not part of main Kconfig
12701272
"GEN_UICR_SECONDARY_GENERATE_PERIPHCONF", # Used in specialized build tool, not part of main Kconfig
12711273
"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
@@ -26,6 +26,8 @@
2626
ENABLED_VALUE = 0xFFFF_FFFF
2727
DISABLED_VALUE = 0xBD23_28A8
2828

29+
KB_4 = 4096
30+
2931

3032
class ScriptError(RuntimeError): ...
3133

@@ -428,6 +430,16 @@ def main() -> None:
428430
type=lambda s: int(s, 0),
429431
help="Size in bytes of cpurad_its_partition (decimal or 0x-prefixed hex)",
430432
)
433+
parser.add_argument(
434+
"--protectedmem",
435+
action="store_true",
436+
help="Enable protected memory region in UICR",
437+
)
438+
parser.add_argument(
439+
"--protectedmem-size-bytes",
440+
type=int,
441+
help="Protected memory size in bytes (must be divisible by 4096)",
442+
)
431443
parser.add_argument(
432444
"--secondary",
433445
action="store_true",
@@ -535,6 +547,16 @@ def main() -> None:
535547
uicr.SECURESTORAGE.ITS.APPLICATIONSIZE1KB = args.cpuapp_its_size // 1024
536548
uicr.SECURESTORAGE.ITS.RADIOCORESIZE1KB = args.cpurad_its_size // 1024
537549

550+
# Handle protected memory configuration
551+
if args.protectedmem:
552+
if args.protectedmem_size_bytes % KB_4 != 0:
553+
raise ScriptError(
554+
f"Protected memory size ({args.protectedmem_size_bytes} bytes) "
555+
f"must be divisible by {KB_4}"
556+
)
557+
uicr.PROTECTEDMEM.ENABLE = ENABLED_VALUE
558+
uicr.PROTECTEDMEM.SIZE4KB = args.protectedmem_size_bytes // KB_4
559+
538560
# Process periphconf data first and configure UICR completely before creating hex objects
539561
periphconf_hex = IntelHex()
540562
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
@@ -67,6 +67,7 @@ endfunction()
6767
if(CMAKE_VERBOSE_MAKEFILE)
6868
endif()
6969

70+
set(protectedmem_args)
7071
set(periphconf_args)
7172
set(periphconf_elfs)
7273
set(merged_hex_file ${APPLICATION_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.hex)
@@ -105,6 +106,12 @@ if(CONFIG_GEN_UICR_SECURESTORAGE)
105106
list(APPEND securestorage_args --cpurad-its-size ${CPURAD_ITS_SIZE})
106107
endif(CONFIG_GEN_UICR_SECURESTORAGE)
107108

109+
# Handle protected memory configuration
110+
if(CONFIG_GEN_UICR_PROTECTEDMEM)
111+
list(APPEND protectedmem_args --protectedmem)
112+
list(APPEND protectedmem_args --protectedmem-size-bytes ${CONFIG_GEN_UICR_PROTECTEDMEM_SIZE_BYTES})
113+
endif()
114+
108115
if(CONFIG_GEN_UICR_GENERATE_PERIPHCONF)
109116
# gen_uicr.py parses all zephyr.elf files. To find these files (which
110117
# have not been built yet) we scan sibling build directories for
@@ -181,6 +188,7 @@ add_custom_command(
181188
--out-uicr-hex ${uicr_hex_file}
182189
${periphconf_args}
183190
${securestorage_args}
191+
${protectedmem_args}
184192
${secondary_args}
185193
DEPENDS ${periphconf_elfs} ${secondary_periphconf_elfs}
186194
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
@@ -32,6 +32,20 @@ config GEN_UICR_SECURESTORAGE
3232
- At least one subpartition must be defined
3333
- Combined subpartition sizes must equal secure_storage_partition size
3434

35+
config GEN_UICR_PROTECTEDMEM
36+
bool "Enable UICR.PROTECTEDMEM"
37+
help
38+
When enabled, the UICR generator will configure the
39+
protected memory region.
40+
41+
config GEN_UICR_PROTECTEDMEM_SIZE_BYTES
42+
int "Protected memory size in bytes"
43+
default 4096
44+
depends on GEN_UICR_PROTECTEDMEM
45+
help
46+
Size of the protected memory region in bytes.
47+
This value must be divisible by 4096 (4 kiB).
48+
3549
config GEN_UICR_SECONDARY
3650
bool "Enable UICR.SECONDARY.ENABLE"
3751

0 commit comments

Comments
 (0)