PIC18F46K80: The Verification Step Is a Map of the Design
A device that can be updated in the field needs a way to decide whether the application it holds is complete. The usual answer is a checksum over a defined range, computed at start-up and compared against a stored value. That is a robustness feature, and it is also the most informative few dozen instructions in the whole image.
The reason is simple: to verify the application, the loader must know where the application begins, where it ends, and what the result should be. Those are exactly the facts a reader wants, and they are stated by code that has to work.
What the verification defines
Four quantities, all of them structural:
- the start address of the application;
- the length, or the end address;
- the algorithm — a simple sum, a CRC, or something more specific;
- where the expected value is stored, and how it is protected against being wrong.
| Quantity | What it tells you | Why it matters |
|---|---|---|
| Start address | Where the application lives | Fixes the memory map |
| Length | Where the application ends | Distinguishes code from trailing constants |
| Algorithm | CRC width and polynomial | Constrains the image, and detects tampering |
| Stored value location | Where the loader keeps its reference | A second place the image is described |
A CRC rather than a checksum is a meaningful detail: it implies the vendor cared about detecting corruption in transit, which in turn implies the update path is used in conditions where corruption is possible.
Why the loader is often readable
The loader must function for updates to work, so it is frequently left writable, and on some products it is left readable as well — particularly where the vendor’s own service tooling reads it back to confirm a version.
Even when it is protected, the loader’s behaviour is observable through the update interface: an identification exchange gives a version, an erase command gives the granularity, and a verification failure gives the range indirectly, because the loader will report a mismatch after a known number of bytes.
That last technique is worth knowing: send an image that is deliberately short and observe where the loader stops or what it reports. The boundary it complains about is the boundary it checks.
Configuring the destination
For replication, the verification step adds a requirement that is easy to miss: the destination image must produce the expected checksum. If the original’s expected value is stored in the loader’s region, and the rebuilt application differs by one byte, the loader will refuse to start it.
Three ways to handle that:
- Rebuild to match, which is impractical for anything but a trivial difference.
- Update the stored expected value, which requires writing to the loader’s region.
- Disable verification, which requires modifying the loader.
On a device where the loader is in a write-protected boot region, none of the three is available without erasing and rewriting the whole device — which is a decision, not a step.
What this tells you about the protection design
A vendor who verifies the application but leaves the loader readable has made a specific trade: reliability over secrecy. A vendor who protects both has chosen secrecy and accepted that field diagnosis is harder.
The pattern of which region is protected, and which is not, is a fairly reliable indicator of how the product was maintained. Products with readable loaders were usually built with a service organisation in mind; products with everything closed were usually built to be replaced.
Reading the application through the loader’s expectations
Once the start address and the length are known, the application’s extent is bounded. That is a small but real advantage during analysis: a disassembly can be limited to the region the loader considers the application, and everything outside it can be treated as loader, configuration or unused.
It also resolves an ambiguity that arises on 64K parts: whether a block of content near the top of the array is application data or an artefact. The loader’s range answers it.
Practical sequence
- Determine whether a loader exists — update interface behaviour, or a boot region in the image.
- Extract the verification parameters: start, length, algorithm.
- Record the expected value and where it lives.
- Bound the application region using those parameters.
- Read the application region if permitted; treat the loader as a separate program.
- For replication, decide how to handle verification before writing anything.
Step six prevents the most common replication failure on these devices: a correctly copied application that will not start because the loader’s stored checksum refers to the original.
Limits
- The verification tells you the application’s extent, not its content.
- A loader that verifies only a portion of the application leaves the remainder unbounded.
- If the expected value is stored in a protected region, it cannot be read, and the checksum can only be inferred by experiment.
Related reading
- PIC18F25K80 and the CAN interface the loader serves — the transport the verification protects.
- PIC18F45K80 and reconstruction from behaviour — where the loader’s bounds become useful constraints.
- PIC18F65K80 and recording the result as a file — how the bounded region is represented.
FAQ
Why do loaders verify the application? Because an interrupted update leaves an incomplete image, and jumping into it is worse than not starting.
Does verification protect the code? No. It detects corruption. Confidentiality comes from the configuration bits.
Can the expected value be read? If it is in an open region, yes. Otherwise it has to be inferred by experiment.
What happens if a copied application fails verification? The loader refuses to transfer control, and the device appears dead while being intact.
Is a CRC always used? No. Simple sums are common, and a sum detects less — which is itself information about how much the vendor worried about corruption.
Conclusion
Verification code is a specification of the memory map written by someone who needed it to be exactly right. Start address, length, algorithm and stored value together bound the application, tell you how the vendor thought about reliability, and predict the failure mode of a copy that ignores them.