rea-reverse

Convert UF2 to BIN Without Losing the Flash Address Map

Written for REA 6.9.0Published by rea-reverseUpdated 3 min read
On this page

A UF2 file is not a raw flash image with a different extension. It contains 512-byte blocks that carry addresses, flags and payload bytes. Removing a fixed-size header from the file will mix framing with firmware and lose the address map.

We will extract Raspberry Pi’s official Debug Probe firmware for Pico, compare it with the ELF from the same release, and inspect two damaged copies. The end result is a verified region file plus its start address, not a guess about where a .bin belongs. Nothing in this walkthrough flashes a device or runs the downloaded firmware.

We tested REA 6.9.0 with Node 26.12.1, Python 3.14 and Zig 0.17.0 on macOS arm64. REA’s Node range is ^22.23.4 || ^24.22.1 || >=26.12.1. Assume rea --version reports 6.9.0; installation is covered separately. Zig is only the independent ELF-to-binary conversion tool here; REA’s UF2 reader does not require it.

Extract UF2 payloads without losing their flash addressesSilent walkthrough with English captions.

Get matching UF2 and ELF files from the official release

Use the two debugprobe_on_pico assets from one pinned release. Do not substitute the debugprobe_on_pico2 image: that is a different target.

mkdir uf2-check
cd uf2-check
base=https://github.com/raspberrypi/debugprobe/releases/download/debugprobe-v2.3.1
curl -fL "$base/debugprobe_on_pico.uf2" -o debugprobe_on_pico.uf2
curl -fL "$base/debugprobe_on_pico.elf" -o debugprobe_on_pico.elf
shasum -a 256 debugprobe_on_pico.uf2 debugprobe_on_pico.elf

Our downloads were 105,984 bytes for the UF2 and 1,074,724 bytes for the ELF. Their SHA-256 values were:

File SHA-256
debugprobe_on_pico.uf2 6649ebba11df46cfa6cfa1faec9706bd21303893cf3f1e40067284bd4e3792d4
debugprobe_on_pico.elf 116b780481c0e1dd0cfe9cc210a9a27c7e5aebbc87411890ccb4b15800360631

These are hashes we calculated to identify the downloaded bytes, not Raspberry Pi signatures or a claim of independent release authentication. The source is the official Debug Probe v2.3.1 release.

Read regions before extracting bytes

rea inspect-artifact ./debugprobe_on_pico.uf2 --json > inventory.json
python3 - <<'PYCODE'
import json
r = json.load(open('inventory.json'))['normalized_result']
g = next(s['evidence']['normalized_result'] for s in r['substeps']
         if s['operation'] == 'inventory_artifact')
print(g['manifest']['root_format'], g['coverage'])
for occurrence in g['occurrences']:
    print(occurrence['logical_path'], occurrence.get('format_metadata'))
PYCODE

REA reports 207 complete blocks, no trailing bytes, no invalid blocks and one main-flash region. The root has data_bytes: 52992 and container-entry coverage complete. Its only region is:

family-0xe48bff56/0x10000000-0x1000ceff.bin
start_address: 268435456  (0x10000000)
end_address:   268488447  (0x1000ceff, inclusive)
length:        52992
family_name:   RP2040

The raw file’s offset zero corresponds to flash address 0x10000000. The end address is inclusive: end - start + 1 equals the length. Keep those facts with the extracted file. A family ID labels a target family; it does not by itself prove a CPU configuration, complete memory map or entry point. REA’s family_name is a registry-derived label.

Extract the region and compare with the ELF

rea extract-artifact ./debugprobe_on_pico.uf2 --json > extracted.json
zig objcopy -O binary debugprobe_on_pico.elf debugprobe-elf.bin
python3 - <<'PYCODE'
import hashlib, json
from pathlib import Path
r = json.load(open('extracted.json'))['normalized_result']
assert r['containment_verified']
assert len(r['artifacts']) == 1
entry = r['artifacts'][0]
region = (Path(r['output_root']) / entry['relative_path']).read_bytes()
image = Path('debugprobe-elf.bin').read_bytes()
assert hashlib.sha256(region).hexdigest() == entry['sha256']
assert region[:len(image)] == image
padding = region[len(image):]
assert padding == bytes(60)
print('region', len(region), hashlib.sha256(region).hexdigest())
print('ELF binary', len(image), hashlib.sha256(image).hexdigest())
print('trailing zero padding', len(padding))
PYCODE

In this release, zig objcopy produces 52,932 bytes. The UF2 region is 52,992 bytes. The first 52,932 bytes match exactly, followed by 60 zero bytes. Those zeros are present in the UF2 payload; they are not gaps invented by REA. The check tests that exact relationship instead of incorrectly requiring the two complete file hashes to match.

Material Bytes SHA-256
Extracted UF2 region 52992 512e42dcf27b9976ae5ad719a70a468e46c57272b0a6be555188e5e02eca2a05
ELF converted to binary 52932 7b180cb0806b31e17c86fd8a81dd2c799d8e1aef50adabcfce70436c48b92aba

We now have an independent cross-check against another official representation of the same build. We have not established device compatibility or that flashing it would be safe. For a different release, investigate changed lengths and bytes rather than removing the assertions until the script passes.

See how missing and conflicting blocks change the answer

Make two disposable copies. The original files remain untouched.

python3 - <<'PYCODE'
from pathlib import Path
whole = Path('debugprobe_on_pico.uf2').read_bytes()
# Remove file block 1, leaving the recognized first block intact.
Path('missing.uf2').write_bytes(whole[:512] + whole[1024:])
# Append a conflicting payload at the first block's original address.
changed = bytearray(whole[:512])
changed[32] ^= 1
Path('conflict.uf2').write_bytes(whole + changed)
PYCODE
rea inspect-artifact ./missing.uf2 --json > missing.json
rea inspect-artifact ./conflict.uf2 --json > conflict.json

The missing-block command exits successfully but reports coverage unknown, with one declared numbered block absent. It returns two regions separated by the missing 256-byte payload, rather than silently filling the gap with zeros. The second command exits with code 1 and artifact_operation_failed. Its detail reports different values at address 0x10000000 for the same RP2040 family. That contradictory image is refused.

These are different outcomes: a useful partial inventory does not make a damaged image complete, while two incompatible writes cannot become one trustworthy output. Inspect the JSON coverage and limitations even when the process exits with zero.

Keep addresses and coverage with the BIN

A useful handoff includes the firmware source URL and hash, each region’s address and family ID, the extraction hash, and the coverage/limitation report. A bare .bin drops the container declarations that explain where its bytes belong.

For a multi-region UF2, REA keeps address-contiguous regions separate and never fills gaps. Different families use separate address spaces. Do not concatenate files blindly or choose a flash base from their order. If you proceed to disassembly, select the architecture and mapping from independent target information; this inventory alone does not select them for you.

For ordinary firmware archives containing a filesystem, the SquashFS extraction guide covers a different problem. UF2 needs its address-bearing blocks decoded first.

Sources: REA 6.9.0 UF2 reader documentation, Microsoft UF2 format, Raspberry Pi Debug Probe source and release.