blob: a03e5aa8f315e51d2e7161da88325853a2b6c35b [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbinc6588c52015-05-15 13:15:34 -05002
3#ifndef _BOOT_DEVICE_H_
4#define _BOOT_DEVICE_H_
5
Aaron Durbindc9f5cd2015-09-08 13:34:43 -05006#include <commonlib/region.h>
Aaron Durbinc6588c52015-05-15 13:15:34 -05007
Aaron Durbindcbccd62016-08-10 11:42:42 -05008/*
Rizwan Qureshi6d4c1f52018-10-26 16:54:42 +05309 * 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 */
18enum bootdev_prot_type {
19 CTRLR_WP = 1,
20 CTRLR_RP = 2,
21 CTRLR_RWP = 3,
22 MEDIA_WP = 4,
23};
24/*
Aaron Durbindcbccd62016-08-10 11:42:42 -050025 * 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 Durbinc6588c52015-05-15 13:15:34 -050030/* Return the region_device for the read-only boot device. */
31const struct region_device *boot_device_ro(void);
32
Aaron Durbindcbccd62016-08-10 11:42:42 -050033/* Return the region_device for the read-write boot device. */
34const struct region_device *boot_device_rw(void);
35
Aaron Durbinc6588c52015-05-15 13:15:34 -050036/*
37 * Create a sub-region of the read-only boot device.
38 * Returns 0 on success, < 0 on error.
39 */
40int boot_device_ro_subregion(const struct region *sub,
41 struct region_device *subrd);
42
43/*
Aaron Durbindcbccd62016-08-10 11:42:42 -050044 * Create a sub-region of the read-write boot device.
45 * Returns 0 on success, < 0 on error.
46 */
47int boot_device_rw_subregion(const struct region *sub,
48 struct region_device *subrd);
49
50/*
Rizwan Qureshi6d4c1f52018-10-26 16:54:42 +053051 * 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 Rudolph2be0b502019-05-09 13:43:49 +020055int boot_device_wp_region(const struct region_device *rd,
Rizwan Qureshi6d4c1f52018-10-26 16:54:42 +053056 const enum bootdev_prot_type type);
57
58/*
Aaron Durbinc6588c52015-05-15 13:15:34 -050059 * Initialize the boot device. This may be called multiple times within
60 * a stage so boot device implementations should account for this behavior.
61 **/
62void boot_device_init(void);
63
Patrick Rudolph78feacc2019-12-03 19:43:06 +010064/*
65 * Restrict read/write access to the bootmedia using platform defined rules.
66 */
Patrick Rudolph6093c502019-05-08 18:36:39 +020067#if CONFIG(BOOTMEDIA_LOCK_NONE) || (CONFIG(BOOTMEDIA_LOCK_IN_VERSTAGE) && ENV_RAMSTAGE)
Patrick Rudolph78feacc2019-12-03 19:43:06 +010068static inline void boot_device_security_lockdown(void) {}
69#else
70void boot_device_security_lockdown(void);
71#endif
Aaron Durbinc6588c52015-05-15 13:15:34 -050072#endif /* _BOOT_DEVICE_H_ */