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 avb::{IoError, SlotVerifyError};
16 use boot::BootError;
17 use bootconfig::BootConfigError;
18 use bootimg::ImageError;
19 use efi::EfiError;
20 use fastboot::TransportError;
21 use fdt::FdtError;
22 use gbl_storage::StorageError;
23 use libgbl::composite_enum;
24 use misc::BcbError;
25 use smoltcp::socket::tcp::{ListenError, RecvError, SendError};
26 use zbi::ZbiError;
27 
28 /// Error types for EFI application.
29 #[derive(Debug)]
30 pub enum EfiAppError {
31     ArithmeticOverflow,
32     BufferAlignment,
33     BufferTooSmall,
34     InvalidInput,
35     InvalidString,
36     NoFdt,
37     NotFound,
38     NoZbiImage,
39     PeerClosed,
40     Timeout,
41     Unsupported,
42 }
43 
44 composite_enum! {
45     /// A top level error type that consolidates errors from different libraries.
46     #[derive(Debug)]
47     pub enum GblEfiError {
48         AvbIoError(IoError),
49         BcbError(BcbError),
50         BootConfigError(BootConfigError),
51         BootError(BootError),
52         EfiAppError(EfiAppError),
53         EfiError(EfiError),
54         FdtError(FdtError),
55         ImageError(ImageError),
56         ListenError(ListenError),
57         RecvError(RecvError),
58         SendError(SendError),
59         SlotVerifyError(SlotVerifyError<'static>),
60         StorageError(StorageError),
61         TransportError(TransportError),
62         ZbiError(ZbiError),
63     }
64 }
65 
66 /// Top level error type.
67 pub type Result<T> = core::result::Result<T, GblEfiError>;
68