Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 2 | |
| 3 | #ifndef _BOOT_DEVICE_H_ |
| 4 | #define _BOOT_DEVICE_H_ |
| 5 | |
Aaron Durbin | dc9f5cd | 2015-09-08 13:34:43 -0500 | [diff] [blame] | 6 | #include <commonlib/region.h> |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 7 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 8 | /* |
Rizwan Qureshi | 6d4c1f5 | 2018-10-26 16:54:42 +0530 | [diff] [blame] | 9 | * Boot device region can be protected by 2 sources, media and controller. |
| 10 | * The following modes are identified. It depends on the flash chip and the |
| 11 | * controller if mode is actually supported. |
| 12 | * |
| 13 | * MEDIA_WP : Flash/Boot device enforces write protect |
| 14 | * CTRLR_WP : Controller device enforces write protect |
| 15 | * CTRLR_RP : Controller device enforces read protect |
| 16 | * CTRLR_RWP : Controller device enforces read-write protect |
| 17 | */ |
| 18 | enum bootdev_prot_type { |
| 19 | CTRLR_WP = 1, |
| 20 | CTRLR_RP = 2, |
| 21 | CTRLR_RWP = 3, |
| 22 | MEDIA_WP = 4, |
| 23 | }; |
| 24 | /* |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 25 | * Please note that the read-only boot device may not be coherent with |
| 26 | * the read-write boot device. Thus, mixing mmap() and writeat() is |
| 27 | * most likely not to work so don't rely on such semantics. |
| 28 | */ |
| 29 | |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 30 | /* Return the region_device for the read-only boot device. */ |
| 31 | const struct region_device *boot_device_ro(void); |
| 32 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 33 | /* Return the region_device for the read-write boot device. */ |
| 34 | const struct region_device *boot_device_rw(void); |
| 35 | |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 36 | /* |
| 37 | * Create a sub-region of the read-only boot device. |
| 38 | * Returns 0 on success, < 0 on error. |
| 39 | */ |
| 40 | int boot_device_ro_subregion(const struct region *sub, |
| 41 | struct region_device *subrd); |
| 42 | |
| 43 | /* |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 44 | * Create a sub-region of the read-write boot device. |
| 45 | * Returns 0 on success, < 0 on error. |
| 46 | */ |
| 47 | int boot_device_rw_subregion(const struct region *sub, |
| 48 | struct region_device *subrd); |
| 49 | |
| 50 | /* |
Rizwan Qureshi | 6d4c1f5 | 2018-10-26 16:54:42 +0530 | [diff] [blame] | 51 | * Write protect a sub-region of the boot device represented |
| 52 | * by the region device. |
| 53 | * Returns 0 on success, < 0 on error. |
| 54 | */ |
Patrick Rudolph | 2be0b50 | 2019-05-09 13:43:49 +0200 | [diff] [blame] | 55 | int boot_device_wp_region(const struct region_device *rd, |
Rizwan Qureshi | 6d4c1f5 | 2018-10-26 16:54:42 +0530 | [diff] [blame] | 56 | const enum bootdev_prot_type type); |
| 57 | |
| 58 | /* |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 59 | * Initialize the boot device. This may be called multiple times within |
| 60 | * a stage so boot device implementations should account for this behavior. |
| 61 | **/ |
| 62 | void boot_device_init(void); |
| 63 | |
Patrick Rudolph | 78feacc | 2019-12-03 19:43:06 +0100 | [diff] [blame] | 64 | /* |
| 65 | * Restrict read/write access to the bootmedia using platform defined rules. |
| 66 | */ |
Patrick Rudolph | 6093c50 | 2019-05-08 18:36:39 +0200 | [diff] [blame] | 67 | #if CONFIG(BOOTMEDIA_LOCK_NONE) || (CONFIG(BOOTMEDIA_LOCK_IN_VERSTAGE) && ENV_RAMSTAGE) |
Patrick Rudolph | 78feacc | 2019-12-03 19:43:06 +0100 | [diff] [blame] | 68 | static inline void boot_device_security_lockdown(void) {} |
| 69 | #else |
| 70 | void boot_device_security_lockdown(void); |
| 71 | #endif |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 72 | #endif /* _BOOT_DEVICE_H_ */ |