1 // Copyright 2024, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use abr::{AbrData, ONE_SHOT_BOOTLOADER, ONE_SHOT_RECOVERY};
16
17 /// Converts big endian order to host order.
18 #[no_mangle]
19 #[allow(non_snake_case)]
AbrBigEndianToHost(val: u32) -> u3220 pub extern "C" fn AbrBigEndianToHost(val: u32) -> u32 {
21 u32::from_be(val)
22 }
23
24 /// Converts host order to big endian.
25 #[no_mangle]
26 #[allow(non_snake_case)]
AbrHostToBigEndian(val: u32) -> u3227 pub extern "C" fn AbrHostToBigEndian(val: u32) -> u32 {
28 val.to_be()
29 }
30
31 /// Checks if one-shot recovery boot is set in the given one-shot flags
32 #[no_mangle]
33 #[allow(non_snake_case)]
AbrIsOneShotRecoveryBootSet(flags: u8) -> bool34 pub extern "C" fn AbrIsOneShotRecoveryBootSet(flags: u8) -> bool {
35 (flags & ONE_SHOT_RECOVERY) != 0
36 }
37
38 /// Checks if one-shot recovery boot is set in the given AbrData
39 ///
40 /// # Safety
41 ///
42 /// Caller must make sure to pass a valid pointer for `abr_data`.
43 #[no_mangle]
44 #[allow(non_snake_case)]
AbrIsOneShotRecoveryBoot(abr_data: *const AbrData) -> bool45 pub unsafe extern "C" fn AbrIsOneShotRecoveryBoot(abr_data: *const AbrData) -> bool {
46 AbrIsOneShotRecoveryBootSet(abr_data.as_ref().unwrap().one_shot_flags)
47 }
48
49 /// Checks if one-shot bootloader boot is set in the given one-shot flags
50 #[no_mangle]
51 #[allow(non_snake_case)]
AbrIsOneShotBootloaderBootSet(flags: u8) -> bool52 pub extern "C" fn AbrIsOneShotBootloaderBootSet(flags: u8) -> bool {
53 (flags & ONE_SHOT_BOOTLOADER) != 0
54 }
55
56 /// Checks if one-shot bootloader boot is set in the given AbrData
57 ///
58 /// # Safety
59 ///
60 /// Caller must make sure to pass a valid pointer for `abr_data`.
61 #[no_mangle]
62 #[allow(non_snake_case)]
AbrIsOneShotBootloaderBoot(abr_data: *const AbrData) -> bool63 pub unsafe extern "C" fn AbrIsOneShotBootloaderBoot(abr_data: *const AbrData) -> bool {
64 AbrIsOneShotBootloaderBootSet(abr_data.as_ref().unwrap().one_shot_flags)
65 }
66
67 /// Sets the one-shot recovery flag in the given AbrData.
68 ///
69 /// # Safety
70 ///
71 /// Caller must make sure to pass a valid pointer for `abr_data`.
72 #[no_mangle]
73 #[allow(non_snake_case)]
AbrSetOneShotRecoveryBoot(abr_data: *mut AbrData, enable: bool)74 pub unsafe extern "C" fn AbrSetOneShotRecoveryBoot(abr_data: *mut AbrData, enable: bool) {
75 abr_data.as_mut().unwrap().set_one_shot_recovery(enable);
76 }
77
78 /// Sets the one-shot bootloader flag in the given AbrData.
79 ///
80 /// # Safety
81 ///
82 /// Caller must make sure to pass a valid pointer for `abr_data`.
83 #[no_mangle]
84 #[allow(non_snake_case)]
AbrSetOneShotBootloaderBoot(abr_data: *mut AbrData, enable: bool)85 pub unsafe extern "C" fn AbrSetOneShotBootloaderBoot(abr_data: *mut AbrData, enable: bool) {
86 abr_data.as_mut().unwrap().set_one_shot_bootloader(enable);
87 }
88