Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 2 | |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 3 | #include <boot_device.h> |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 4 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 5 | void __weak boot_device_init(void) |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 6 | { |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 7 | /* Provide weak do-nothing init. */ |
| 8 | } |
| 9 | |
Patrick Rudolph | 2be0b50 | 2019-05-09 13:43:49 +0200 | [diff] [blame] | 10 | int __weak boot_device_wp_region(const struct region_device *rd, |
Rizwan Qureshi | 6d4c1f5 | 2018-10-26 16:54:42 +0530 | [diff] [blame] | 11 | const enum bootdev_prot_type type) |
| 12 | { |
| 13 | /* return a failure, make aware WP is not implemented */ |
| 14 | return -1; |
| 15 | } |
| 16 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 17 | static 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 Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 27 | int boot_device_ro_subregion(const struct region *sub, |
| 28 | struct region_device *subrd) |
| 29 | { |
Aaron Durbin | aeb2e15 | 2015-10-13 14:26:55 -0500 | [diff] [blame] | 30 | /* Ensure boot device has been initialized at least once. */ |
| 31 | boot_device_init(); |
| 32 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 33 | return boot_device_subregion(sub, subrd, boot_device_ro()); |
| 34 | } |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 35 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 36 | int 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 Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 41 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 42 | return boot_device_subregion(sub, subrd, boot_device_rw()); |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 43 | } |