host_command.h
/*
* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __HOST_COMMAND_H__
#define __HOST_COMMAND_H__
#include <stdio.h>
#include <stdint.h>
#include "bootloader_common.h"
#include "property/property.h"
#include "packet/serial_packet.h"
#include "blsh.h"
/*******************************************************************************
* Definitions
******************************************************************************/
enum _transfer_mode_type
{
kIdle_mode = 0,
kSPI_mode = 1,
kI2C_mode = 2,
kUART_mode = 3,
kCAN_mode = 4
};
#if DEBUG && !DEBUG_PRINT_DISABLE
static const char *const kCommandNames[] = { "flash-erase-all",
"flash-erase-region",
"read-memory",
"write-memory",
"fill-memory",
"flash-security-disable",
"get-property",
"receive-sb-file",
"execute",
"call",
"reset",
"set-property",
"flash-erase-all-unsecure",
"flash-program-once",
"flash-read-once",
"flash-read-resource",
"configure-quadspi",
"reliable-update",
"flash-image",
"i2c",
"spi",
"can" };
#endif
#pragma pack(1)
typedef struct _command_frame_packet
{
framing_data_packet_t framing_data;
command_packet_t command_data;
uint32_t param[7];
} command_frame_packet_t;
#pragma pack()
#pragma pack(1)
typedef struct _generic_response_frame_packet
{
framing_data_packet_t framing_data;
uint8_t commandTag;
uint8_t flags;
uint8_t reserved;
uint8_t parameterCount;
uint32_t status;
uint32_t param_commandTag;
} generic_response_frame_packet_t;
#pragma pack()
#pragma pack(1)
typedef struct _flash_read_once_response_frame_packet
{
framing_data_packet_t framing_data;
flash_read_once_response_packet_t response;
} flash_read_once_response_frame_packet_t;
#pragma pack()
#pragma pack(1)
typedef struct _property_response_frame_packet
{
framing_data_packet_t framing_data;
get_property_response_packet_t generic_response;
} property_response_frame_packet_t;
#pragma pack()
typedef struct _memory_info
{
bool is_info_reday;
uint32_t flashStart;
uint32_t flashSize;
uint32_t ramStart;
uint32_t ramSize;
uint32_t reservedFlashStart;
uint32_t reservedFlashEnd;
uint32_t reservedRamStart;
uint32_t reservedRamEnd;
uint32_t blankFlashStart;
uint32_t blankFlashSize;
uint32_t blankRamStart;
uint32_t blankRamSize;
} memory_info_t;
typedef struct _write_memory_test_option
{
uint32_t address;
uint32_t writeLength;
uint32_t testTimes;
uint64_t averageCost;
uint32_t averageSpeed;
uint8_t divider;
} write_memory_test_option_t;
typedef struct _command_info
{
bool is_info_reday;
uint32_t cmd_mask;
} command_info_t;
typedef status_t (*transfer_data_t)(uint8_t *data, uint32_t length);
extern transfer_data_t write_serial_data;
extern transfer_data_t read_serial_data;
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
status_t handle_getProperty_command(uint8_t input_param, uint32_t *response_param);
status_t handle_setProperty_command(uint8_t property_tag, uint32_t property_value);
status_t handle_flashEraseAllUnsecure_command(void);
status_t handle_flashEraseAll_command(void);
status_t handle_flashEraseRegion_command(uint32_t start_address, uint32_t erase_bytes);
status_t handle_reset_command(void);
status_t handle_writeMemory_command(uint32_t start_address, uint8_t *buffer, uint32_t length);
status_t handle_readMemory_command(uint32_t start_address, uint8_t *buffer, uint32_t length);
status_t handle_fillMemory_command(uint32_t start_address, uint32_t pattern_word, uint32_t byte_count);
status_t handle_flashSecurityDisable_command(uint32_t backdoorkey_low, uint32_t backdoorkey_high);
status_t handle_execute_command(uint32_t address, uint32_t arg, uint32_t stack_pointer);
status_t handle_call_command(uint32_t address, uint32_t arg);
status_t handle_flashProgramOnce_command(uint32_t index, uint32_t byte_count, uint32_t data1, uint32_t data2);
status_t handle_flashReadOnce_command(uint32_t index, uint32_t byte_count, uint32_t *data1, uint32_t *data2);
status_t handle_flashReadResource_command(uint32_t start_address, uint8_t *buffer, uint32_t length, uint32_t option);
status_t handle_receiveSBFile_command(uint32_t address, uint32_t length);
status_t get_memory_info(memory_info_t *info);
status_t get_command_info(command_info_t *info);
status_t run_ping_command(void);
status_t wait_ping_response(uint8_t try_count);
status_t wait_ack_packet(void);
status_t wait_command_response(generic_response_frame_packet_t *command_response);
void check_transfer_bus(uint8_t transfer_bus, uint32_t *input_freq);
void configure_transfer_bus(uint8_t transfer_bus, uint32_t freq);
#if defined(__cplusplus)
}
#endif /* __cplusplus */
#endif /* __HOST_COMMAND_H__ */
generic_response_frame_packet_t::parameterCount
uint8_t parameterCount
Definition: host_command.h:98
memory_info_t
target memory info
Definition: host_command.h:123
generic_response_frame_packet_t::flags
uint8_t flags
Definition: host_command.h:96
command_packet_t
Command packet format.
Definition: command_packet.h:113
flash_read_once_response_frame_packet_t
generic response packet
Definition: host_command.h:106
get_property_response_packet_t
Get Property response packet format.
Definition: command_packet.h:290
property_response_frame_packet_t
generic response packet
Definition: host_command.h:115
write_memory_test_option_t
memory test options
Definition: host_command.h:143
generic_response_frame_packet_t
generic response packet
Definition: host_command.h:92
generic_response_frame_packet_t::commandTag
uint8_t commandTag
Definition: host_command.h:95
generic_response_frame_packet_t::param_commandTag
uint32_t param_commandTag
Definition: host_command.h:100
flash_read_once_response_packet_t
Flash Read Once response packet format.
Definition: command_packet.h:306
framing_data_packet_t
Serial framing data packet.
Definition: serial_packet.h:106
generic_response_frame_packet_t::reserved
uint8_t reserved
Definition: host_command.h:97
command_frame_packet_t
command packet
Definition: host_command.h:82
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
command_info_t
bootloader command info
Definition: host_command.h:154
generic_response_frame_packet_t::status
uint32_t status
Definition: host_command.h:99