The Programming Port Permission Matrix: Read, Write, Erase, Debug
A datasheet describes memory protection as a bit. The interface implements four permissions. Treating them as one is the source of most of the confusion in this area, and of one design mistake that is genuinely dangerous.
The four permissions are read, write, erase and debug. They can be granted and withheld independently in principle, and every combination of granted and withheld has appeared in a shipping product. A few of those combinations are sound. One of them is worse than leaving the device completely open, and it is common.
What each permission actually controls
Reading means reading out the contents of the program memory through the interface. On some parts it is a single command; on others it is a side effect of entering debug mode and dumping memory.
Writing means programming a location that is currently erased. It does not imply being able to erase, and on most parts writing over a non-erased location is refused or produces a bitwise AND of old and new.
Erasing means returning a block or the whole array to the erased state. This is the permission that matters most, because on an overwhelming majority of parts it is the only way to clear a protection that forbids reading.
Debugging means attaching a debugger that can halt the core, read registers and execute arbitrary instructions. It is not a memory permission at all — it is a permission to run code — and it therefore subsumes every other permission. A device that allows debug and forbids read does not forbid read.
| Permission | What it grants | Implications |
|---|---|---|
| Read | Dump the array | Direct confidentiality loss |
| Write | Program erased locations | Content injection |
| Erase | Clear blocks or the whole array | Enables every other operation |
| Debug | Halt and execute | Bypasses all three above |
The fourth row is the one that makes the matrix collapse. Debug access is equivalent to physical possession, because code running on the core can read anything the core can read. Any protection scheme that leaves debug enabled is a scheme whose read protection is decorative.
The four implementations
Each permission is enforced by one of four mechanisms, and the mechanism decides whether the restriction is reversible.
| Implementation | Reversible | Typical use |
|---|---|---|
| Configuration fuse | No | Permanent read protection |
| Password or key | Yes, with the password | Service access |
| Debug lock bits | Yes, by mass erase | Development to production |
| Physical cut or removed pad | No | Highest grade parts |
The third row is the standard production mechanism: the debug lock is set at the end of the line, and clearing it requires a mass erase, which removes the contents. That is a deliberate coupling of two permissions, and it is the reason “unlock and keep the data” is usually a contradictory request.
The first row is the strongest and is the one customers most often misunderstand. A fuse that permanently disables read is not a lock that can be picked; it is a statement that the contents will never be readable through the interface, and the only route becomes physical. That is why parts with permanent fuses are cheap to protect and expensive to recover.
The dangerous combination
Granting write and erase while withholding read is a specific combination that appears in firmware update schemes, and it deserves its own discussion.
The intent is clear: the field engineer must be able to reprogram the device but must not be able to extract the code. The first half works. The second half does not, because write and erase together with no read gives an attacker the ability to replace the firmware with his own.
Consider what that means. The attacker cannot read the secret, but he can install code that reads it and transmits it. The installed code runs with full privileges, and the original protection no longer applies to it because the protection was enforced on the interface rather than on the core. One upload and one boot later, the secret is on a serial port.
| Combination | Confidentiality | Integrity | Verdict |
|---|---|---|---|
| Read off, write off, erase off | Good | Good | Sound |
| Read off, write off, erase on | Weak | Weak | Erase defeats it |
| Read off, write on, erase on | None | None | Worse than open |
| Read on, write off, erase off | None | Good | Usable where secrecy is not required |
The third row is the one to avoid, and it is worth being precise about why it is worse than an unprotected device. An unprotected device is obviously unprotected; a design that appears protected but accepts arbitrary firmware gives a false assurance that survives until the first incident.
The mitigation is authentication of the uploaded image. If the bootloader verifies a signature before accepting an update, write access no longer implies content control. That is the mechanism described in secure boot, and it is the only thing that makes a write-enabled, read-disabled port safe.
The interface nobody documents
Every permission map built from a datasheet is incomplete, because the datasheet documents the interfaces the vendor expects the customer to use. The interfaces the vendor uses internally are documented somewhere else, or nowhere.
Three of them recur.
The factory test mode is entered by a pin combination at power-up, or by a specific sequence on an existing interface. In test mode the part typically ignores the protection bits entirely, because the test programme needs to read and write everything. This mode is the single largest gap in most protection schemes, and it is not mentioned in any customer-facing document.
Boundary scan, where present, exposes every pin’s state and every boundary register. It is not a memory interface, so it does not read flash, but it can drive the pins that enter test mode and it can observe the pins that carry data. A device with boundary scan enabled in production has an interface that its designer probably did not consider.
The boot ROM’s recovery path is the third. Many parts have a ROM routine that accepts an image over a serial line when a specific condition holds — a blank device, a corrupted checksum, a particular pin state. That routine exists so that a bricked device can be recovered at the factory, and it usually runs before the protection check because the protection check lives in the flash it is trying to recover.
| Undocumented interface | How it is entered | Permission it typically grants |
|---|---|---|
| Factory test mode | Pin combination at power-up | Full read and write |
| Boundary scan | JTAG instruction | Pin observation and control |
| Boot ROM recovery | Blank or corrupt device | Write, sometimes read |
| Debug mailbox | Register write from the core | Whatever the core can do |
The fourth row is the one that matters when the core is already running attacker code. A mailbox that lets the core request a debug operation is a permission that depends on who is asking, and a protection scheme that trusts the core’s identity has no protection at all.
Why erase is coupled to read
On most parts the protection bit can only be cleared by a mass erase of the whole array. This is not an implementation shortcut; it is a deliberate design decision, because a protection that can be cleared without losing the contents protects nothing.
The consequence is that protection converts confidentiality into availability. A protected device is not a device whose contents are secret; it is a device whose contents are secret or destroyed. Anyone who can clear the protection can destroy the data, and anyone who wants the data must find a route that does not clear it.
This reframing is useful in assessment because it changes what the attacker is looking for. The question is not “how do I remove the protection” but “is there any route that reads without clearing”. Three such routes exist: a debug path that bypasses the protection check, a fault injection that corrupts the check, and a physical read of the array. Each is a different project, and the first is the one that most often turns out to exist.
Mapping a real device
Building the matrix for a specific part takes an afternoon and produces a document that answers most subsequent questions.
The first step is to enumerate the interfaces. A modern part may have a debug port, an ISP bootloader, a factory test interface and a boundary-scan chain, and each has its own permission model. The datasheet documents the first two and usually omits the last two.
The second step is to determine which permissions each interface honours. A debug port that refuses memory reads but allows register access is not read-protected, because registers can be used to reach memory. An ISP bootloader that refuses a read command may still allow a verify command that returns a comparison result, which is a slow read channel.
The third step is to test the coupling between permissions on a sacrificial unit. Set the protection, attempt each operation, and record which ones succeed and which ones return an error rather than failing silently. Silent failure is common and is the reason a permission map built from datasheets alone is unreliable.
| Interface | Documented | Usually present | Frequently omitted |
|---|---|---|---|
| Debug port | Yes | Yes | Register-level access |
| ISP bootloader | Yes | Sometimes | Verify command as read channel |
| Factory test mode | Rarely | Sometimes | Full memory access |
| Boundary scan | No | Sometimes | Pin state and register access |
What the assessment provides
The deliverable for this layer is a permission map: for each interface, which of the four operations succeed, which fail loudly, which fail silently, and which are coupled. It is produced from the datasheet, from the part’s behaviour on a bench, and from a sacrificial unit where the protection is deliberately set.
That map is what turns a recovery request into a route. Where read is genuinely absent from every interface and erase is the only path, the physical route in extracting IC flash is the answer. Where a debug path exists that honours read despite the protection bit, the route is a read. Where the protection is a conditional branch evaluated at boot, the route is fault injection, whose feasibility is discussed in glitch attacks as a search problem. Where the protection is layered rather than single, the ordering between layers decides which layer to attack, which is the subject of three protection layers.
The one conclusion worth stating in advance is that a part with write enabled and read disabled is not protected, and a customer who has deployed such a scheme should hear that before a recovery is requested rather than after.