brickproof-fw 0.1.0__tar.gz

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.
Files changed (104) hide show
  1. brickproof_fw-0.1.0/LICENSE +202 -0
  2. brickproof_fw-0.1.0/PKG-INFO +249 -0
  3. brickproof_fw-0.1.0/README.md +224 -0
  4. brickproof_fw-0.1.0/brickproof_fw.egg-info/PKG-INFO +249 -0
  5. brickproof_fw-0.1.0/brickproof_fw.egg-info/SOURCES.txt +102 -0
  6. brickproof_fw-0.1.0/brickproof_fw.egg-info/dependency_links.txt +1 -0
  7. brickproof_fw-0.1.0/brickproof_fw.egg-info/entry_points.txt +2 -0
  8. brickproof_fw-0.1.0/brickproof_fw.egg-info/requires.txt +5 -0
  9. brickproof_fw-0.1.0/brickproof_fw.egg-info/top_level.txt +1 -0
  10. brickproof_fw-0.1.0/examples/demo_ab_bootloader/README.md +23 -0
  11. brickproof_fw-0.1.0/examples/demo_ab_bootloader/__init__.py +3 -0
  12. brickproof_fw-0.1.0/examples/demo_ab_bootloader/adapter.yaml +59 -0
  13. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-consume_first.yaml +10 -0
  14. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-early_unpg.yaml +11 -0
  15. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-naive_floor.yaml +10 -0
  16. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-no_erase.yaml +11 -0
  17. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-no_unlock.yaml +11 -0
  18. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-pop_after_switch.yaml +11 -0
  19. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-protected_slot.yaml +9 -0
  20. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-resume_copy.yaml +13 -0
  21. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-retry_limit.yaml +14 -0
  22. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-self_lock.yaml +14 -0
  23. brickproof_fw-0.1.0/examples/demo_ab_bootloader/bug-trust_header.yaml +10 -0
  24. brickproof_fw-0.1.0/examples/demo_ab_bootloader/build.py +101 -0
  25. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-consume_first.yaml +10 -0
  26. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-early_unpg.yaml +11 -0
  27. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-naive_floor.yaml +10 -0
  28. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-no_erase.yaml +12 -0
  29. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-no_unlock.yaml +11 -0
  30. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-pop_after_switch.yaml +11 -0
  31. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-protected_slot.yaml +9 -0
  32. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-retry_limit.yaml +14 -0
  33. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-self_lock.yaml +14 -0
  34. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-trust_header.yaml +10 -0
  35. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-bug-watchdog.yaml +14 -0
  36. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-hold_pg.yaml +11 -0
  37. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411-watchdog.yaml +7 -0
  38. brickproof_fw-0.1.0/examples/demo_ab_bootloader/f411.yaml +62 -0
  39. brickproof_fw-0.1.0/examples/demo_ab_bootloader/hold_pg.yaml +11 -0
  40. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/app_v1.img +0 -0
  41. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/app_v2.img +0 -0
  42. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader.elf +0 -0
  43. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_consume_first.elf +0 -0
  44. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_early_unpg.elf +0 -0
  45. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_naive_floor.elf +0 -0
  46. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_no_erase.elf +0 -0
  47. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_no_unlock.elf +0 -0
  48. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_pop_after_switch.elf +0 -0
  49. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_resume_copy.elf +0 -0
  50. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_retry_limit.elf +0 -0
  51. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_self_lock.elf +0 -0
  52. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_bug_trust_header.elf +0 -0
  53. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/bootloader_hold_pg.elf +0 -0
  54. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_app_v1.img +0 -0
  55. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_app_v2.img +0 -0
  56. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader.elf +0 -0
  57. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_consume_first.elf +0 -0
  58. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_early_unpg.elf +0 -0
  59. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_naive_floor.elf +0 -0
  60. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_no_erase.elf +0 -0
  61. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_no_unlock.elf +0 -0
  62. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_pop_after_switch.elf +0 -0
  63. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_retry_limit.elf +0 -0
  64. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_self_lock.elf +0 -0
  65. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_trust_header.elf +0 -0
  66. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_bug_watchdog.elf +0 -0
  67. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/f411_bootloader_hold_pg.elf +0 -0
  68. brickproof_fw-0.1.0/examples/demo_ab_bootloader/prebuilt/meta_floor1.bin +0 -0
  69. brickproof_fw-0.1.0/examples/demo_ab_bootloader/watchdog.yaml +7 -0
  70. brickproof_fw-0.1.0/pyproject.toml +58 -0
  71. brickproof_fw-0.1.0/setup.cfg +4 -0
  72. brickproof_fw-0.1.0/src/brickproof/__init__.py +3 -0
  73. brickproof_fw-0.1.0/src/brickproof/adapter.py +399 -0
  74. brickproof_fw-0.1.0/src/brickproof/cli.py +304 -0
  75. brickproof_fw-0.1.0/src/brickproof/drivers/__init__.py +1 -0
  76. brickproof_fw-0.1.0/src/brickproof/drivers/staged_slot.py +91 -0
  77. brickproof_fw-0.1.0/src/brickproof/engine/__init__.py +0 -0
  78. brickproof_fw-0.1.0/src/brickproof/engine/session.py +724 -0
  79. brickproof_fw-0.1.0/src/brickproof/engine/workdir.py +167 -0
  80. brickproof_fw-0.1.0/src/brickproof/models/mem_guard.py +21 -0
  81. brickproof_fw-0.1.0/src/brickproof/models/stm32f1_flash.py +435 -0
  82. brickproof_fw-0.1.0/src/brickproof/models/stm32f1_rcc.py +17 -0
  83. brickproof_fw-0.1.0/src/brickproof/models/stm32f4_flash.py +435 -0
  84. brickproof_fw-0.1.0/src/brickproof/oracle.py +105 -0
  85. brickproof_fw-0.1.0/src/brickproof/plan.py +137 -0
  86. brickproof_fw-0.1.0/src/brickproof/platforms/stm32f103.repl +34 -0
  87. brickproof_fw-0.1.0/src/brickproof/platforms/stm32f411.repl +20 -0
  88. brickproof_fw-0.1.0/src/brickproof/pool.py +79 -0
  89. brickproof_fw-0.1.0/src/brickproof/regulations.py +137 -0
  90. brickproof_fw-0.1.0/src/brickproof/report.py +287 -0
  91. brickproof_fw-0.1.0/src/brickproof/runner.py +638 -0
  92. brickproof_fw-0.1.0/src/brickproof/torn.py +101 -0
  93. brickproof_fw-0.1.0/src/brickproof/trace.py +186 -0
  94. brickproof_fw-0.1.0/tests/test_adapter.py +268 -0
  95. brickproof_fw-0.1.0/tests/test_depth.py +160 -0
  96. brickproof_fw-0.1.0/tests/test_oracle.py +177 -0
  97. brickproof_fw-0.1.0/tests/test_plan.py +223 -0
  98. brickproof_fw-0.1.0/tests/test_pool.py +139 -0
  99. brickproof_fw-0.1.0/tests/test_report.py +219 -0
  100. brickproof_fw-0.1.0/tests/test_runner.py +161 -0
  101. brickproof_fw-0.1.0/tests/test_session_lifecycle.py +82 -0
  102. brickproof_fw-0.1.0/tests/test_torn.py +223 -0
  103. brickproof_fw-0.1.0/tests/test_trace.py +218 -0
  104. brickproof_fw-0.1.0/tests/test_workdir.py +113 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,249 @@
