codecraftai-protocol-uefi 1.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ccai/protocols/uefi/__init__.py +3 -0
- ccai/protocols/uefi/boottoopceonce.py +356 -0
- ccai/protocols/uefi/boottosetupworkflow.py +487 -0
- ccai/protocols/uefi/capsuleupdateworkflow.py +610 -0
- ccai/protocols/uefi/espcontentsync.py +628 -0
- ccai/protocols/uefi/secureboothenrollment.py +560 -0
- ccai/protocols/uefi/uefacapsule.py +1411 -0
- ccai/protocols/uefi/uefiagent.py +660 -0
- ccai/protocols/uefi/uefiaspects.py +960 -0
- ccai/protocols/uefi/uefibase.py +998 -0
- ccai/protocols/uefi/uefibootmanager.py +1431 -0
- ccai/protocols/uefi/uefichannel.py +689 -0
- ccai/protocols/uefi/ueficlient.py +609 -0
- ccai/protocols/uefi/ueficonnection.py +364 -0
- ccai/protocols/uefi/ueficonst.py +274 -0
- ccai/protocols/uefi/uefidevicepath.py +2129 -0
- ccai/protocols/uefi/uefiespfiles.py +1617 -0
- ccai/protocols/uefi/uefiexceptions.py +299 -0
- ccai/protocols/uefi/uefigpt.py +683 -0
- ccai/protocols/uefi/uefiguids.py +90 -0
- ccai/protocols/uefi/uefihelpers.py +829 -0
- ccai/protocols/uefi/uefihii.py +912 -0
- ccai/protocols/uefi/uefiinterfaces.py +296 -0
- ccai/protocols/uefi/uefiipmicredential.py +178 -0
- ccai/protocols/uefi/uefiipmisoltransport.py +928 -0
- ccai/protocols/uefi/uefiloadedimage.py +804 -0
- ccai/protocols/uefi/uefilogging.py +148 -0
- ccai/protocols/uefi/uefimbr.py +379 -0
- ccai/protocols/uefi/uefimeasuredboot.py +1147 -0
- ccai/protocols/uefi/uefinetboot.py +726 -0
- ccai/protocols/uefi/uefirebootworkflow.py +389 -0
- ccai/protocols/uefi/uefiredfishcredential.py +177 -0
- ccai/protocols/uefi/uefiredfishtransport.py +1089 -0
- ccai/protocols/uefi/uefireset.py +540 -0
- ccai/protocols/uefi/uefisecureboot.py +939 -0
- ccai/protocols/uefi/uefiserialcredential.py +186 -0
- ccai/protocols/uefi/uefiserialtransport.py +1274 -0
- ccai/protocols/uefi/uefisession.py +1019 -0
- ccai/protocols/uefi/uefishell.py +1771 -0
- ccai/protocols/uefi/uefisshhosttransport.py +715 -0
- ccai/protocols/uefi/uefisystemtables.py +1422 -0
- ccai/protocols/uefi/uefitime.py +998 -0
- ccai/protocols/uefi/uefivariables.py +1371 -0
- codecraftai_protocol_uefi-1.2.0.dist-info/METADATA +54 -0
- codecraftai_protocol_uefi-1.2.0.dist-info/RECORD +47 -0
- codecraftai_protocol_uefi-1.2.0.dist-info/WHEEL +4 -0
- codecraftai_protocol_uefi-1.2.0.dist-info/licenses/LICENSE.md +204 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: boottoopceonce
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module containing the :class:`BootToOptionOnceWorkflow`
|
|
5
|
+
layer-6 orchestration and its :class:`BootOnceResult`
|
|
6
|
+
report dataclass. The workflow boots a specified UEFI
|
|
7
|
+
``Boot####`` option exactly once without modifying
|
|
8
|
+
``BootOrder`` by writing ``BootNext`` for the target
|
|
9
|
+
option, driving a reboot through the layer-6
|
|
10
|
+
:class:`ccai.protocols.uefi.uefirebootworkflow.RebootWorkflow`,
|
|
11
|
+
and verifying on the next boot that ``BootCurrent``
|
|
12
|
+
reflects the option the test requested.
|
|
13
|
+
|
|
14
|
+
The workflow also enforces the firmware's
|
|
15
|
+
spec-mandated behavior that ``BootNext`` is
|
|
16
|
+
automatically cleared after the next boot (UEFI
|
|
17
|
+
spec §3.1.3 / §3.1.5). A noncompliant firmware that
|
|
18
|
+
leaves ``BootNext`` set is diagnosed here and raises
|
|
19
|
+
:class:`ccai.protocols.uefi.uefiexceptions.UefiVariableError`
|
|
20
|
+
so the caller never silently lands in a permanent
|
|
21
|
+
one-shot loop.
|
|
22
|
+
|
|
23
|
+
The workflow composes
|
|
24
|
+
:class:`ccai.protocols.uefi.uefibootmanager.BootManager`
|
|
25
|
+
(for the ``Boot####`` existence / decode check and
|
|
26
|
+
``BootNext`` / ``BootCurrent`` reads) and
|
|
27
|
+
:class:`RebootWorkflow` (for the reboot-and-back step).
|
|
28
|
+
|
|
29
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
__author__ = "Myron Walker"
|
|
34
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
35
|
+
__credits__ = []
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
import os
|
|
39
|
+
|
|
40
|
+
from dataclasses import dataclass
|
|
41
|
+
from typing import Any, Optional
|
|
42
|
+
|
|
43
|
+
from ccai.protocols.uefi.uefiaspects import (
|
|
44
|
+
DEFAULT_CMD_ASPECTS,
|
|
45
|
+
UefiCmdAspects,
|
|
46
|
+
resolve_aspects,
|
|
47
|
+
)
|
|
48
|
+
from ccai.protocols.uefi.uefibootmanager import BootManager
|
|
49
|
+
from ccai.protocols.uefi.uefiexceptions import UefiVariableError
|
|
50
|
+
from ccai.protocols.uefi.uefilogging import (
|
|
51
|
+
UEFI_BOOTMGR_CHANNEL,
|
|
52
|
+
get_uefi_logger,
|
|
53
|
+
)
|
|
54
|
+
from ccai.protocols.uefi.uefireset import ResetKind
|
|
55
|
+
from ccai.protocols.uefi.uefirebootworkflow import RebootWorkflow
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
__all__ = [
|
|
59
|
+
"BootOnceResult",
|
|
60
|
+
"BootToOptionOnceWorkflow",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# ---------------------------------------------------------------------------
|
|
65
|
+
# BootOnceResult
|
|
66
|
+
# ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@dataclass(frozen=True)
|
|
70
|
+
class BootOnceResult:
|
|
71
|
+
"""
|
|
72
|
+
Structured outcome of a
|
|
73
|
+
:meth:`BootToOptionOnceWorkflow.boot_once` call.
|
|
74
|
+
|
|
75
|
+
:ivar success: ``True`` iff the firmware honored the
|
|
76
|
+
``BootNext`` request and ``BootCurrent``
|
|
77
|
+
post-reset equals ``requested_index``; ``False``
|
|
78
|
+
when the firmware booted a different option or
|
|
79
|
+
when ``BootCurrent`` could not be read.
|
|
80
|
+
:ivar observed_boot_current: Value of the ``BootCurrent``
|
|
81
|
+
variable observed post-reset, or
|
|
82
|
+
``None`` when the variable was
|
|
83
|
+
absent.
|
|
84
|
+
:ivar requested_index: The option index the caller requested be
|
|
85
|
+
booted exactly once.
|
|
86
|
+
"""
|
|
87
|
+
success: bool
|
|
88
|
+
observed_boot_current: Optional[int]
|
|
89
|
+
requested_index: int
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# ---------------------------------------------------------------------------
|
|
93
|
+
# BootToOptionOnceWorkflow
|
|
94
|
+
# ---------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class BootToOptionOnceWorkflow:
|
|
98
|
+
"""
|
|
99
|
+
Layer-6 workflow that boots a specified ``Boot####`` option
|
|
100
|
+
exactly once without modifying ``BootOrder``.
|
|
101
|
+
|
|
102
|
+
Holds opaque references to a
|
|
103
|
+
:class:`ccai.protocols.uefi.uefiagent.UefiAgent`, a
|
|
104
|
+
:class:`ccai.protocols.uefi.uefibootmanager.BootManager`,
|
|
105
|
+
and a
|
|
106
|
+
:class:`ccai.protocols.uefi.uefirebootworkflow.RebootWorkflow`
|
|
107
|
+
along with an instance default :class:`UefiCmdAspects`. Every
|
|
108
|
+
call to :meth:`boot_once` resolves aspects once via
|
|
109
|
+
:func:`resolve_aspects`, validates the target option exists,
|
|
110
|
+
writes ``BootNext``, drives the reboot through the injected
|
|
111
|
+
:class:`RebootWorkflow`, reads back ``BootCurrent`` and
|
|
112
|
+
``BootNext``, and returns a structured :class:`BootOnceResult`.
|
|
113
|
+
|
|
114
|
+
:param agent: The owning :class:`UefiAgent`.
|
|
115
|
+
:param boot_manager: The layer-5
|
|
116
|
+
:class:`BootManager` used for every
|
|
117
|
+
``Boot####`` / ``BootNext`` /
|
|
118
|
+
``BootCurrent`` variable operation.
|
|
119
|
+
:param reboot_workflow: The layer-6 :class:`RebootWorkflow`
|
|
120
|
+
used for the reboot-and-back step.
|
|
121
|
+
:param aspects: Default :class:`UefiCmdAspects` used when a
|
|
122
|
+
call omits its own ``aspects`` override.
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
def __init__(self, agent: Any,
|
|
126
|
+
boot_manager: BootManager,
|
|
127
|
+
reboot_workflow: RebootWorkflow,
|
|
128
|
+
aspects: UefiCmdAspects = DEFAULT_CMD_ASPECTS) -> None:
|
|
129
|
+
"""
|
|
130
|
+
Initialize the :class:`BootToOptionOnceWorkflow`.
|
|
131
|
+
|
|
132
|
+
:param agent: The owning :class:`UefiAgent` instance.
|
|
133
|
+
:param boot_manager: The :class:`BootManager` facade.
|
|
134
|
+
:param reboot_workflow: The :class:`RebootWorkflow`
|
|
135
|
+
composer.
|
|
136
|
+
:param aspects: Default aspects for calls that omit an
|
|
137
|
+
override.
|
|
138
|
+
"""
|
|
139
|
+
self._agent: Any = agent
|
|
140
|
+
self._boot_manager: BootManager = boot_manager
|
|
141
|
+
self._reboot_workflow: RebootWorkflow = reboot_workflow
|
|
142
|
+
self._aspects: UefiCmdAspects = aspects
|
|
143
|
+
self._logger = get_uefi_logger(channel=UEFI_BOOTMGR_CHANNEL)
|
|
144
|
+
return
|
|
145
|
+
|
|
146
|
+
# ------------------------------------------------------------------
|
|
147
|
+
# Public API
|
|
148
|
+
# ------------------------------------------------------------------
|
|
149
|
+
|
|
150
|
+
def boot_once(self, index: int,
|
|
151
|
+
aspects: Optional[UefiCmdAspects] = None) -> BootOnceResult:
|
|
152
|
+
"""
|
|
153
|
+
Boot the specified ``Boot####`` option exactly once.
|
|
154
|
+
|
|
155
|
+
Orchestration:
|
|
156
|
+
|
|
157
|
+
1. Verify ``Boot{index:04X}`` exists via
|
|
158
|
+
:meth:`BootManager.get_boot_option`; raise
|
|
159
|
+
:class:`UefiVariableError` if the variable is absent.
|
|
160
|
+
2. Write ``BootNext = index`` via
|
|
161
|
+
:meth:`BootManager.set_boot_next`.
|
|
162
|
+
3. Reboot via
|
|
163
|
+
:meth:`RebootWorkflow.reboot_and_verify` with
|
|
164
|
+
:class:`ResetKind.WARM`.
|
|
165
|
+
4. Read ``BootCurrent`` via
|
|
166
|
+
:meth:`BootManager.get_boot_current` to check which
|
|
167
|
+
option actually booted.
|
|
168
|
+
5. Verify ``BootNext`` was cleared by the firmware (per
|
|
169
|
+
UEFI spec §3.1.3 / §3.1.5 the firmware SHALL clear
|
|
170
|
+
``BootNext`` after the next boot). When ``BootNext``
|
|
171
|
+
still contains the originally-written value the
|
|
172
|
+
workflow raises :class:`UefiVariableError` with a
|
|
173
|
+
``"firmware did not clear BootNext"`` message.
|
|
174
|
+
6. Return a :class:`BootOnceResult` describing the
|
|
175
|
+
outcome. ``success`` is ``True`` iff the observed
|
|
176
|
+
``BootCurrent`` equals the requested ``index``.
|
|
177
|
+
|
|
178
|
+
:param index: The ``Boot####`` option index to boot
|
|
179
|
+
exactly once.
|
|
180
|
+
:param aspects: Optional per-call :class:`UefiCmdAspects`;
|
|
181
|
+
when ``None`` the instance default is used.
|
|
182
|
+
|
|
183
|
+
:returns: A :class:`BootOnceResult` describing the outcome.
|
|
184
|
+
:raises: UefiVariableError
|
|
185
|
+
"""
|
|
186
|
+
effective_aspects = resolve_aspects(
|
|
187
|
+
passed=aspects,
|
|
188
|
+
instance_default=self._aspects,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
host = getattr(self._agent, "host", None)
|
|
192
|
+
target_name = "Boot{:04X}".format(index)
|
|
193
|
+
|
|
194
|
+
self._logger.info(
|
|
195
|
+
"uefi.workflow.bootnext: begin host=%s target=%s",
|
|
196
|
+
host, target_name,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# Step 1 — verify Boot#### exists.
|
|
200
|
+
self._require_boot_option_exists(index=index, aspects=effective_aspects)
|
|
201
|
+
|
|
202
|
+
# Step 2 — write BootNext.
|
|
203
|
+
self._logger.info(
|
|
204
|
+
"uefi.workflow.bootnext: set_boot_next host=%s target=%s",
|
|
205
|
+
host, target_name,
|
|
206
|
+
)
|
|
207
|
+
self._boot_manager.set_boot_next(index=index, aspects=effective_aspects)
|
|
208
|
+
|
|
209
|
+
# Step 3 — reboot via the layer-6 RebootWorkflow.
|
|
210
|
+
self._logger.info(
|
|
211
|
+
"uefi.workflow.bootnext: reboot host=%s target=%s",
|
|
212
|
+
host, target_name,
|
|
213
|
+
)
|
|
214
|
+
self._reboot_workflow.reboot_and_verify(
|
|
215
|
+
kind=ResetKind.WARM,
|
|
216
|
+
wait_for_shell=True,
|
|
217
|
+
aspects=effective_aspects,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
# Step 4 — observe BootCurrent.
|
|
221
|
+
observed_boot_current = self._boot_manager.get_boot_current(
|
|
222
|
+
aspects=effective_aspects,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
self._logger.info(
|
|
226
|
+
"uefi.workflow.bootnext: observed boot_current host=%s observed=%s requested=0x%04X",
|
|
227
|
+
host, observed_boot_current, index,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
# Step 5 — verify the firmware cleared BootNext.
|
|
231
|
+
self._require_boot_next_cleared(
|
|
232
|
+
requested_index=index,
|
|
233
|
+
aspects=effective_aspects,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
# Step 6 — build the final result. ``success`` hinges on
|
|
237
|
+
# BootCurrent matching the requested index byte-for-byte.
|
|
238
|
+
if observed_boot_current is None:
|
|
239
|
+
success = False
|
|
240
|
+
elif observed_boot_current == index:
|
|
241
|
+
success = True
|
|
242
|
+
else:
|
|
243
|
+
success = False
|
|
244
|
+
|
|
245
|
+
result = BootOnceResult(
|
|
246
|
+
success=success,
|
|
247
|
+
observed_boot_current=observed_boot_current,
|
|
248
|
+
requested_index=index,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
self._logger.info(
|
|
252
|
+
"uefi.workflow.bootnext: done host=%s target=%s success=%s",
|
|
253
|
+
host, target_name, success,
|
|
254
|
+
)
|
|
255
|
+
return result
|
|
256
|
+
|
|
257
|
+
# ------------------------------------------------------------------
|
|
258
|
+
# Internal helpers
|
|
259
|
+
# ------------------------------------------------------------------
|
|
260
|
+
|
|
261
|
+
def _require_boot_option_exists(self, index: int,
|
|
262
|
+
aspects: UefiCmdAspects) -> None:
|
|
263
|
+
"""
|
|
264
|
+
Verify the target ``Boot####`` variable is present by
|
|
265
|
+
reading it through :meth:`BootManager.get_boot_option`.
|
|
266
|
+
A missing variable surfaces as a
|
|
267
|
+
:class:`UefiVariableError` with an explicit
|
|
268
|
+
``"Boot#### not present on target"`` detail line so the
|
|
269
|
+
caller does not have to introspect the underlying error's
|
|
270
|
+
``efi_status``.
|
|
271
|
+
|
|
272
|
+
:param index: The option index to probe.
|
|
273
|
+
:param aspects: Effective aspects for the read.
|
|
274
|
+
|
|
275
|
+
:raises: UefiVariableError
|
|
276
|
+
"""
|
|
277
|
+
target_name = "Boot{:04X}".format(index)
|
|
278
|
+
try:
|
|
279
|
+
self._boot_manager.get_boot_option(
|
|
280
|
+
index=index,
|
|
281
|
+
aspects=aspects,
|
|
282
|
+
)
|
|
283
|
+
except UefiVariableError as verr:
|
|
284
|
+
err_msg_lines = [
|
|
285
|
+
"BootToOptionOnceWorkflow: target Boot#### not present on target.",
|
|
286
|
+
"TARGET: {}".format(target_name),
|
|
287
|
+
]
|
|
288
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
289
|
+
raise UefiVariableError(
|
|
290
|
+
err_msg,
|
|
291
|
+
details=[
|
|
292
|
+
"{} not present on target".format(target_name),
|
|
293
|
+
"inner={!r}".format(verr),
|
|
294
|
+
],
|
|
295
|
+
name=target_name,
|
|
296
|
+
) from verr
|
|
297
|
+
|
|
298
|
+
return
|
|
299
|
+
|
|
300
|
+
def _require_boot_next_cleared(self, requested_index: int,
|
|
301
|
+
aspects: UefiCmdAspects) -> None:
|
|
302
|
+
"""
|
|
303
|
+
Read ``BootNext`` post-reboot and raise when it is still
|
|
304
|
+
observed to contain the value we wrote. This enforces the
|
|
305
|
+
UEFI §3.1.3 / §3.1.5 contract that the firmware SHALL
|
|
306
|
+
clear ``BootNext`` after the next boot.
|
|
307
|
+
|
|
308
|
+
:param requested_index: The option index that was written
|
|
309
|
+
into ``BootNext`` before the
|
|
310
|
+
reboot.
|
|
311
|
+
:param aspects: Effective aspects for the read.
|
|
312
|
+
|
|
313
|
+
:raises: UefiVariableError
|
|
314
|
+
"""
|
|
315
|
+
observed = self._boot_manager.get_boot_next(aspects=aspects)
|
|
316
|
+
|
|
317
|
+
if observed is None:
|
|
318
|
+
# Firmware cleared BootNext per UEFI §3.1.3 / §3.1.5.
|
|
319
|
+
return
|
|
320
|
+
|
|
321
|
+
if observed == requested_index:
|
|
322
|
+
err_msg_lines = [
|
|
323
|
+
"BootToOptionOnceWorkflow: firmware did not clear BootNext after the one-shot boot.",
|
|
324
|
+
"UEFI SPEC: §3.1.3 / §3.1.5 require BootNext be cleared after the next boot.",
|
|
325
|
+
]
|
|
326
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
327
|
+
raise UefiVariableError(
|
|
328
|
+
err_msg,
|
|
329
|
+
details=[
|
|
330
|
+
"firmware did not clear BootNext after the one-shot boot",
|
|
331
|
+
"UEFI §3.1.3 / §3.1.5 violation",
|
|
332
|
+
"requested_index=0x{:04X}".format(requested_index),
|
|
333
|
+
"BootNext observed=0x{:04X}".format(observed),
|
|
334
|
+
],
|
|
335
|
+
name="BootNext",
|
|
336
|
+
) from None
|
|
337
|
+
|
|
338
|
+
# BootNext is still set but points at a different option; record
|
|
339
|
+
# what we saw so the caller can triage. We still raise because
|
|
340
|
+
# the one-shot invariant — "BootNext SHALL be cleared after the
|
|
341
|
+
# next boot" — has been violated by the firmware.
|
|
342
|
+
err_msg_lines = [
|
|
343
|
+
"BootToOptionOnceWorkflow: firmware left BootNext set to an unexpected value after the one-shot boot.",
|
|
344
|
+
"UEFI SPEC: §3.1.3 / §3.1.5 require BootNext be cleared after the next boot.",
|
|
345
|
+
]
|
|
346
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
347
|
+
raise UefiVariableError(
|
|
348
|
+
err_msg,
|
|
349
|
+
details=[
|
|
350
|
+
"firmware did not clear BootNext after the one-shot boot",
|
|
351
|
+
"UEFI §3.1.3 / §3.1.5 violation",
|
|
352
|
+
"requested_index=0x{:04X}".format(requested_index),
|
|
353
|
+
"BootNext observed=0x{:04X}".format(observed),
|
|
354
|
+
],
|
|
355
|
+
name="BootNext",
|
|
356
|
+
) from None
|