1 /*
2  * Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 #include "hardware/boot_lock.h"
7 #include "pico/runtime_init.h"
8 
9 #if NUM_BOOT_LOCKS > 0
boot_locks_reset(void)10 void boot_locks_reset(void) {
11     GCC_Pragma("GCC unroll 1") // prevent GCC unrolling this loop which is 8 bytes per
12     for (uint i = 0; i < NUM_BOOT_LOCKS; i++) {
13         boot_unlock_unsafe(boot_lock_instance(i));
14     }
15 }
16 
boot_lock_init(uint lock_num)17 boot_lock_t *boot_lock_init(uint lock_num) {
18     assert(lock_num < NUM_BOOT_LOCKS);
19     boot_lock_t *lock = boot_lock_instance(lock_num);
20     boot_unlock_unsafe(lock);
21     return lock;
22 }
23 
24 #if !PICO_RUNTIME_NO_INIT_BOOT_LOCKS_RESET
25 #include "hardware/sync.h"
runtime_init_boot_locks_reset(void)26 void __weak runtime_init_boot_locks_reset(void) {
27     boot_locks_reset();
28 }
29 #endif
30 
31 #if !PICO_RUNTIME_SKIP_INIT_BOOT_LOCKS_RESET
32 PICO_RUNTIME_INIT_FUNC_RUNTIME(runtime_init_boot_locks_reset, PICO_RUNTIME_INIT_BOOT_LOCKS_RESET);
33 #endif
34 
35 #endif
36