@@ -100,19 +100,27 @@ and validate image fields.
100100
101101 - Analysis happens asynchronously in the background using Celery (we
102102 already use it heavily, so this fits right in).
103- - The system attempts to extract metadata:
104-
105- - ``/etc/openwrt_release `` → DISTRIB_DESCRIPTION (image identifier),
106- DISTRIB_TARGET, architecture.
107- - **Embedded, device tree-based targets ** (``ramips ``, ``ath ``,
108- ``ath79 ``, ``mediatek ``, ``ipq ``, ``rockchip ``): extract kernel
109- from ``sysupgrade `` images, decompress if needed (gzip, ``lzma ``,
110- ``xz ``, ``zstd `` - whatever OpenWrt uses), locate and extract the
111- embedded Device Tree Blob (DTB) using ``binwalk `` or similar
112- well-known tools, read the ``compatible `` property; use the first
113- compatible string as the authoritative board identifier.
114- - **x86 targets **: no board concept exists; rely only on
115- ``/etc/openwrt_release ``.
103+ - **Primary metadata extraction method **: OpenWrt ``sysupgrade `` images
104+ already contain JSON metadata embedded by the ``fwtool `` utility.
105+ This metadata includes:
106+
107+ - ``version.dist `` and ``version.version `` → OS identifier
108+ - ``version.target `` → target and architecture
109+ - ``version.board `` and ``supported_devices `` → board compatibility
110+ - Extraction is fast and does not require decompression.
111+ - A minimal Python implementation for reference: `extract_metadata.py
112+ <https://gist.github.com/nemesifier/b5ed320f6d4ef0ef6782148b5d300c81> `__
113+
114+ - **Fallback method ** (for images without ``fwtool `` metadata, e.g.,
115+ non-``sysupgrade `` images): May require kernel decompression and
116+ Device Tree Blob (DTB) extraction. See implementation notes below for
117+ details.
118+
119+ - ``x86 `` & ``armvirt ``: These are disk images without ``fwtool ``
120+ metadata; no board concept exists. Manual metadata input is
121+ required.
122+ - Other compile targets may lack ``fwtool `` metadata; more research
123+ is needed, *please include your findings in your GSoC proposal *.
116124
117125 - Images remain **unconfirmed ** and invisible for upgrade operations
118126 while analysis runs.
@@ -195,22 +203,32 @@ Safety rules
195203Implementation notes
196204++++++++++++++++++++
197205
198- **Tooling: ** We should use ``binwalk `` or similar standard tools for DTB
199- extraction rather than writing custom parsers. OpenWrt images change all
200- the time and our resources are limited - better to rely on tools that
201- handle this stuff already. If ``binwalk `` isn't available or fails, notify
202- users and fallback to manual extraction mode.
203-
204- **Memory management: ** Decompression can be memory-hungry (``lzma ``/``xz ``
205- can need 10-100MB+). We should:
206-
207- - Make memory limits configurable with reasonable defaults for typical
208- OpenWrt images.
209- - Detect when an image would exceed memory thresholds.
210- - Handle out of memory gracefully via ``generic_notification `` (since we
211- can't validate during Django model save - compression ratios vary).
212- - Consider limiting decompression output size to prevent zip bomb-style
213- attacks.
206+ **Primary extraction method: ** Firmware images built with OpenWrt's build
207+ system already contain JSON metadata embedded via the ``fwtool `` utility.
208+ This has been standard practice for years and is present in all
209+ ``sysupgrade `` images, including custom builds. The metadata can be
210+ extracted quickly without decompression. A minimal Python implementation
211+ demonstrating this approach is available for reference:
212+ `extract_metadata.py
213+ <https://gist.github.com/nemesifier/b5ed320f6d4ef0ef6782148b5d300c81> `__.
214+
215+ **Fallback extraction method: ** For images without ``fwtool `` metadata
216+ (non-``sysupgrade `` images, ``x86 `` / ``armvirt `` disk images, or edge
217+ cases), extraction may require decompressing the kernel and extracting the
218+ Device Tree Blob (DTB). Contributors should research established tools and
219+ techniques for this (e.g., kernel decompression, ``binwalk `` for DTB
220+ location) rather than reinventing solutions. The specific implementation
221+ details are left to the contributor's research.
222+
223+ **Memory management: ** While ``fwtool `` metadata extraction does not
224+ require decompression, fallback methods might. For cases requiring
225+ decompression:
226+
227+ - Make memory limits configurable with reasonable defaults.
228+ - Handle out of memory errors in the background task and notify users via
229+ ``generic_notification ``.
230+ - Implement limits on max decompression output size to prevent zip
231+ bomb-style attacks.
214232
215233**Timeouts: ** Use the same task timeouts we already use for firmware
216234upgrades.
@@ -233,7 +251,7 @@ To handle these differences, this module uses the concept of an **Upgrader
233251Class **. Therefore, the logic described here should be implemented in a
234252similar object-oriented structure, allowing for customization, extension,
235253or complete override if needed. Each upgrader class must have a related
236- meta-data extraction class.
254+ metadata extraction class.
237255
238256Benefits
239257++++++++
@@ -264,15 +282,22 @@ repo:
264282Additional context and research findings
265283++++++++++++++++++++++++++++++++++++++++
266284
285+ - **``fwtool`` metadata **: OpenWrt has embedded JSON metadata in
286+ ``sysupgrade `` images for years via the ``fwtool `` utility. This
287+ metadata is reliable and contains all essential information (OS
288+ identifier, target, board, supported devices).
289+ - **``sysupgrade`` vs disk images **: Only ``sysupgrade `` images contain
290+ ``fwtool `` metadata. ``x86 `` and ``armvirt `` images are disk images and
291+ lack this metadata. Contributors should investigate whether other
292+ compile targets produce disk images.
267293- ``/etc/board.json `` and ``/tmp/sysinfo/* `` are runtime generated and not
268294 present in firmware images.
269- - For embedded targets, the **only authoritative board identity **
270- pre-installation is the DTB in the kernel.
271- - DTB extraction is feasible but non-trivial: kernels may be compressed
272- and DTBs at variable offsets.
273- - x86 is a fundamental exception: no board concept exists, images are
295+ - For embedded targets without ``fwtool `` metadata, the **only
296+ authoritative board identity ** pre-installation is the DTB in the
297+ kernel.
298+ - ``x86 `` is a fundamental exception: no board concept exists, images are
274299 target wide.
275- - ``Rootfs `` images (``*-squashfs-rootfs.img ``) are **not suitable for
300+ - ``rootfs `` images (``*-squashfs-rootfs.img ``) are **not suitable for
276301 upgrades ** and should not be treated as fully valid.
277302- A draft/unconfirmed workflow ensures the system remains safe while
278303 extraction runs or fails.
@@ -296,26 +321,32 @@ Downsides and challenges
296321Open questions for contributors
297322+++++++++++++++++++++++++++++++
298323
299- 1. **DTB extraction details **: How exactly should ``binwalk `` (or your
300- proposed tool) locate and extract DTBs across different target
301- families? What are the failure modes and how do we handle them?
324+ 1. **Non-``sysupgrade`` images **: How should we handle images without
325+ ``fwtool `` metadata (``x86 ``, ``armvirt `` disk images, and potentially
326+ other targets)? Are there other compile targets that produce disk
327+ images instead of ``sysupgrade `` images? What is the best approach for
328+ these cases?
3023292. **Manual override workflow **: Design the complete admin UI flow for
303330 when extraction fails. What does the user see? How do they enter
304331 metadata manually? How do we validate their input?
3053323. **Cross-version compatibility **: OpenWrt versions from 18.06 to 24.10
306- may have different formats. How do we handle this? Should we detect the
307- version and adjust extraction logic?
333+ may have different metadata formats. How do we handle this? Should we
334+ detect the version and adjust extraction logic?
3083354. **Downloading fw images for testing **: Best practices for downloading
309336 test images: part of test setup or separate command? How to handle
310337 caching efficiently?
311- 5. **Decompression limits **: What's a reasonable default for maximum
312- decompressed size? How do we detect compression bombs early?
338+ 5. **Decompression limits **: For fallback methods requiring decompression,
339+ what's a reasonable default for maximum decompressed size? How do we
340+ detect compression bombs early?
3133416. **Status UI **: What should the admin interface look like for showing
314342 analysis status? Status badges? Progress indicators? How do we
315343 communicate "this image is being analyzed" vs "this needs your
316344 attention"?
3173457. **Error granularity **: How detailed should failure messages be?
318346 Technical details for admins vs. user-friendly summaries?
347+ 8. **Derivatives and non OpenWrt firmware **: How do you intend to
348+ structure the code so that each Upgrader Class has its own metadata
349+ extraction logic?
319350
320351Prerequisites to work on this project
321352+++++++++++++++++++++++++++++++++++++
0 commit comments