1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
pub mod ap;
pub(crate) mod communication_interface;
pub mod component;
pub(crate) mod core;
pub mod dp;
pub mod memory;
pub mod sequences;
pub mod swo;
mod traits;
pub use communication_interface::{
ApInformation, ArmChipInfo, ArmCommunicationInterface, DapError, MemoryApInformation, Register,
};
pub use swo::{SwoAccess, SwoConfig, SwoMode, SwoReader};
pub use traits::*;
use crate::DebugProbeError;
use self::ap::AccessPort;
use self::ap::AccessPortError;
use self::armv7a::Armv7aError;
use self::armv8a::Armv8aError;
use self::communication_interface::RegisterParseError;
pub use self::core::armv6m;
pub use self::core::armv7a;
pub use self::core::armv7m;
pub use self::core::armv8a;
pub use self::core::armv8m;
pub use self::core::Dump;
use self::dp::DebugPortError;
use self::memory::romtable::RomTableError;
use self::sequences::ArmDebugSequenceError;
pub use communication_interface::ArmProbeInterface;
#[derive(Debug, thiserror::Error)]
#[error("An ARM specific error occured.")]
pub enum ArmError {
#[error("The operation requires one of the following architectures: {0:?}")]
ArchitectureRequired(&'static [&'static str]),
#[error("Timeout occured during operation.")]
Timeout,
#[error("Address is not in 32 bit address space.")]
AddressOutOf32BitAddressSpace,
#[error("Target device is not an ARM device.")]
NoArmTarget,
#[error("Error using access port")]
AccessPort {
address: ApAddress,
source: AccessPortError,
},
#[error("Error using a debug port.")]
DebugPort(#[from] DebugPortError),
#[error("The core needs to be halted for this operation but was not.")]
CoreNotHalted,
#[error("Probe and device internal state mismatch. A probe re-attach is required")]
ReAttachRequired,
#[error("An operation could not be performed because it lacked the permission to do so: {0}")]
MissingPermissions(String),
#[error("An error occured in the communication with an access port or debug port.")]
Dap(#[from] DapError),
#[error("The debug probe encountered an error.")]
Probe(#[from] DebugProbeError),
#[error("Failed to access address 0x{address:08x} as it is not aligned to the requirement of {alignment} bytes for this platform and API call.")]
MemoryNotAligned {
address: u64,
alignment: usize,
},
#[error("Out of bounds access")]
OutOfBounds,
#[error("{0} bit is not a supported memory transfer width on the current core")]
UnsupportedTransferWidth(usize),
#[error("The AP with address {0:?} does not exist.")]
ApDoesNotExist(ApAddress),
WrongApType,
#[error("Unable to create a breakpoint at address {0:#010X}. Hardware breakpoints are only supported at addresses < 0x2000'0000.")]
UnsupportedBreakpointAddress(u32),
Armv8a(#[from] Armv8aError),
Armv7a(#[from] Armv7aError),
DebugSequence(#[from] ArmDebugSequenceError),
TracingUnconfigured,
RegisterParse(#[from] RegisterParseError),
RomTable(#[source] RomTableError),
ChipEraseFailed,
}
impl ArmError {
pub fn from_access_port(err: AccessPortError, ap: impl AccessPort) -> Self {
ArmError::AccessPort {
address: ap.ap_address(),
source: err,
}
}
pub fn alignment_error(address: u64, alignment: usize) -> Self {
ArmError::MemoryNotAligned { address, alignment }
}
}
impl From<RomTableError> for ArmError {
fn from(value: RomTableError) -> Self {
match value {
RomTableError::Memory(err) => *err,
other => ArmError::RomTable(other),
}
}
}
pub fn valid_32bit_arm_address(address: u64) -> Result<u32, ArmError> {
address
.try_into()
.map_err(|_| ArmError::AddressOutOf32BitAddressSpace)
}