Posts Tagged ‘crack pic18f14k22 memoria flash del controller’
PIC18F14K22: The Block Boundary That Decides What You Can See
Sixteen kilobytes of program memory on a 20-pin device, split into two halves. The split exists so that a bootloader written into the lower half can stay readable — or stay writable — independently of the application above it. It is a small feature with a large effect on what a read produces.
The effect is easiest to see as a table of outcomes, because on this part a read either works completely, fails completely, or produces exactly one visible half.
| CP1 | CP0 | Lower half | Upper half |
|---|---|---|---|
| 0 | 0 | Readable | Readable |
| 0 | 1 | Readable | Zeros |
| 1 | 0 | Zeros | Readable |
| 1 | 1 | Zeros | Zeros |
The third row is the one that matters in practice. It describes a device whose bootloader is protected and whose application is not — a configuration that appears in products where the vendor’s code sits below and the customer’s above.
Where the boundary falls
The two blocks divide the array at its midpoint: the lower block occupies the first half of the program memory, the upper block the second. On a 16K part that places the division at the eight-kilobyte address.
Everything about interpreting a partial read depends on that address being known exactly. A read that stops producing valid data at the midpoint is a read of a protected upper block. A read with a gap somewhere else is not.
This distinction is worth stating because it is routinely missed. A tool that reports “reads zeros after address X” invites the conclusion that X is a protection boundary, and on this part X must be the midpoint. If it is not, the cause is elsewhere: a transport failure, a device held in a state where the array is not accessible, or a reader configured for the wrong part.
Why a partially readable device is easier and harder
Easier, because half the code is available and half a program is a substantial amount of evidence. The visible block usually contains the vector table — reset and interrupts sit at the bottom of the array — so the reading starts with entry points.
Harder, because the two halves were written at different times by different people, and the interface between them is exactly the thing that is missing. A bootloader’s calls into an application are not in the application, and an application’s expectations of its bootloader are not in the bootloader.
The practical approach is to read the visible half completely, then use it to characterise the invisible half: what it is called, what it is passed, and when.
Reading a visible block properly
Half an image is not half a job. Three things need to be established before the visible half is useful:
- Where it ends. Confirm the last valid word and the first zero. The boundary should be the block edge; anything else means the read is not simply gated.
- What it contains. Vector table, initialisation, and — often — a version string, which identifies the build.
- What it expects. Calls into the missing region leave traces: arguments loaded before the call, return values consumed after it.
The third item is where a partial image earns its keep. A bootloader that calls an application entry point with a structure pointer reveals the structure’s layout from the bootloader’s side, even though the application’s own definition is invisible.
Configuration words, and the trap in reading them
The configuration words sit outside the protected region and are readable on this family. They confirm which of the four states in the table above applies.
The trap is that configuration is often rewritten by a bootloader at runtime. A device whose bootloader clears CP0 before jumping to the application, or restores it afterwards, presents different configuration depending on when it was read. Reading the configuration twice — once after reset, once after the application has started — resolves the ambiguity, and the difference between the two readings is itself informative.
Writing protection is a separate gate
This family also provides write-protect bits, one per block, and they are independent of the read-protect bits. A device can be read-protected and writable, or readable and write-protected, and the two states lead to different recovery options.
| Writable | Readable | What you can do |
|---|---|---|
| Yes | Yes | Read and rewrite freely |
| Yes | No | Erase and rewrite; original lost |
| No | Yes | Read, and treat the source as a reference |
| No | No | Neither; analysis is behavioural |
The second row is the common production configuration: readable protection removed by erasing. It is also where most accidental losses happen, because an erase looks like the first step of a recovery and is in fact a destruction.
Limits
- Two bits, two halves. There is no finer granularity to work with.
- A fully protected device yields nothing by reading, and the configuration word is the only confirmation available.
- Erasing to remove protection removes the contents with it, on this part more than on any larger one because there is so little to lose.
Related reading
- PIC18F13K22 and the single-bit case — the same silicon without the block split.
- PIC18F13K50 and bootloaders that cannot read their application — why a readable boot block does not imply a readable application.
- PIC18F23K22 and write protection as a separate gate — the second bit that changes what is possible.
FAQ
How many protection bits does this part have? Two, one per half of the array.
Where is the block boundary? At the midpoint of the program memory — for a 16K device, the eight-kilobyte address.
Can a partial read be produced deliberately? Yes, by protecting one block and leaving the other open. That is the bootloader configuration.
Is the configuration word readable when protected? Yes on this family, which is how the protection state is confirmed.
Does write protection hide contents? No. It prevents modification, not reading.
Conclusion
Two bits and one address define everything about what a read of this part can produce. The boundary’s position is the diagnostic: a transition at the midpoint is protection, a transition anywhere else is a different problem. And the sharpest practical warning on the family applies here most of all — erasing to unprotect destroys the very thing the exercise was for.