Skip to content

Commit 009778d

Browse files
SebastianBoerlubos
authored andcommitted
[nrf fromtree] soc: nordic: uicr: Add support for UICR.WDTSTART
Add support for UICR.WDTSTART. UICR.WDTSTART configures the automatic start of a local watchdog timer before the application core is booted. This provides early system protection ensuring that the system can recover from early boot failures. Signed-off-by: Sebastian Bøe <[email protected]> (cherry picked from commit af32ebd)
1 parent 5785431 commit 009778d

File tree

4 files changed

+157
-6
lines changed

4 files changed

+157
-6
lines changed

scripts/ci/check_compliance.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,12 +1351,18 @@ def check_no_undef_outside_kconfig(self, kconf):
13511351
"FOO_SETTING_1",
13521352
"FOO_SETTING_2",
13531353
"GEN_UICR_GENERATE_PERIPHCONF", # Used in specialized build tool, not part of main Kconfig
1354-
"GEN_UICR_PROTECTEDMEM", # Used in specialized build tool, not part of main Kconfig
1355-
"GEN_UICR_PROTECTEDMEM_SIZE_BYTES", # Used in specialized build tool, not part of main Kconfig
1356-
"GEN_UICR_SECONDARY", # Used in specialized build tool, not part of main Kconfig
1357-
"GEN_UICR_SECONDARY_GENERATE_PERIPHCONF", # Used in specialized build tool, not part of main Kconfig
1358-
"GEN_UICR_SECONDARY_PROCESSOR_VALUE", # Used in specialized build tool, not part of main Kconfig
1359-
"GEN_UICR_SECURESTORAGE", # Used in specialized build tool, not part of main Kconfig
1354+
"GEN_UICR_PROTECTEDMEM",
1355+
"GEN_UICR_PROTECTEDMEM_SIZE_BYTES",
1356+
"GEN_UICR_SECONDARY",
1357+
"GEN_UICR_SECONDARY_GENERATE_PERIPHCONF",
1358+
"GEN_UICR_SECONDARY_PROCESSOR_VALUE",
1359+
"GEN_UICR_SECONDARY_WDTSTART",
1360+
"GEN_UICR_SECONDARY_WDTSTART_CRV",
1361+
"GEN_UICR_SECONDARY_WDTSTART_INSTANCE_CODE",
1362+
"GEN_UICR_SECURESTORAGE",
1363+
"GEN_UICR_WDTSTART",
1364+
"GEN_UICR_WDTSTART_CRV",
1365+
"GEN_UICR_WDTSTART_INSTANCE_CODE",
13601366
"HEAP_MEM_POOL_ADD_SIZE_", # Used as an option matching prefix
13611367
"HUGETLBFS", # Linux, in boards/xtensa/intel_adsp_cavs25/doc
13621368
"IAR_BUFFERED_WRITE",

