Add KBOOT.
This commit is contained in:
176
src/blsh/bllibc.c
Normal file
176
src/blsh/bllibc.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "bllibc.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
uint32_t bl_strstart(uint8_t *dst, uint8_t *src)
|
||||
{
|
||||
while (*src && (*src == *dst))
|
||||
{
|
||||
src++;
|
||||
dst++;
|
||||
}
|
||||
|
||||
if ((*src == ' ') || (*src == 0))
|
||||
{
|
||||
if (*dst == 0)
|
||||
return k_fullMatch;
|
||||
else
|
||||
return k_partMatch;
|
||||
}
|
||||
else
|
||||
return k_unmatch;
|
||||
}
|
||||
|
||||
bool bl_atoi(uint32_t *dst, uint8_t *str)
|
||||
{
|
||||
int32_t ishex = 0;
|
||||
uint32_t ret = 0;
|
||||
|
||||
if (*str == 0)
|
||||
return 0;
|
||||
|
||||
if ((*str == '0') && (*(str + 1) == 'x'))
|
||||
{
|
||||
ishex = 1;
|
||||
str += 2;
|
||||
}
|
||||
|
||||
while (*str)
|
||||
{
|
||||
if (ishex)
|
||||
ret *= 16;
|
||||
else
|
||||
ret *= 10;
|
||||
|
||||
if ((*str >= '0') && (*str <= '9'))
|
||||
{
|
||||
ret += *str - '0';
|
||||
}
|
||||
else if (ishex && (*str >= 'a') && (*str <= 'f'))
|
||||
{
|
||||
ret += *str - 'a' + 10;
|
||||
}
|
||||
else if (ishex && (*str >= 'A') && (*str <= 'F'))
|
||||
{
|
||||
ret += *str - 'A' + 10;
|
||||
}
|
||||
else if (*str == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst = 0;
|
||||
return false;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
*dst = ret;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *bl_litoa(int64_t num)
|
||||
{
|
||||
int32_t sign = num;
|
||||
int32_t i = 0;
|
||||
int32_t j = 0;
|
||||
uint8_t temp[100];
|
||||
static uint8_t str[100];
|
||||
|
||||
if (sign < 0)
|
||||
{
|
||||
num = -num;
|
||||
}
|
||||
do
|
||||
{
|
||||
temp[i] = num % 10 + '0';
|
||||
num /= 10;
|
||||
i++;
|
||||
} while (num > 0);
|
||||
if (sign < 0)
|
||||
{
|
||||
temp[i++] = '-';
|
||||
}
|
||||
temp[i] = '\0';
|
||||
i--;
|
||||
while (i >= 0)
|
||||
{
|
||||
str[j] = temp[i];
|
||||
j++;
|
||||
i--;
|
||||
}
|
||||
str[j] = '\0';
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static uint8_t bl_htoi(uint8_t hex)
|
||||
{
|
||||
if ((hex >= '0') && (hex <= '9'))
|
||||
{
|
||||
return hex - '0';
|
||||
}
|
||||
else if ((hex >= 'a') && (hex <= 'f'))
|
||||
{
|
||||
return 10 + hex - 'a';
|
||||
}
|
||||
else if ((hex >= 'A') && (hex <= 'F'))
|
||||
{
|
||||
return 10 + hex - 'A';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t read_hex_byte(uint8_t *buffer, uint32_t index)
|
||||
{
|
||||
uint8_t char_high = buffer[index];
|
||||
uint8_t char_low = buffer[index + 1];
|
||||
|
||||
return (bl_htoi(char_high) << 4) | (bl_htoi(char_low));
|
||||
}
|
||||
75
src/blsh/bllibc.h
Normal file
75
src/blsh/bllibc.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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 __BLLIBC_H__
|
||||
#define __BLLIBC_H__
|
||||
|
||||
#include "bootloader_common.h"
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief similarity of two strings
|
||||
*/
|
||||
enum
|
||||
{
|
||||
k_nullMatch,
|
||||
k_fullMatch,
|
||||
k_partMatch,
|
||||
k_unmatch,
|
||||
k_match,
|
||||
k_ambig
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @brief return similarity of two strings start part
|
||||
*/
|
||||
uint32_t bl_strstart(uint8_t *dst, uint8_t *src);
|
||||
|
||||
/*! @brief string to integer */
|
||||
bool bl_atoi(uint32_t *dst, uint8_t *str);
|
||||
|
||||
/*! @brief long integer to string */
|
||||
uint8_t *bl_litoa(int64_t num);
|
||||
|
||||
/*! @brief read a hex byte from two char */
|
||||
uint8_t read_hex_byte(uint8_t *buffer, uint32_t index);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __BLLIBC_H__ */
|
||||
364
src/blsh/blsh.c
Normal file
364
src/blsh/blsh.c
Normal file
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "blsh.h"
|
||||
#include "bllibc.h"
|
||||
#include "host_hardware.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief input buffer size */
|
||||
#define k_cmdBufferSize 256
|
||||
|
||||
/*! @brief input History depth */
|
||||
#define k_cmdHistoryDepth 16
|
||||
|
||||
/*! @brief max input command args */
|
||||
#define k_cmdMaxArgs 16
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
/*! @brief help command definition */
|
||||
static void help_func(uint8_t argc, uint8_t **argv);
|
||||
static blsh_cmd_t help_cmd = { "help", "Display commands list and usage", "help", help_func, 0, 0 };
|
||||
static blsh_cmd_t *root_cmd = &help_cmd;
|
||||
|
||||
/*! @brief exit command definition */
|
||||
static void exit_func(uint8_t argc, uint8_t **argv);
|
||||
static blsh_cmd_t exit_cmd = { "exit", "Exit the blsh", "exit", exit_func, 0, 0 };
|
||||
|
||||
/*! @brief blsh input buffer and index
|
||||
*/
|
||||
static uint8_t s_inputBuffer[k_cmdHistoryDepth][k_cmdBufferSize + 1] = { 0 };
|
||||
static uint32_t s_curCmdIndex = 0;
|
||||
static uint32_t s_curBufIndex = 0;
|
||||
|
||||
/*! @brief blsh exit flag */
|
||||
static uint8_t s_blsh_exit = 0;
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
static void blsh_handle(uint8_t c);
|
||||
static void line_execute(uint8_t *line);
|
||||
static uint32_t command_parse(blsh_cmd_t **_cmd, uint8_t **_str);
|
||||
static void command_execute(blsh_cmd_t *cmd, uint8_t *str);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
******************************************************************************/
|
||||
|
||||
void blsh_init(void)
|
||||
{
|
||||
command_add(&exit_cmd);
|
||||
|
||||
blsh_printf("\r\n **************************************** ");
|
||||
blsh_printf("\r\n *** Welcome to blsh *** ");
|
||||
blsh_printf("\r\n **************************************** ");
|
||||
blsh_printf("\r\n > "); /* Start a new line */
|
||||
}
|
||||
|
||||
void blsh_run(void)
|
||||
{
|
||||
uint8_t c;
|
||||
if (blsh_getchar(&c))
|
||||
{
|
||||
blsh_handle(c);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t blsh_exit(void)
|
||||
{
|
||||
return s_blsh_exit;
|
||||
}
|
||||
|
||||
void command_add(blsh_cmd_t *cmd)
|
||||
{
|
||||
blsh_cmd_t *index;
|
||||
|
||||
if (!root_cmd)
|
||||
{
|
||||
root_cmd = cmd;
|
||||
}
|
||||
else
|
||||
{
|
||||
index = root_cmd;
|
||||
while (index->next)
|
||||
index = index->next;
|
||||
index->next = cmd;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief handle input char
|
||||
*
|
||||
* @param c input char.
|
||||
*/
|
||||
static void blsh_handle(uint8_t c)
|
||||
{
|
||||
uint8_t *line = s_inputBuffer[s_curBufIndex];
|
||||
|
||||
if ((c == '\n') || (c == '\r')) /* Confirm the command */
|
||||
{
|
||||
/* Echo */
|
||||
blsh_putchar(c);
|
||||
|
||||
while (*line && (*line == ' '))
|
||||
line++;
|
||||
if (*line)
|
||||
{
|
||||
microseconds_init();
|
||||
line_execute(line);
|
||||
microseconds_shutdown();
|
||||
|
||||
s_curBufIndex = (s_curBufIndex + 1) % k_cmdHistoryDepth;
|
||||
s_curCmdIndex = 0;
|
||||
s_inputBuffer[s_curBufIndex][0] = 0;
|
||||
}
|
||||
/* Start a new line */
|
||||
if (!s_blsh_exit)
|
||||
blsh_printf("\r\n > ");
|
||||
}
|
||||
else if ((c == 0x08) || (c == 0x7f)) /* Backspace and delete */
|
||||
{
|
||||
if (s_curCmdIndex > 0)
|
||||
{
|
||||
line[--s_curCmdIndex] = 0;
|
||||
blsh_printf("\b \b");
|
||||
}
|
||||
}
|
||||
else if (c == 0x1b) /* Command turning */
|
||||
{
|
||||
uint8_t key_value[3] = { 0 };
|
||||
key_value[0] = c;
|
||||
key_value[1] = wait_uart_char_blocking();
|
||||
key_value[2] = wait_uart_char_blocking();
|
||||
|
||||
if (key_value[2] == 0x41) /* Up */
|
||||
{
|
||||
uint8_t prevLine = (s_curBufIndex + k_cmdHistoryDepth - 1) % k_cmdHistoryDepth;
|
||||
|
||||
if (s_inputBuffer[prevLine][0])
|
||||
{
|
||||
while (s_curCmdIndex-- > 0)
|
||||
blsh_printf("\b \b");
|
||||
line = s_inputBuffer[prevLine];
|
||||
s_curCmdIndex = strlen((char *)line);
|
||||
s_curBufIndex = prevLine;
|
||||
blsh_printf("\r > %s", line);
|
||||
}
|
||||
}
|
||||
else if (key_value[2] == 0x42) /* Down */
|
||||
{
|
||||
uint8_t nextLine = (s_curBufIndex + 1) % k_cmdHistoryDepth;
|
||||
|
||||
if (s_inputBuffer[nextLine][0])
|
||||
{
|
||||
while (s_curCmdIndex-- > 0)
|
||||
blsh_printf("\b \b");
|
||||
line = s_inputBuffer[nextLine];
|
||||
s_curCmdIndex = strlen((char *)line);
|
||||
s_curBufIndex = nextLine;
|
||||
blsh_printf("\r > %s", line);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
blsh_printf("%s", key_value);
|
||||
}
|
||||
}
|
||||
else /* Input command */
|
||||
{
|
||||
if (s_curCmdIndex < k_cmdBufferSize)
|
||||
{
|
||||
/* Echo */
|
||||
blsh_putchar(c);
|
||||
line[s_curCmdIndex++] = c;
|
||||
line[s_curCmdIndex] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief process input line
|
||||
*
|
||||
* @param line input line.
|
||||
*/
|
||||
static void line_execute(uint8_t *line)
|
||||
{
|
||||
uint8_t *str = line;
|
||||
blsh_cmd_t *cmd = root_cmd;
|
||||
uint32_t ret = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
ret = command_parse(&cmd, &str);
|
||||
|
||||
if (ret == k_match)
|
||||
{
|
||||
if (cmd)
|
||||
{
|
||||
command_execute(cmd, str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (ret == k_ambig)
|
||||
{
|
||||
blsh_printf("\r\n Error: Ambiguity command: %s", str);
|
||||
break;
|
||||
}
|
||||
else if (ret == k_unmatch)
|
||||
{
|
||||
blsh_printf("\r\n Error: Invalid command: %s", str);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief parse the command line
|
||||
*
|
||||
* @param _cmd command root.
|
||||
* @param _str input command.
|
||||
*/
|
||||
static uint32_t command_parse(blsh_cmd_t **_cmd, uint8_t **_str)
|
||||
{
|
||||
uint8_t *str = *_str;
|
||||
/* uint32_t matched_len = 0; */
|
||||
blsh_cmd_t *cmd;
|
||||
/* blsh_cmd_t *matched_cmd = 0; */
|
||||
uint32_t ret = 0;
|
||||
|
||||
/* Eliminate start blanks */
|
||||
while (*str == ' ')
|
||||
str++;
|
||||
if (!*str)
|
||||
{
|
||||
*_str = str;
|
||||
return k_nullMatch;
|
||||
}
|
||||
|
||||
for (cmd = *_cmd; cmd; cmd = cmd->next)
|
||||
{
|
||||
ret = bl_strstart(cmd->name, str);
|
||||
|
||||
if (ret == k_fullMatch)
|
||||
{
|
||||
while (*str && (*str != ' '))
|
||||
str++;
|
||||
while (*str == ' ')
|
||||
str++;
|
||||
*_str = str;
|
||||
*_cmd = cmd;
|
||||
return k_match;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return k_unmatch;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief execute the command
|
||||
*
|
||||
* @param cmd input command.
|
||||
* @param str input string.
|
||||
*/
|
||||
static void command_execute(blsh_cmd_t *cmd, uint8_t *str)
|
||||
{
|
||||
uint8_t temp[k_cmdBufferSize] = { 0 };
|
||||
uint8_t *string = temp;
|
||||
uint8_t *argv[k_cmdMaxArgs];
|
||||
uint8_t argc = 0;
|
||||
|
||||
memcpy(temp, str, strlen((char *)str));
|
||||
argv[argc++] = cmd->name;
|
||||
while (*string && (argc < k_cmdMaxArgs))
|
||||
{
|
||||
while (*string == ' ')
|
||||
string++;
|
||||
if (*string == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
argv[argc++] = string;
|
||||
while (*string && (*string != ' '))
|
||||
string++;
|
||||
if (!*string)
|
||||
{
|
||||
break;
|
||||
}
|
||||
*string++ = 0;
|
||||
}
|
||||
|
||||
if (cmd->function)
|
||||
{
|
||||
cmd->function(argc, argv);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief process help command
|
||||
*
|
||||
* @param argc the count of arguments inputed to shell.
|
||||
* @param argv the value of arguments inputed to shell.
|
||||
*/
|
||||
static void help_func(uint8_t argc, uint8_t **argv)
|
||||
{
|
||||
blsh_cmd_t *cmd = 0;
|
||||
|
||||
blsh_printf("\r\n Command List: \r\n ");
|
||||
for (cmd = root_cmd; cmd; cmd = cmd->next)
|
||||
{
|
||||
blsh_printf("%s\r\n \t\t\t %s\r\n ", cmd->usage, cmd->help);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief process exit command
|
||||
*
|
||||
* @param argc the count of arguments inputed to shell.
|
||||
* @param argv the value of arguments inputed to shell.
|
||||
*/
|
||||
static void exit_func(uint8_t argc, uint8_t **argv)
|
||||
{
|
||||
s_blsh_exit = 1;
|
||||
blsh_printf("\r\n Bye \r\n");
|
||||
}
|
||||
83
src/blsh/blsh.h
Normal file
83
src/blsh/blsh.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 __BLSH_H__
|
||||
#define __BLSH_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "bootloader_common.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
#define blsh_printf debug_printf
|
||||
#define blsh_getchar wait_uart_char
|
||||
#define blsh_putchar putchar
|
||||
|
||||
/*! @brief blsh command callback function */
|
||||
typedef void (*blsh_func_t)(uint8_t argc, uint8_t **argv);
|
||||
|
||||
/*! @brief blsh command struct */
|
||||
typedef struct _blsh_cmd
|
||||
{
|
||||
uint8_t *name; /* command input name, not 0. */
|
||||
uint8_t *help; /* help string, can be 0. */
|
||||
uint8_t *usage; /* usage string, can be 0. */
|
||||
blsh_func_t function; /* function to launch on command, can be 0. */
|
||||
void *arg; /* current argument when function called. */
|
||||
struct _blsh_cmd *next; /* next command, can be 0. */
|
||||
} blsh_cmd_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @brief blsh initialize */
|
||||
void blsh_init(void);
|
||||
|
||||
/*! @brief blsh main loop */
|
||||
void blsh_run(void);
|
||||
|
||||
/*! @brief exit blsh or not */
|
||||
uint8_t blsh_exit(void);
|
||||
|
||||
/*! @brief add a new command */
|
||||
void command_add(blsh_cmd_t *cmd);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __BLSH_H__ */
|
||||
1376
src/blsh/host_blsh_cmd.c
Normal file
1376
src/blsh/host_blsh_cmd.c
Normal file
File diff suppressed because it is too large
Load Diff
94
src/blsh/host_blsh_cmd.h
Normal file
94
src/blsh/host_blsh_cmd.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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_BLSH_CMD_H__
|
||||
#define __HOST_BLSH_CMD_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "blsh.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/*! @brief bus option */
|
||||
typedef struct _bus_option
|
||||
{
|
||||
uint8_t bus;
|
||||
uint32_t freq;
|
||||
} bus_option_t;
|
||||
|
||||
/*! @brief Packetizer status codes. */
|
||||
enum _packetizer_status
|
||||
{
|
||||
kStatus_NoPingResponse = MAKE_STATUS(kStatusGroup_Packetizer, 0),
|
||||
kStatus_InvalidPacketType = MAKE_STATUS(kStatusGroup_Packetizer, 1),
|
||||
kStatus_InvalidCRC = MAKE_STATUS(kStatusGroup_Packetizer, 2),
|
||||
kStatus_NoCommandResponse = MAKE_STATUS(kStatusGroup_Packetizer, 3)
|
||||
};
|
||||
|
||||
#if defined(BL_EMBEDDED_HOST)
|
||||
|
||||
extern blsh_cmd_t flash_image_cmd;
|
||||
extern blsh_cmd_t write_memory_cmd;
|
||||
extern blsh_cmd_t read_memory_cmd;
|
||||
extern blsh_cmd_t fill_memory_cmd;
|
||||
extern blsh_cmd_t flash_security_disable_cmd;
|
||||
extern blsh_cmd_t flash_erase_all_cmd;
|
||||
extern blsh_cmd_t flash_erase_all_unsecure_cmd;
|
||||
extern blsh_cmd_t flash_erase_region_cmd;
|
||||
extern blsh_cmd_t execute_cmd;
|
||||
extern blsh_cmd_t call_cmd;
|
||||
extern blsh_cmd_t flash_program_once_cmd;
|
||||
extern blsh_cmd_t flash_read_once_cmd;
|
||||
extern blsh_cmd_t flash_read_resource_cmd;
|
||||
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*! @brief initial blsh command and get some information for follow-up work */
|
||||
void host_blsh_cmd_init(void);
|
||||
|
||||
/*! @brief get transfer bus type */
|
||||
status_t transfer_bus_parse(uint8_t *src, uint8_t *option);
|
||||
|
||||
/*! @brief get bus frequency */
|
||||
status_t transfer_freq_parse(uint8_t *src, uint8_t bus, uint32_t *option);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __HOST_BLSH_CMD_H__ */
|
||||
1429
src/blsh/host_command.c
Normal file
1429
src/blsh/host_command.c
Normal file
File diff suppressed because it is too large
Load Diff
248
src/blsh/host_command.h
Normal file
248
src/blsh/host_command.h
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* 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
|
||||
******************************************************************************/
|
||||
/*! @brief Transfer bus mode */
|
||||
enum _transfer_mode_type
|
||||
{
|
||||
kIdle_mode = 0,
|
||||
kSPI_mode = 1,
|
||||
kI2C_mode = 2,
|
||||
kUART_mode = 3,
|
||||
kCAN_mode = 4
|
||||
};
|
||||
|
||||
#if DEBUG && !DEBUG_PRINT_DISABLE
|
||||
/*! @brief Command names */
|
||||
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)
|
||||
/*! @brief command packet */
|
||||
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)
|
||||
/*! @brief generic response packet */
|
||||
typedef struct _generic_response_frame_packet
|
||||
{
|
||||
framing_data_packet_t framing_data;
|
||||
uint8_t commandTag; /*!< A command tag. */
|
||||
uint8_t flags; /*!< Combination of packet flags. */
|
||||
uint8_t reserved; /*!< Reserved, helpful for alignment, set to zero. */
|
||||
uint8_t parameterCount; /*!< Number of parameters that follow in buffer. */
|
||||
uint32_t status; /*!< parameter 0 */
|
||||
uint32_t param_commandTag; /*!< parameter 1 */
|
||||
} generic_response_frame_packet_t;
|
||||
#pragma pack()
|
||||
|
||||
#pragma pack(1)
|
||||
/*! @brief generic response packet */
|
||||
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)
|
||||
/*! @brief generic response packet */
|
||||
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()
|
||||
|
||||
/*! @brief target memory info */
|
||||
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;
|
||||
|
||||
/*! @brief memory test options */
|
||||
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;
|
||||
|
||||
/*! @brief bootloader command info */
|
||||
typedef struct _command_info
|
||||
{
|
||||
bool is_info_reday;
|
||||
uint32_t cmd_mask;
|
||||
} command_info_t;
|
||||
|
||||
/*! @brief Data transfer bus mode(dafault = spi). */
|
||||
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 */
|
||||
|
||||
/*! @brief handle get-property command */
|
||||
status_t handle_getProperty_command(uint8_t input_param, uint32_t *response_param);
|
||||
|
||||
/*! @brief handle set-property command */
|
||||
status_t handle_setProperty_command(uint8_t property_tag, uint32_t property_value);
|
||||
|
||||
/*! @brief handle flash-erase-all-unsecure command */
|
||||
status_t handle_flashEraseAllUnsecure_command(void);
|
||||
|
||||
/*! @brief handle flash-erase-all command */
|
||||
status_t handle_flashEraseAll_command(void);
|
||||
|
||||
/*! @brief handle flash-erase-region command */
|
||||
status_t handle_flashEraseRegion_command(uint32_t start_address, uint32_t erase_bytes);
|
||||
|
||||
/*! @brief handle reset target command */
|
||||
status_t handle_reset_command(void);
|
||||
|
||||
/*! @brief handle write-memory command */
|
||||
status_t handle_writeMemory_command(uint32_t start_address, uint8_t *buffer, uint32_t length);
|
||||
|
||||
/*! @brief handle read memory command */
|
||||
status_t handle_readMemory_command(uint32_t start_address, uint8_t *buffer, uint32_t length);
|
||||
|
||||
/*! @brief handle fill memory command */
|
||||
status_t handle_fillMemory_command(uint32_t start_address, uint32_t pattern_word, uint32_t byte_count);
|
||||
|
||||
/*! @brief handle flash security disable command */
|
||||
status_t handle_flashSecurityDisable_command(uint32_t backdoorkey_low, uint32_t backdoorkey_high);
|
||||
|
||||
/*! @brief handle execute command */
|
||||
status_t handle_execute_command(uint32_t address, uint32_t arg, uint32_t stack_pointer);
|
||||
|
||||
/*! @brief handle call command */
|
||||
status_t handle_call_command(uint32_t address, uint32_t arg);
|
||||
|
||||
/*! @brief handle flash program once command */
|
||||
status_t handle_flashProgramOnce_command(uint32_t index, uint32_t byte_count, uint32_t data1, uint32_t data2);
|
||||
|
||||
/*! @brief handle flash read once command */
|
||||
status_t handle_flashReadOnce_command(uint32_t index, uint32_t byte_count, uint32_t *data1, uint32_t *data2);
|
||||
|
||||
/*! @brief handle flash read resource command */
|
||||
status_t handle_flashReadResource_command(uint32_t start_address, uint8_t *buffer, uint32_t length, uint32_t option);
|
||||
|
||||
/*! @brief handle get-property command */
|
||||
status_t handle_receiveSBFile_command(uint32_t address, uint32_t length);
|
||||
|
||||
/*! @brief get target flash and ram information */
|
||||
status_t get_memory_info(memory_info_t *info);
|
||||
|
||||
/*! @brief get target command information */
|
||||
status_t get_command_info(command_info_t *info);
|
||||
|
||||
/*! @brief send ping command and wait ping response */
|
||||
status_t run_ping_command(void);
|
||||
|
||||
/*! @brief wait for ping command response */
|
||||
status_t wait_ping_response(uint8_t try_count);
|
||||
|
||||
/*! @brief wait ack packet */
|
||||
status_t wait_ack_packet(void);
|
||||
|
||||
/*! @brief wait command response */
|
||||
status_t wait_command_response(generic_response_frame_packet_t *command_response);
|
||||
|
||||
/*! @brief check transfer bus frequency */
|
||||
void check_transfer_bus(uint8_t transfer_bus, uint32_t *input_freq);
|
||||
|
||||
/*! @brief configure transfer bus send and receive function */
|
||||
void configure_transfer_bus(uint8_t transfer_bus, uint32_t freq);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __HOST_COMMAND_H__ */
|
||||
Reference in New Issue
Block a user