Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
Command Handler

API for the command handler. More...

+ Collaboration diagram for Command Handler:

Data Structures

struct  command_handler_entry_t
 Format of command handler entry. More...
 
struct  command_processor_data_t
 Command processor data format. More...
 
struct  command_interface_t
 Interface to command processor operations. More...
 
struct  config_i2c_cmd_packet_t
 

Enumerations

enum  _command_state {
  kCommandState_CommandPhase,
  kCommandState_DataPhase,
  kCommandState_CommandPhase,
  kCommandState_DataPhase,
  kCommandState_DataPhaseRead,
  kCommandState_DataPhaseWrite
}
 Command state machine states.
 
enum  _secure_commands { kCommandsAllowedWhenSecure }
 
enum  _command_state {
  kCommandState_CommandPhase,
  kCommandState_DataPhase,
  kCommandState_CommandPhase,
  kCommandState_DataPhase,
  kCommandState_DataPhaseRead,
  kCommandState_DataPhaseWrite
}
 Command state machine states.
 
enum  buspal_state_t {
  kBuspal_Idle,
  kBuspal_I2c,
  kBuspal_Spi,
  kBuspal_FlexCAN,
  kBuspal_MsCAN
}
 

Functions

status_t bootloader_command_init (void)
 Initialize the command processor component.
 
status_t bootloader_command_pump (void)
 Pump the command state machine. More...
 
static const command_handler_entry_tfind_entry (uint8_t tag)
 Find command handler entry. More...
 
static status_t handle_command_internal (uint8_t *packet, uint32_t packetLength)
 Handle a command transaction.
 
static uint16_t calculate_framing_crc16 (framing_data_packet_t *packet, const uint8_t *data)
 Calculate crc over framing data packet.
 
static status_t handle_data_read (bool *hasMoreData)
 
static void handle_read_memory_command (uint8_t *packet, uint32_t packetLength)
 
static status_t peripheral_read (uint8_t *dest, uint32_t readLength)
 
static status_t peripheral_write (uint8_t *src, uint32_t writeLength)
 
void handleUsbBusPalCommand ()
 handle USB command
 
static void handle_config_i2c (uint8_t *packet, uint32_t packetLength)
 
static void handle_config_spi (uint8_t *packet, uint32_t packetLength)
 
static void handle_config_can (uint8_t *packet, uint32_t packetLength)
 
static void handle_write_memory_command (uint8_t *packet, uint32_t packetLength)
 
static status_t handle_data_write (bool *hasMoreData)
 

Variables

command_interface_t g_commandInterface
 Default command interface.
 
const command_handler_entry_t g_commandHandlerTable []
 Command handler table.
 
command_processor_data_t g_commandData
 Command processor state data.
 
command_interface_t g_commandInterface
 Default command interface. More...
 
command_processor_data_t g_commandData
 Command processor state data.
 
buspal_state_t g_buspalState = kBuspal_Idle
 
uint8_t g_targetRxBuffer [64]
 
command_interface_t g_commandInterface
 Default command interface.
 

State machine

static status_t handle_command (uint8_t *packet, uint32_t packetLength)
 Handle a command transaction.
 
static status_t handle_data (bool *hasMoreData)
 Handle a data transaction.
 

Command handlers

void handle_reset (uint8_t *packet, uint32_t packetLength)
 Reset command handler.
 
void handle_flash_erase_all (uint8_t *packet, uint32_t packetLength)
 Flash Erase All command handler.
 
void handle_flash_erase_all_unsecure (uint8_t *packet, uint32_t packetLength)
 Flash Erase All Unsecure command handler.
 
void handle_flash_erase_region (uint8_t *packet, uint32_t packetLength)
 Flash Erase Region command handler.
 
void handle_receive_sb_file (uint8_t *packet, uint32_t packetLength)
 Receive SB File command handler.
 
void handle_read_memory (uint8_t *packet, uint32_t packetLength)
 Read Memory command handler.
 
void handle_fill_memory (uint8_t *packet, uint32_t packetLength)
 Fill Memory command handler.
 
void handle_set_property (uint8_t *packet, uint32_t packetLength)
 Set Property command handler.
 
void handle_get_property (uint8_t *packet, uint32_t packetLength)
 Get Property command handler.
 