soc/nordic/common/uicr/gen_uicr.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,36 @@ def main() -> None:
440440
type=int,
441441
help="Protected memory size in bytes (must be divisible by 4096)",
442442
)
443+
parser.add_argument(
444+
"--wdtstart",
445+
action="store_true",
446+
help="Enable watchdog timer start in UICR",
447+
)
448+
parser.add_argument(
449+
"--wdtstart-instance-code",
450+
type=lambda s: int(s, 0),
451+
help="Watchdog timer instance code (0xBD2328A8 for WDT0, 0x1730C77F for WDT1)",
452+
)
453+
parser.add_argument(
454+
"--wdtstart-crv",
455+
type=int,
456+
help="Initial Counter Reload Value (CRV) for watchdog timer (minimum: 0xF)",
457+
)
458+
parser.add_argument(
459+
"--secondary-wdtstart",
460+
action="store_true",
461+
help="Enable watchdog timer start in UICR.SECONDARY",
462+
)
463+
parser.add_argument(
464+
"--secondary-wdtstart-instance-code",
465+
type=lambda s: int(s, 0),
466+
help="Secondary watchdog timer instance code (0xBD2328A8 for WDT0, 0x1730C77F for WDT1)",
467+
)
468+
parser.add_argument(
469+
"--secondary-wdtstart-crv",
470+
type=int,
471+
help="Secondary initial Counter Reload Value (CRV) for watchdog timer (minimum: 0xF)",
472+
)
443473
parser.add_argument(
444474
"--secondary",
445475
action="store_true",
@@ -557,6 +587,12 @@ def main() -> None:
557587
uicr.PROTECTEDMEM.ENABLE = ENABLED_VALUE
558588
uicr.PROTECTEDMEM.SIZE4KB = args.protectedmem_size_bytes // KB_4
559589

590+
# Handle WDTSTART configuration
591+
if args.wdtstart:
592+
uicr.WDTSTART.ENABLE = ENABLED_VALUE
593+
uicr.WDTSTART.CRV = args.wdtstart_crv
594+
uicr.WDTSTART.INSTANCE = args.wdtstart_instance_code
595+
560596
# Process periphconf data first and configure UICR completely before creating hex objects
561597
periphconf_hex = IntelHex()
562598
secondary_periphconf_hex = IntelHex()
@@ -625,6 +661,12 @@ def main() -> None:
625661

626662
uicr.SECONDARY.PERIPHCONF.MAXCOUNT = args.secondary_periphconf_size // 8
627663

664+
# Handle secondary WDTSTART configuration
665+
if args.secondary_wdtstart:
666+
uicr.SECONDARY.WDTSTART.ENABLE = ENABLED_VALUE
667+
uicr.SECONDARY.WDTSTART.CRV = args.secondary_wdtstart_crv
668+
uicr.SECONDARY.WDTSTART.INSTANCE = args.secondary_wdtstart_instance_code
669+
628670
# Create UICR hex object with final UICR data
629671
uicr_hex = IntelHex()
630672
uicr_hex.frombytes(bytes(uicr), offset=args.uicr_address)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ endif()
7777

7878
set(protectedmem_args)
7979
set(periphconf_args)
80+
set(wdtstart_args)
8081
set(periphconf_elfs)
8182
set(merged_hex_file ${APPLICATION_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.hex)
8283
set(secondary_periphconf_elfs)
@@ -120,6 +121,13 @@ if(CONFIG_GEN_UICR_PROTECTEDMEM)
120121
list(APPEND protectedmem_args --protectedmem-size-bytes ${CONFIG_GEN_UICR_PROTECTEDMEM_SIZE_BYTES})
121122
endif()
122123

124+
# Handle WDTSTART configuration
125+
if(CONFIG_GEN_UICR_WDTSTART)
126+
list(APPEND wdtstart_args --wdtstart)
127+
list(APPEND wdtstart_args --wdtstart-instance-code ${CONFIG_GEN_UICR_WDTSTART_INSTANCE_CODE})
128+
list(APPEND wdtstart_args --wdtstart-crv ${CONFIG_GEN_UICR_WDTSTART_CRV})
129+
endif()
130+
123131
if(CONFIG_GEN_UICR_GENERATE_PERIPHCONF)
124132
# gen_uicr.py parses all zephyr.elf files. To find these files (which
125133
# have not been built yet) we scan sibling build directories for
@@ -173,6 +181,13 @@ if(CONFIG_GEN_UICR_SECONDARY)
173181
--secondary-processor ${CONFIG_GEN_UICR_SECONDARY_PROCESSOR_VALUE}
174182
)
175183

184+
# Handle secondary WDTSTART configuration
185+
if(CONFIG_GEN_UICR_SECONDARY_WDTSTART)
186+
list(APPEND secondary_args --secondary-wdtstart)
187+
list(APPEND secondary_args --secondary-wdtstart-instance-code ${CONFIG_GEN_UICR_SECONDARY_WDTSTART_INSTANCE_CODE})
188+
list(APPEND secondary_args --secondary-wdtstart-crv ${CONFIG_GEN_UICR_SECONDARY_WDTSTART_CRV})
189+
endif()
190+
176191
if(CONFIG_GEN_UICR_SECONDARY_GENERATE_PERIPHCONF)
177192
# Compute SECONDARY_PERIPHCONF absolute address and size from this image's devicetree
178193
compute_partition_address_and_size("secondary_periphconf_partition" SECONDARY_PERIPHCONF_ADDRESS SECONDARY_PERIPHCONF_SIZE)
@@ -195,6 +210,7 @@ add_custom_command(
195210
--uicr-address ${UICR_ADDRESS}
196211
--out-merged-hex ${merged_hex_file}
197212
--out-uicr-hex ${uicr_hex_file}
213+
${wdtstart_args}
198214
${periphconf_args}
199215
${securestorage_args}
200216
${protectedmem_args}

soc/nordic/common/uicr/gen_uicr/Kconfig

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,93 @@ config GEN_UICR_PROTECTEDMEM_SIZE_BYTES
4646
Size of the protected memory region in bytes.
4747
This value must be divisible by 4096 (4 kiB).
4848

49+
config GEN_UICR_WDTSTART
50+
bool "Enable UICR.WDTSTART"
51+
help
52+
When enabled, the UICR generator will configure an application
53+
domain watchdog timer to start automatically before the
54+
application core is booted.
55+
56+
choice GEN_UICR_WDTSTART_INSTANCE
57+
prompt "Watchdog timer instance"
58+
depends on GEN_UICR_WDTSTART
59+
default GEN_UICR_WDTSTART_INSTANCE_WDT0
60+
help
61+
Select which watchdog timer instance to use.
62+
63+
config GEN_UICR_WDTSTART_INSTANCE_WDT0
64+
bool "WDT0"
65+
help
66+
Use watchdog timer instance 0.
67+
68+
config GEN_UICR_WDTSTART_INSTANCE_WDT1
69+
bool "WDT1"
70+
help
71+
Use watchdog timer instance 1.
72+
73+
endchoice
74+
75+
config GEN_UICR_WDTSTART_INSTANCE_CODE
76+
hex
77+
default 0xBD2328A8 if GEN_UICR_WDTSTART_INSTANCE_WDT0
78+
default 0x1730C77F if GEN_UICR_WDTSTART_INSTANCE_WDT1
79+
depends on GEN_UICR_WDTSTART
80+
81+
config GEN_UICR_WDTSTART_CRV
82+
int "Initial Counter Reload Value (CRV)"
83+
default 65535
84+
range 15 4294967295
85+
depends on GEN_UICR_WDTSTART
86+
help
87+
Initial Counter Reload Value (CRV) for the watchdog timer.
88+
This value determines the watchdog timeout period.
89+
Must be at least 15 (0xF) to ensure proper watchdog operation.
90+
Default value 65535 creates a 2-second timeout.
91+
92+
config GEN_UICR_SECONDARY_WDTSTART
93+
bool "Enable UICR.SECONDARY.WDTSTART"
94+
depends on GEN_UICR_SECONDARY
95+
help
96+
When enabled, the UICR generator will configure the
97+
watchdog timer to start automatically before the
98+
secondary firmware is booted.
99+
100+
choice GEN_UICR_SECONDARY_WDTSTART_INSTANCE
101+
prompt "Secondary watchdog timer instance"
102+
depends on GEN_UICR_SECONDARY_WDTSTART
103+
default GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT0
104+
help
105+
Select which watchdog timer instance to use for secondary firmware.
106+
107+
config GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT0
108+
bool "WDT0"
109+
help
110+
Use watchdog timer instance 0 for secondary firmware.
111+
112+
config GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT1
113+
bool "WDT1"
114+
help
115+
Use watchdog timer instance 1 for secondary firmware.
116+
117+
endchoice
118+
119+
config GEN_UICR_SECONDARY_WDTSTART_INSTANCE_CODE
120+
hex
121+
default 0xBD2328A8 if GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT0
122+
default 0x1730C77F if GEN_UICR_SECONDARY_WDTSTART_INSTANCE_WDT1
123+
depends on GEN_UICR_SECONDARY_WDTSTART
124+
125+
config GEN_UICR_SECONDARY_WDTSTART_CRV
126+
int "Secondary initial Counter Reload Value (CRV)"
127+
default 65535
128+
range 15 4294967295
129+
depends on GEN_UICR_SECONDARY_WDTSTART
130+
help
131+
Initial Counter Reload Value (CRV) for the secondary watchdog timer.
132+
This value determines the watchdog timeout period.
133+
Must be at least 15 (0xF) to ensure proper watchdog operation.
134+
Default value 65535 creates a 2-second timeout.
135+
49136
config GEN_UICR_SECONDARY
50137
bool "Enable UICR.SECONDARY.ENABLE"
51138

0 commit comments

Comments
 (0)