Every ECU software update, in the factory, at a dealer or over the air, ends in the same few UDS services: open a download, send the image in blocks, close the download. Around them sits a sequence that prepares the vehicle and checks the result. ISO 14229-1 defines the services. The exact order, the routines and the security algorithm belong to each manufacturer, and their bootloader specifications define them. This guide shows the common shape and the bytes that do not change.

A typical sequence

StepRequestPurposeDefined by
110 03Extended diagnostic sessionISO 14229-1
231 01 xx xxCheck programming preconditions (speed 0, voltage OK)Manufacturer routine
385 02 (functional)Stop all ECUs storing DTCs while the bus is disturbedISO 14229-1
428 03 01 (functional)Stop normal transmit and receive on other ECUsISO 14229-1
510 02Programming session; the ECU often restarts into its bootloaderISO 14229-1
627 01 / 27 02 (example level)Security access: request seed, send keyISO 14229-1 service, manufacturer algorithm and level
72E xx xx ...Write a fingerprint: who programmed, whenManufacturer DID
831 01 FF 00 ...Erase the memory areaISO 14229-1 routine 0xFF00 eraseMemory
934 ...RequestDownload: address, size, formatISO 14229-1
1036 01 ... to 36 nn ...TransferData blocksISO 14229-1
1137RequestTransferExitISO 14229-1
1231 01 FF 01Check programming dependencies: CRC, signature, compatibilityISO 14229-1 routine 0xFF01
1311 01Hard reset into the new applicationISO 14229-1
1428 00 01, 85 01 (functional)Restore communication and DTC settingISO 14229-1

Steps 8 to 11 repeat for each memory area, for example once for the application and once for calibration data. Steps 3, 4 and 14 go to the functional address so that every ECU on the network hears them.

Step by step

Sessions and security

10 02 switches to the programming session. Some ECUs answer, reset, and come back running their bootloader, so expect a short silence and do not treat it as a failure. Programming services are usually locked behind security access: 27 with an odd sub-function requests a seed, and 27 with the next even sub-function sends the key calculated from it. Which level, and how the key is calculated, is the manufacturer's secret. A wrong key returns 7F 27 35 (invalidKey); too many wrong keys return 7F 27 36 (exceedNumberOfAttempts), and after that 7F 27 37 (requiredTimeDelayNotExpired) until a lockout delay has passed.

Erase

31 01 FF 00 starts the eraseMemory routine. Its parameters, usually the address and size of the area, are manufacturer-defined. Erasing flash takes time, so the ECU typically answers 7F 31 78 (responsePending) until it is done. Keep waiting; each 78 restarts the longer P2* timeout.

RequestDownload: 0x34

Example
34 00 44 00 02 00 00 00 10 00 00
BytesFieldValue
34ServiceRequestDownload
00dataFormatIdentifierHigh nibble compression, low nibble encryption; 00 = neither
44addressAndLengthFormatIdentifierHigh nibble: size is 4 bytes; low nibble: address is 4 bytes
00 02 00 00memoryAddress0x00020000
00 10 00 00memorySize0x00100000 = 1 MiB

The positive answer tells you how big each TransferData request may be:

Example
74 20 0F FA

20: the high nibble says the length that follows is 2 bytes. 0F FA = 4090 is maxNumberOfBlockLength, and it includes the 36 service byte and the counter. So each TransferData carries at most 4088 bytes of image.

TransferData: 0x36

Example
36 01 <4088 bytes>     76 01
36 02 <4088 bytes>     76 02
...
36 FF <4088 bytes>     76 FF
36 00 <4088 bytes>     76 00

The block sequence counter starts at 01, increases by one per block, and wraps from FF to 00, not to 01. The ECU echoes it in the positive response. If a response is lost and you repeat the same block with the same counter, the ECU must accept it; a counter that skips ahead returns 7F 36 73 (wrongBlockSequenceCounter).

RequestTransferExit: 0x37

37 closes the download, and 77 confirms it. Then 31 01 FF 01 (checkProgrammingDependencies) asks the bootloader to verify what it received, for example a CRC or a signature, and whether the new software fits the hardware and other software parts. In a typical bootloader, only a passed check marks the application valid, and 11 01 then starts it.

The download loop in Python

These functions build the requests and split the image. They work with any transport that has a request(bytes) -&gt; bytes method, such as the ISO-TP link from the UDS DID scanning guide:

Python
def request_download(address, size, address_bytes=4, size_bytes=4, data_format=0x00):
    """34 request: data format (compression/encryption), then address and size with their lengths."""
    length_format = size_bytes << 4 | address_bytes
    return (bytes([0x34, data_format, length_format])
            + address.to_bytes(address_bytes, "big") + size.to_bytes(size_bytes, "big"))


def max_block_length(response):
    """74 response: high nibble of byte 1 = number of bytes in maxNumberOfBlockLength."""
    if response[0] != 0x74:
        raise ValueError(f"RequestDownload refused: {response.hex(' ')}")
    count = response[1] >> 4
    return int.from_bytes(response[2:2 + count], "big")