void handle_write_memory (uint8_t *packet, uint32_t packetLength)
 Write Memory command handler.
 
void handle_execute (uint8_t *packet, uint32_t packetLength)
 Execute command handler.
 
void handle_call (uint8_t *packet, uint32_t packetLength)
 Call command handler.
 
void handle_flash_security_disable (uint8_t *packet, uint32_t packetLength)
 Flash Security Disable command handler.
 
void handle_flash_program_once (uint8_t *packet, uint32_t length)
 Flash Program Once command handler.
 
void handle_flash_read_once (uint8_t *packet, uint32_t length)
 Flash Read Once command handler.
 
void handle_flash_read_resource (uint8_t *packet, uint32_t length)
 Flash Read Resource command handler.
 
void handle_configure_quadspi (uint8_t *packet, uint32_t packetLength)
 Configure QuadSpi command handler.
 
void handle_reliable_update (uint8_t *packet, uint32_t packetLength)
 Reliable Update command handler.
 

Command responses

void send_read_memory_response (uint32_t commandStatus, uint32_t length)
 Send a read memory response packet.
 
void send_generic_response (uint32_t commandStatus, uint32_t commandTag)
 Send a generic response packet.
 
void send_get_property_response (uint32_t commandStatus, uint32_t *value, uint32_t numValues)
 Send a get property response packet.
 
void send_flash_read_once_response (uint32_t commandStatus, uint32_t *value, uint32_t byteCount)
 Send a flash read once resposne packet.
 
void send_flash_read_resource_response (uint32_t commandStatus, uint32_t length)
 Send a flash read resource memory response packet.
 

Data phase

static void reset_data_phase ()
 Reset data phase variables.
 
void finalize_data_phase (status_t status)
 Complete the data phase, optionally send a response.
 
status_t handle_data_producer (bool *hasMoreData)
 Handle data phase with data producer (send to host).
 
status_t handle_data_consumer (bool *hasMoreData)
 Handle data phase with data consumer (read from host).
 

Usage Information

API for the command handler.


Data Structure Documentation

struct command_handler_entry_t

Format of command handler entry.

Data Fields

void(* handleCommand )(uint8_t *packet, uint32_t packetLength)
 
status_t(* handleData )(bool *hasMoreData)
 
struct command_processor_data_t

Command processor data format.

+ Collaboration diagram for command_processor_data_t:

Public Member Functions

 CommandProcessorData ()
 Pointer to handler table entry for packet in process.
 

Data Fields

int32_t state
 Current state machine state.
 
uint8_t * packet
 Pointer to packet in process.
 
uint32_t packetLength
 Length of packet in process.
 
struct command_processor_data_t::DataPhase dataPhase
 
const command_handler_entry_thandlerEntry
 
struct command_interface_t

Interface to command processor operations.

+ Collaboration diagram for command_interface_t:

Data Fields

status_t(* init )(void)
 
status_t(* pump )(void)
 
const command_handler_entry_thandlerTable
 
command_processor_data_tstateData
 
struct config_i2c_cmd_packet_t
+ Collaboration diagram for config_i2c_cmd_packet_t:
Data Fields
uint32_t address Parameter 0: i2c slave address.
command_packet_t commandPacket header
uint32_t speed Parameter 1: i2c speed in kHz.

Enumeration Type Documentation

Enumerator
kCommandsAllowedWhenSecure 

Bitmask of commands allowed when flash security is enabled.

This bitmask uses the same format as the AvailableCommands property. This is, the bit number for a given command is the command's tag value minus one.

Function Documentation

status_t bootloader_command_pump ( void  )

Pump the command state machine.

Executes one command or data phase transaction.

static const command_handler_entry_t* find_entry ( uint8_t  tag)
static

Find command handler entry.

Return values
NULLif no entry found.

Variable Documentation

command_interface_t g_commandInterface
Initial value:
const command_handler_entry_t g_commandHandlerTable[]
Command handler table.
Definition: bl_command.c:127
Format of command handler entry.
Definition: bl_command.h:49
command_processor_data_t g_commandData
Command processor state data.
Definition: bl_command.c:204
status_t bootloader_command_pump(void)
Pump the command state machine.
Definition: bl_command.c:224
status_t bootloader_command_init(void)
Initialize the command processor component.
Definition: bl_command.c:215

Default command interface.