wire_format — Wire format¶
This module describes the “wire” format used to communicate between the user space tools and the punchboot bootloader.
Source code: include/pb-tools/wire.h, lib/wire.c
Punch BOOT
Copyright (C) 2020 Jonas Blixt jonpe960@gmail.com
SPDX-License-Identifier: BSD-3-Clause
This file contains the ‘wire’ format for the punchboot bootloader. The various structs and defines are used for sending data between host and device.
Generally a struct pb_command is sent from the host and the device is expected to respond with a struct pb_result.
Additional read/writes are optional but must always be terminated by sending a struct pb_result
The pb_commands enum encodes all of the available commands.
Defines
-
PB_WIRE_MAGIC¶
Magic number present in all the command and result headers.
-
PB_COMMAND_REQUEST_MAX_SIZE¶
Maximum number of bytes that can be embedded in a command request
-
PB_RESULT_RESPONSE_MAX_SIZE¶
Maximum number of bytes that can be embedded in a response result
-
PB_WIRE_PART_FLAG_BOOTABLE¶
The partition is bootable
-
PB_WIRE_PART_FLAG_OTP¶
The partition can only be written once
-
PB_WIRE_PART_FLAG_WRITABLE¶
The partition is writeable
-
PB_WIRE_PART_FLAG_ERASE_BEFORE_WRITE¶
The partition must be erased before any write operation
Enums
-
enum pb_auth_method¶
The punchboot protocol support two different methods of authentication. The device may choose to implement more then one.
Values:
-
enumerator PB_AUTH_INVALID¶
Invalid, guard
-
enumerator PB_AUTH_ASYM_TOKEN¶
Use a signature based authentication token
-
enumerator PB_AUTH_PASSWORD¶
Use a password based authentication
-
enumerator PB_AUTH_INVALID¶
-
enum pb_commands¶
Punchboot commands
Values:
-
enumerator PB_CMD_INVALID¶
-
enumerator PB_CMD_DEVICE_RESET¶
-
enumerator PB_CMD_DEVICE_IDENTIFIER_READ¶
-
enumerator PB_CMD_DEVICE_READ_CAPS¶
-
enumerator PB_CMD_SLC_SET_CONFIGURATION¶
-
enumerator PB_CMD_SLC_SET_CONFIGURATION_LOCK¶
-
enumerator PB_CMD_SLC_SET_EOL¶
-
enumerator PB_CMD_SLC_REVOKE_KEY¶
-
enumerator PB_CMD_SLC_READ¶
-
enumerator PB_CMD_BOOTLOADER_VERSION_READ¶
-
enumerator PB_CMD_PART_TBL_READ¶
-
enumerator PB_CMD_PART_TBL_INSTALL¶
-
enumerator PB_CMD_PART_VERIFY¶
-
enumerator PB_CMD_PART_ACTIVATE¶
-
enumerator PB_CMD_PART_BPAK_READ¶
-
enumerator PB_CMD_PART_ERASE¶
-
enumerator PB_CMD_AUTHENTICATE¶
-
enumerator PB_CMD_AUTH_SET_OTP_PASSWORD¶
-
enumerator PB_CMD_STREAM_INITIALIZE¶
-
enumerator PB_CMD_STREAM_PREPARE_BUFFER¶
-
enumerator PB_CMD_STREAM_WRITE_BUFFER¶
-
enumerator PB_CMD_STREAM_FINALIZE¶
-
enumerator PB_CMD_BOOT_PART¶
-
enumerator PB_CMD_BOOT_RAM¶
-
enumerator PB_CMD_BOARD_COMMAND¶
-
enumerator PB_CMD_BOARD_STATUS_READ¶
-
enumerator PB_CMD_STREAM_READ_BUFFER¶
-
enumerator PB_CMD_PART_RESIZE¶
-
enumerator PB_CMD_BOOT_STATUS¶
-
enumerator PB_CMD_END¶
-
enumerator PB_CMD_INVALID¶
Functions
-
int pb_wire_init_command(struct pb_command *command, enum pb_commands command_code)¶
Initializes and resets a command structure. The magic value is populated and the command code is set.
- Parameters
command – [out] Pointer to a command structure
command_code – [in] The actual command code
- Returns
PB_RESULT_OK on success or a negative number on errors
-
int pb_wire_init_command2(struct pb_command *command, enum pb_commands command_code, void *data, size_t size)¶
Initializes and resets a command structure. The magic value is populated, the command code is set and the request array is populated with data.
- Parameters
command – [out] Pointer to a command structure
command_code – [in] The actual command code
data – [in] Pointer to data that will be stored in the request array
size – [in] Number of bytes of data
- Returns
PB_RESULT_OK on success or a negative number on errors
-
int pb_wire_init_result(struct pb_result *result, enum pb_results result_code)¶
Initializes and resets a result structure. The magic value is populated and the result code is set.
- Parameters
result – [out] pointer to a pb_result structure
result_code – [in] The result code
- Returns
PB_RESULT_OK on success or a negative number on errors
-
int pb_wire_init_result2(struct pb_result *result, enum pb_results result_code, void *data, size_t size)¶
Initializes and resets a result structure. The magic value is populated and the result code is set.
- Parameters
result – [out] pointer to a pb_result structure
result_code – [in] The result code
data – [in] Pointer to data that will be stored in the response array
size – [in] size in bytes of the data
- Returns
PB_RESULT_OK on success or a negative number on errors
-
bool pb_wire_valid_command(struct pb_command *command)¶
Checks that a command is valid and contains the correct magic number
- Parameters
command – [in] The command to check
- Returns
True on if the command is valid or false if not
-
bool pb_wire_valid_result(struct pb_result *result)¶
Checks that a result is valid and contains the correct magic number
- Parameters
result – [in] The result to check
- Returns
True on if the result is valid or false if not
-
bool pb_wire_requires_auth(struct pb_command *command)¶
Checks if a command requires the user to authenticate before issuing the command.
- Parameters
command – [in] The command to check
- Returns
True if the command requires an authenticated session
-
const char *pb_wire_command_string(enum pb_commands cmd)¶
Translates a punchboot command to a textual representation
- Parameters
cmd – [in] The command
- Returns
a string or “”
-
struct pb_command¶
- #include <wire.h>
Punchboot command structure (64 bytes)
Alignment: 64 bytes
-
struct pb_result¶
- #include <wire.h>
Punchboot command result (64 bytes)
Alignment: 64 Bytes
-
struct pb_result_device_caps¶
- #include <wire.h>
Device capabilities
Public Members
-
uint8_t stream_no_of_buffers¶
Number of stream buffers
-
uint32_t stream_buffer_size¶
Size of stream buffers in bytes
-
uint16_t operation_timeout_ms¶
Generic operation timeout
-
uint16_t part_erase_timeout_ms¶
Maximum erase time for a partition
-
uint8_t bpak_stream_support¶
Set to 1 if the device supports receiving concatenated bpak archives
-
uint32_t chunk_transfer_max_bytes¶
Maximum number of bytes in one transfer
-
uint8_t rz[18]¶
Reserved
-
uint8_t stream_no_of_buffers¶
-
struct pb_result_part_table_read¶
- #include <wire.h>
Read partition table response
-
struct pb_result_part_table_entry¶
-
struct pb_command_stream_initialize¶
- #include <wire.h>
Initialize streaming to or from a partition
-
struct pb_command_stream_prepare_buffer¶
- #include <wire.h>
Prepare buffer to receive data
This command must always be followd by a data transfer corresponding the size field.
-
struct pb_command_stream_write_buffer¶
- #include <wire.h>
Write data from an internal buffer to a partition
-
struct pb_command_stream_read_buffer¶
- #include <wire.h>
Read data from a partition to an internal buffer
This command does not need a prepare_buffer CMD before it.
-
struct pb_command_authenticate¶
- #include <wire.h>
Authentication command
The authentication command must be followed by a write opertion by the host that contains the authentication data.
-
struct pb_command_verify_part¶
- #include <wire.h>
Verify partition
The device computes a sha256 hash and compares with the input hash
-
struct pb_command_activate_part¶
- #include <wire.h>
Activate bootable partition command
-
struct pb_command_read_bpak¶
- #include <wire.h>
Read BPAK header command
If the last 4kByte of the partition contains a valid bpak header the header is sent to the host using this command.
-
struct pb_command_erase_part¶
- #include <wire.h>
Erase partition command
-
struct pb_command_resize_part¶
- #include <wire.h>
Resize partition command
-
struct pb_command_install_part_table¶
- #include <wire.h>
Install default partition table
-
struct pb_result_device_identifier¶
- #include <wire.h>
Read device identifier
-
struct pb_result_slc¶
- #include <wire.h>
Security Life Cycle (SLC) result
-
struct pb_result_slc_key_status¶
- #include <wire.h>
Active/Revoked keys result
-
struct pb_command_revoke_key¶
- #include <wire.h>
Revoke key command
-
struct pb_command_boot_part¶
- #include <wire.h>
Boot from partition command
-
struct pb_command_ram_boot¶
- #include <wire.h>
Ram boot command
A bpak image is transfered to ram and executed
-
struct pb_command_board¶
- #include <wire.h>
Board specific command
This optional command, when called will run a function in the board module that can be unique for a board.
-
struct pb_result_board¶
- #include <wire.h>
The result structure for the board command
-
struct pb_result_board_status¶
- #include <wire.h>
Board status result
-
struct pb_result_boot_status¶
- #include <wire.h>
Boot status result