Tag: decap encrypted mcu program

  • PIC18F4550: Read It Twice, or You Read a Half-Update

    PIC18F4550: Read It Twice, or You Read a Half-Update

    Flash is not read-only on this part. The PIC18F4550 writes its own program memory through TBLWT, which is how every USB bootloader on it works — and it means a single read can capture one block from before an update and the next block from after it.

    The part carries 32 KB of program memory — 16,384 instruction words — with 2,048 bytes of SRAM, 256 bytes of data EEPROM, 35 I/O pins, thirteen channels of 10-bit ADC, a full-speed USB 2.0 interface with 1 KB of dual-port RAM, and 48 MHz operation for 12 MIPS. It shares DS39632 with the 24 KB PIC18F4455 and the two 28-pin members.

    Self-Programming Is the Normal Case

    On most microcontrollers, the flash is written once in production and never again. On a USB part it is rewritten whenever a user runs the update tool.

    The sequence is: erase a block, write the new content word by word into holding registers, trigger the write, verify. It takes milliseconds per block and it is not atomic. Between the erase and the last write, that block holds neither the old firmware nor the new one.

    A read during that window returns a mixture. You will not catch an update in progress on a bench — updates happen on the customer’s desk. What you can catch is the *aftermath*:

    • A device that was updated and then failed to boot, so it is stuck with a partially written application

    All three produce a file that is internally inconsistent in a way no single read reveals.

    The Two-Read Test

    The test costs one read and settles it:

    1. Read the full device — flash, configuration, EEPROM, IDs. 2. Power-cycle, wait a minute, read it again. 3. Compare, byte for byte.

    Result Interpretation
    Identical The device is quiescent. The image is a stable snapshot.
    Different in EEPROM only Normal: a counter or a log is being written. Flash is stable.
    Different in flash The application writes its own flash at runtime, or the read is not repeatable.

    The third row is the one worth acting on. If flash content changes between two reads of a device that is merely powered on, the firmware is doing something unusual — storing calibration in a flash page, using flash as a log, or rewriting a block on every boot. Any of those means “the firmware” is not a fixed object, and the image has to be taken at a defined moment: right after reset, before the application runs, or with the device held in reset if the tool supports it.

    Why the Configuration Block Matters More Here

    The 4550’s USB clock comes from a 96 MHz PLL divided by two, enabled in CONFIG1H. Configuration words are also writable at runtime on this family, and some bootloaders use that: they clear a protection bit before an update and set it afterwards.

    A device interrupted between those two operations has a configuration state that matches neither the factory setting nor the intended one. The read succeeds, the file is 32 KB, and the part will not enumerate because the PLL is not enabled.

    Which is the second reason to read twice and record the configuration separately. If it differs between reads, the firmware is manipulating it, and the image you want is the one taken when the product actually worked.

    What a Complete Image Contains

    • 32 KB of program memory at 0x0000–0x7FFF, in four 8 KB protection blocks
    • Twelve configuration bytes at 0x300000
    • 256 bytes of EEPROM at 0xF00000
    • Device ID at 0x3FFFFE, revision at 0x3FFFFF

    The 1 KB of dual-port USB RAM is not in that list: separate address range, volatile, rebuilt at every enumeration. A delivery note claiming to include it describes something that cannot be delivered.

    When the Reads Disagree and You Cannot Stop It

    If the device rewrites flash on every boot, no number of reads produces a stable image. The workaround is to capture at a defined point: hold the part in reset, release it, and read immediately — before the application’s first write. That needs a tool that can sequence the two operations.

    Where the array is fully protected, the route runs through the die and the same rule applies: the image is only meaningful relative to a known device state. That is the invasive extraction case, and it is worth saying up front that the device may be self-modifying.

    A 4550 job is otherwise straightforward: 32 KB, twelve config bytes, 256 bytes of EEPROM, two IDs, twice. The reading the memory page covers the sequence, the services page covers routing, and contact us if the board has a firmware update port — that fact changes how the read should be taken.

    Service scope and next steps

    Before we quote a PIC job we confirm the silicon revision and the protection configuration, because both decide whether the on-chip programming area can be read directly or needs a different approach. The full scope of what we handle, how a project runs from electrical integrity test to delivered file, and the payment terms are described on our service capabilities page.

    Ready to extract this PIC firmware?

    Send us the part number and a short description of what you need. Free evaluation, fixed quotation, and a reply within one business day.

    Request a quotation