1
+ Metadata-Version: 2.4
2
+ Name: brickproof-fw
3
+ Version: 0.1.0
4
+ Summary: Power-fail testing for firmware updates: cut power at every flash operation in Renode and check the device recovers
5
+ Author: Adham Ehab
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/AdhamEhab14/brickproof
8
+ Project-URL: Issues, https://github.com/AdhamEhab14/brickproof/issues
9
+ Project-URL: Changelog, https://github.com/AdhamEhab14/brickproof/blob/main/CHANGELOG.md
10
+ Keywords: firmware,bootloader,ota,power-loss,fault-injection,renode,embedded,testing
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Embedded Systems
14
+ Classifier: Topic :: Software Development :: Testing
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Operating System :: OS Independent
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: PyYAML>=6
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=8; extra == "dev"
23
+ Requires-Dist: ruff>=0.6; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # BrickProof
27
+
28
+ Pull the plug on your firmware update, in an emulator, at every point where it matters, and
29
+ check that the device still comes back.
30
+
31
+ BrickProof runs your firmware in [Renode](https://renode.io), cuts power during an update,
32
+ powers the device back up, and checks that it recovered: an approved image is installed, it is
33
+ really running, the update was not lost, and an older image cannot sneak back in. It tells you
34
+ which cuts brick the device, and how to reproduce each one.
35
+
36
+ It came out of the power-cut tests of
37
+ [Three-Tier-STM32-Secure-Bootloader](https://github.com/AdhamEhab14/Three-Tier-STM32-Secure-Bootloader),
38
+ where it found three real bugs. That bootloader's fixed release has since been cut at every one
39
+ of the 12,109 distinct flash states of its self-update, with no failure. Supported chips: STM32F1 and STM32F4 (F411).
40
+
41
+ ## Quick start
42
+
43
+ You need Python 3.10+ and [Renode 1.17](https://github.com/renode/renode/releases) (put
44
+ `renode` on PATH or set `RENODE_PATH`). No toolchain, no board, no firmware of your own: a demo
45
+ comes with the package.
46
+
47
+ ```bash
48
+ git clone https://github.com/AdhamEhab14/brickproof
49
+ cd brickproof
50
+ pip install .
51
+ brickproof demo
52
+ ```
53
+
54
+ The demo is a small A/B bootloader updating its app from v1 to v2. BrickProof first checks
55
+ that the update works when nothing interrupts it, then cuts power at every flash state the
56
+ update goes through, one per line:
57
+
58
+ ```
59
+ PASS baseline (no cut) 168 ops 2.2s runs v2
60
+ PASS op-0 op 0 erase 0x0801E400 1.8s runs v2
61
+ PASS op-1 op 1 program 0x0801E400 1.7s runs v2
62
+ ...
63
+ 167/167 cuts recovered
64
+ coverage: 167 cut(s) over 167 distinct flash states (168 operations): every state is cut
65
+ ```
66
+
67
+ Now run a build with a known bug. BrickProof should catch it:
68
+
69
+ ```bash
70
+ brickproof demo self_lock --fail-fast
71
+ ```
72
+
73
+ `brickproof demo --list` shows all of them:
74
+
75
+ | Build | The mistake | What happens |
76
+ |---|---|---|
77
+ | `consume_first` | marks the staged image used before copying it | a cut leaves no valid image: bricked |
78
+ | `trust_header` | copies the header first and trusts it without a CRC | boots a half-copied image |
79
+ | `naive_floor` | rewrites the anti-rollback floor in place, after the install | an older image can be installed again |
80
+ | `pop_after_switch` | pops saved registers after switching to the app's stack | reads past the end of RAM: bus fault on every boot |
81
+ | `no_erase` | copies the new image over the old one without erasing | the chip refuses to program cells that are not erased |
82
+ | `no_unlock` | never unlocks the flash controller | the chip ignores every write: the update silently does nothing |
83
+ | `early_unpg` | stores every second cell after programming mode is off again | the chip ignores those stores: half the image is never written |
84
+ | `protected_slot` | (a device setting) the app slot is write-protected | the chip refuses every erase and program there |
85
+ | `resume_copy` | after an interrupted install, skips the erase and writes only what is missing | survives every clean cut; a torn write leaves a cell the chip will not program again |
86
+ | `retry_limit` | gives up on an update after two interrupted attempts | survives any single cut; two cuts in a row lose the update |
87
+ | `self_lock` | write-protects its own flash from the bootloader, in the field | a cut while the option bytes are erased, and the retry mass-erases the flash |
88
+
89
+ The first three are the bugs BrickProof found in the Three-Tier bootloader. `pop_after_switch`
90
+ was found by a real board after an emulator had passed it. The rest are mistakes a plain
91
+ emulator lets through and a chip does not.
92
+
93
+ The demo also builds for an **STM32F411**, a chip that differs from the F103 in everything a
94
+ power cut touches: an erase wipes a whole sector of 16 to 128 KB, a program writes a word and
95
+ is never refused (the cell ends up as old AND new), and the chip rewrites its own option
96
+ bytes. `brickproof demo f411` runs the correct build, and `brickproof demo f411-bug-no_erase`
97
+ and the other `f411-bug-*` builds have the same mistakes. `resume_copy` is missing there on
98
+ purpose: an F4 does let a half-written cell be programmed again, so it is not a bug on that chip.
99
+ It has one of its own instead, `f411-bug-watchdog`: on a device with a hardware watchdog, a
100
+ sector erase that takes a second gets the chip reset half way through, on every attempt.
101
+ `watchdog` and `f411-watchdog` are the correct build on such a device, and `hold_pg` and
102
+ `f411-hold_pg` are the correct build writing flash the other common way, with programming
103
+ mode left on over a whole run of cells.
104
+
105
+ ## What a run covers
106
+
107
+ **Clean cuts.** A golden run traces every flash operation of the update. After a power loss
108
+ only flash is left, so two cuts that leave the same flash are the same test: BrickProof cuts
109
+ only at distinct flash states and tells you how many there are and how many it covered.
110
+ `plan: every` cuts all of them. `plan: phases` cuts all of them in short phases and samples
111
+ long ones, and the report says which phases were sampled.
112
+
113
+ **Torn operations** (`--torn`). Power can fail inside an erase or a program. BrickProof also
114
+ boots the device from those states: an erase with only some bits flipped, a cell with only
115
+ some bits written. The shapes follow what flash cells do, but they are a model until compared
116
+ with real hardware, so they are counted on their own line.
117
+
118
+ **Cuts during recovery** (`--depth 2`). Recovery writes flash too. BrickProof traces it and
119
+ cuts again. A flash state already tested is skipped.
120
+
121
+ **The chip's rules.** A plain emulator is more forgiving than silicon. BrickProof gives the
122
+ emulated chip its real RAM and flash sizes, faults on memory that is not there, refuses to
123
+ program a cell that is not erased or a store of the wrong width, ignores a store made while
124
+ programming mode is off, enforces write protection, and models the option bytes.
125
+ Erases and programs take the time the datasheet gives them (a 128 KB sector erase is a second
126
+ during which the CPU stands still), so watchdogs and timeouts behave as on the board.
127
+ `flash.timing: max` in the adapter uses the slowest figures the datasheet allows. A reset
128
+ the firmware or a watchdog causes reboots the device as on the chip, and a hardware watchdog
129
+ set in the option bytes runs from reset.
130
+
131
+ **What the update costs the flash.** Each run reports how long the chip spends erasing and
132
+ programming, and which page or sector is erased most often per update, set against the
133
+ endurance the datasheet promises.
134
+
135
+ **An outside judge.** The verdict does not rest on what the firmware says about itself. An
136
+ oracle checks that the bytes installed are exactly an approved image and that the CPU is
137
+ running inside it, not in a fault handler. `runs v2` at the end of a line is its finding.
138
+
139
+ **A check on itself.** After every cut, the emulated flash is compared byte for byte with
140
+ what the golden run predicts for that point. If they differ, the run stops.
141
+
142
+ To see what an update does to flash, and what a run would cut, without cutting anything:
143
+
144
+ ```bash
145
+ brickproof trace examples/demo_ab_bootloader/adapter.yaml
146
+ ```
147
+
148
+ ```
149
+ op 0 erase 1 ops 1 states cut all 0x0801E400 spare rollback-floor page
150
+ ops 1-6 program 6 ops 5 states cut all 0x0801E400 .. 0x0801E40A new floor record
151
+ op 7 erase 1 ops 1 states cut all 0x08002000 Slot A
152
+ ops 8-157 program 150 ops 150 states cut all 0x08002200 .. 0x0800232A app body
153
+ ops 158-165 program 8 ops 8 states cut all 0x08002000 .. 0x0800200E header, last
154
+ ops 166-167 program 2 ops 2 states cut all 0x08010000 .. 0x08010002 mark the staged image used
155
+ plan (every): 167 cut(s) over 167 distinct flash states (168 operations): every state is cut
156
+ ```
157
+
158
+ (The notes on the right are added here; the tool prints the rest.)
159
+
160
+ ## Options
161
+
162
+ | Option | What it does |
163
+ |---|---|
164
+ | `--plan every` / `--plan phases` | cut every distinct flash state, or sample long phases |
165
+ | `--torn` | also boot from torn erases and programs |
166
+ | `--depth 2` | also cut during the recovery from each first cut |
167
+ | `-j N` / `-j auto` | run N emulators side by side; the results do not depend on N |
168
+ | `--real-every N` | on a long update, make every Nth cut in the emulator and compute the rest |
169
+ | `--shard K/N` | run every Nth cut, starting with the Kth: splits a long campaign over N machines |
170
+ | `--cut N` | run one operation alone, to reproduce a result |
171
+ | `--fail-fast` | stop at the first failure |
172
+ | `--json`, `--junit`, `--html FILE` | reports |
173
+
174
+ The HTML report is one self-contained page: the verdict, what was covered and what was
175
+ sampled, each failure with a command that reproduces it, the SHA-256 of every firmware file
176
+ tested, and where the evidence fits in UN R156 and the EU Cyber Resilience Act
177
+ ([how that map is made](docs/regulations.md)).
178
+
179
+ Exit codes: `0` every cut recovered, `1` at least one failed, `2` adapter error, `3` BrickProof
180
+ itself failed (including its own flash self-check).
181
+
182
+ ## Testing your own firmware
183
+
184
+ Write an adapter: one YAML file that says what to load, the real flash and RAM sizes of the
185
+ chip, what is write-protected, which images are approved (the `oracle` section), and how to
186
+ plan the cuts.
187
+
188
+ If your bootloader applies an image waiting in a staging slot on the next boot (MCUboot's
189
+ overwrite mode, most OTA designs), the built-in `staged_slot` driver does the rest, and the
190
+ demo's [adapter.yaml](examples/demo_ab_bootloader/adapter.yaml) is the template. If the update
191
+ is started over a protocol (UART, CAN, UDS), add a small `driver.py`, like the one for the
192
+ Three-Tier bootloader in [adapters/three_tier_f103](adapters/three_tier_f103). Every key is explained in
193
+ [docs/adapter.md](docs/adapter.md).
194
+
195
+ ```bash
196
+ brickproof run my_adapter.yaml --torn --depth 2 -j auto --html report.html
197
+ ```
198
+
199
+ ## In CI
200
+
201
+ ```yaml
202
+ - uses: AdhamEhab14/brickproof@v0.1.0
203
+ with:
204
+ adapter: test/brickproof.yaml
205
+ args: --torn --depth 2 -j 3
206
+ ```
207
+
208
+ The job fails if any cut does not recover, and the JSON, JUnit and HTML reports are uploaded
209
+ as an artifact.
210
+
211
+ ## Docker
212
+
213
+ ```bash
214
+ docker run --rm ghcr.io/adhamehab14/brickproof # the demo
215
+ docker run --rm -v "$PWD:/work" ghcr.io/adhamehab14/brickproof run adapter.yaml --html report.html
216
+ ```
217
+
218
+ ## Layout
219
+
220
+ | Path | What |
221
+ |---|---|
222
+ | `src/brickproof/engine/` | Renode driver in lock-step virtual time, work-folder setup |
223
+ | `src/brickproof/models/` | The flash controller model (operation counting, cuts, the chip's rules, option bytes) and the memory guard |
224
+ | `src/brickproof/platforms/` | Base Renode platforms the models plug into |
225
+ | `src/brickproof/trace.py` | The golden-run trace: phases, replay to any operation |
226
+ | `src/brickproof/plan.py` | The cut planner: distinct flash states, exhaustive or sampled |
227
+ | `src/brickproof/torn.py` | Torn states: an erase or a program left half done |
228
+ | `src/brickproof/oracle.py` | The outside judge: approved image installed, and really running |
229
+ | `src/brickproof/runner.py`, `pool.py` | A campaign: baseline, cuts, torn states, depth, over one or many emulators |
230
+ | `src/brickproof/report.py`, `regulations.py` | JUnit and HTML reports, and the regulation map |
231
+ | `src/brickproof/drivers/` | Built-in drivers (`staged_slot`) |
232
+ | `examples/demo_ab_bootloader/` | The demo firmware, its source, prebuilt files and adapters |
233
+ | `adapters/` | Adapters for real projects (Three-Tier bootloader) |
234
+ | `docs/decisions.md` | Why things are the way they are, with the measurements behind them |
235
+
236
+ ## Limits
237
+
238
+ - The device is emulated. Torn-operation shapes are a model until compared with hardware.
239
+ - Flash is modelled for STM32F1 (pages, halfword programming) and STM32F411 (sectors, byte
240
+ to double-word programming). Another family needs a model of its flash controller in
241
+ `src/brickproof/models/`; the engine itself no longer assumes either chip.
242
+ - Flash timing uses datasheet figures (typical or slowest), not measurements, and does not
243
+ vary with temperature, voltage or age. Wear is counted per update, not simulated.
244
+ - Not modelled: low-power modes, so the two option bits that decide whether entering one
245
+ resets the chip have no effect.
246
+
247
+ ## Licence
248
+
249
+ Apache-2.0, see [LICENSE](LICENSE).