def transfer_requests(image, max_length):
    """36 requests. max_length includes the SID and the counter, so each carries max_length - 2 bytes."""
    chunk = max_length - 2
    for index, start in enumerate(range(0, len(image), chunk)):
        counter = (index + 1) & 0xFF  # starts at 1, wraps from 0xFF to 0x00
        yield bytes([0x36, counter]) + image[start:start + chunk]


print(request_download(0x0002_0000, 0x0010_0000).hex(" "))
limit = max_block_length(bytes.fromhex("74 20 0F FA"))
blocks = list(transfer_requests(bytes(0x0010_0000), limit))
print(f"max block length {limit}, {len(blocks)} TransferData requests, "
      f"counters {blocks[0][1]:02X} ... {blocks[254][1]:02X}, {blocks[255][1]:02X}, {blocks[256][1]:02X}")

Output:

Example
34 00 44 00 02 00 00 00 10 00 00
max block length 4090, 257 TransferData requests, counters 01 ... FF, 00, 01

A 1 MiB image needs 257 blocks, so the counter wraps once. Then the loop, tested against a simulated bootloader that checks the counter the way a real one does:

Python
class FakeBootloader:
    """Accepts one download and checks the block sequence counter, like a real server."""

    def __init__(self):
        self.memory, self.expected, self.size = bytearray(), None, 0

    def request(self, payload):
        sid = payload[0]
        if sid == 0x34:
            self.size = int.from_bytes(payload[7:11], "big")
            self.expected = 1
            return bytes.fromhex("74 20 0F FA")
        if sid == 0x36:
            if payload[1] != self.expected:
                return bytes([0x7F, 0x36, 0x73])  # wrongBlockSequenceCounter
            self.memory += payload[2:]
            self.expected = (self.expected + 1) & 0xFF
            return bytes([0x76, payload[1]])
        if sid == 0x37:
            return b"\x77" if len(self.memory) == self.size else bytes([0x7F, 0x37, 0x24])
        return bytes([0x7F, sid, 0x11])


def download(link, address, image):
    limit = max_block_length(link.request(request_download(address, len(image))))
    for request in transfer_requests(image, limit):
        reply = link.request(request)
        if reply[:2] != bytes([0x76, request[1]]):
            raise RuntimeError(f"block {request[1]:02X} failed: {reply.hex(' ')}")
    exit_reply = link.request(b"\x37")
    if exit_reply[:1] != b"\x77":
        raise RuntimeError(f"RequestTransferExit failed: {exit_reply.hex(' ')}")


ecu = FakeBootloader()
image = bytes(range(256)) * 4096  # 1 MiB test pattern
download(ecu, 0x0002_0000, image)
print("received", len(ecu.memory), "bytes, identical:", bytes(ecu.memory) == image)

Output:

Example
received 1048576 bytes, identical: True

A real tool also needs the session, security and erase steps before this, handling of 7F xx 78 on every request, and a timeout and retry policy agreed with the bootloader's specification.

How long it takes on CAN

Each 4090-byte TransferData travels as one ISO-TP first frame and 584 consecutive frames, plus a flow control frame and the response. For the 1 MiB image above that is about 150 600 frames. A classical CAN frame with 8 data bytes and an 11-bit ID is 111 bits before stuffing and up to 135 with worst-case stuffing, so at 500 kbit/s and 100 % bus load the transfer alone takes about 33 to 41 seconds. STmin gaps between frames, erase time and the dependency check come on top. This is one reason ECUs with large images are often flashed over CAN FD or DoIP, where each frame carries far more data.

When it fails

ResponseMeaningUsual cause
7F 34 22conditionsNotCorrectPreconditions not met: wrong session, speed, voltage
7F 34 33securityAccessDeniedSecurity access not done or not at the right level
7F 34 70uploadDownloadNotAcceptedAddress or size outside what the bootloader allows, or memory not erased
7F 36 73wrongBlockSequenceCounterA block was skipped
7F 36 71transferDataSuspendedThe transfer was stopped by a fault
7F 36 72generalProgrammingFailureWriting the flash failed
7F 37 24requestSequenceErrorExit sent before all announced bytes arrived

Frequently asked questions

What is the UDS flashing sequence?

The core is RequestDownload (0x34), TransferData (0x36) in blocks, and RequestTransferExit (0x37). Before it come the programming session (10 02), security access (0x27) and erasing (31 01 FF 00); after it the dependency check (31 01 FF 01) and a reset (11 01). The exact order and routines are defined by each manufacturer.

What is maxNumberOfBlockLength?

The largest TransferData request the ECU accepts, returned in the RequestDownload response. It includes the 0x36 service byte and the block sequence counter, so the data per block is two bytes less.

Does the UDS block sequence counter start at 0 or 1?

At 1. It increases by one for each TransferData request and wraps from 0xFF to 0x00. Repeating the previous block with the same counter is allowed, so a tool can resend after a lost response.

Why does the ECU answer 7F 31 78 during erase?

0x78 is responsePending. Erasing flash takes longer than the normal response time, so the ECU tells the tester to wait. The final answer follows within the extended P2* time.

References