blob: ee8ba759605fbee9832b9d177dae22086e283365 [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Gabe Black396b0722013-09-26 16:22:09 -07002
Aaron Durbinc6588c52015-05-15 13:15:34 -05003#include <boot_device.h>
Gabe Black396b0722013-09-26 16:22:09 -07004
Aaron Durbin64031672018-04-21 14:45:32 -06005void __weak boot_device_init(void)
Gabe Black396b0722013-09-26 16:22:09 -07006{
Aaron Durbinc6588c52015-05-15 13:15:34 -05007 /* Provide weak do-nothing init. */
8}
9
Patrick Rudolph2be0b502019-05-09 13:43:49 +020010int __weak boot_device_wp_region(const struct region_device *rd,
Rizwan Qureshi6d4c1f52018-10-26 16:54:42 +053011 const enum bootdev_prot_type type)
12{
13 /* return a failure, make aware WP is not implemented */
14 return -1;
15}
16
Aaron Durbindcbccd62016-08-10 11:42:42 -050017static int boot_device_subregion(const struct region *sub,
18 struct region_device *subrd,
19 const struct region_device *parent)
20{
21 if (parent == NULL)
22 return -1;
23
24 return rdev_chain(subrd, parent, region_offset(sub), region_sz(sub));
25}
26
Aaron Durbinc6588c52015-05-15 13:15:34 -050027int boot_device_ro_subregion(const struct region *sub,
28 struct region_device *subrd)
29{
Aaron Durbinaeb2e152015-10-13 14:26:55 -050030 /* Ensure boot device has been initialized at least once. */
31 boot_device_init();
32
Aaron Durbindcbccd62016-08-10 11:42:42 -050033 return boot_device_subregion(sub, subrd, boot_device_ro());
34}
Aaron Durbinc6588c52015-05-15 13:15:34 -050035
Aaron Durbindcbccd62016-08-10 11:42:42 -050036int boot_device_rw_subregion(const struct region *sub,
37 struct region_device *subrd)
38{
39 /* Ensure boot device has been initialized at least once. */
40 boot_device_init();
Aaron Durbinc6588c52015-05-15 13:15:34 -050041
Aaron Durbindcbccd62016-08-10 11:42:42 -050042 return boot_device_subregion(sub, subrd, boot_device_rw());
Gabe Black396b0722013-09-26 16:22:09 -070043}