199767f8919635c4928607450d9e0abb932109ceToomas Soome/******************************************************************************
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Filename: loader_prompt.c
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Instantiation of the interactive loader functions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Revision information:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 20AUG2004 kb_admin initial creation
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 12JAN2005 kb_admin massive changes for tftp, strings, and more
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 05JUL2005 kb_admin save tag address, and set registers on boot
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BEGIN_KBDD_BLOCK
199767f8919635c4928607450d9e0abb932109ceToomas Soome * No warranty, expressed or implied, is included with this software. It is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * provided "AS IS" and no warranty of any kind including statutory or aspects
199767f8919635c4928607450d9e0abb932109ceToomas Soome * relating to merchantability or fitness for any purpose is provided. All
199767f8919635c4928607450d9e0abb932109ceToomas Soome * intellectual property rights of others is maintained with the respective
199767f8919635c4928607450d9e0abb932109ceToomas Soome * owners. This software is not copyrighted and is intended for reference
199767f8919635c4928607450d9e0abb932109ceToomas Soome * only.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * END_BLOCK
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome *****************************************************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "at91rm9200_lowlevel.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "at91rm9200.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "emac.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "loader_prompt.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "env_vars.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "lib.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "spi_flash.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "ee.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/******************************* GLOBALS *************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*********************** PRIVATE FUNCTIONS/DATA ******************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char inputBuffer[MAX_INPUT_SIZE];
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int buffCount;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome// argv pointer are either NULL or point to locations in inputBuffer
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char *argv[MAX_COMMAND_PARAMS];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FLASH_OFFSET (0 * FLASH_PAGE_SIZE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KERNEL_OFFSET (220 * FLASH_PAGE_SIZE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define KERNEL_LEN (6 * 1024 * FLASH_PAGE_SIZE)
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic const char *backspaceString = "\010 \010";
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic const command_entry_t CommandTable[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_DUMP, "d"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_EXEC, "e"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_LOCAL_IP, "ip"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_MAC, "m"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_SERVER_IP, "server_ip"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_TFTP, "tftp"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_XMODEM, "x"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_RESET, "R"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_LOAD_SPI_KERNEL, "k"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_REPLACE_KERNEL_VIA_XMODEM, "K"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_REPLACE_FLASH_VIA_XMODEM, "I"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_REPLACE_ID_EEPROM, "E"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_FINAL_FLAG, 0}
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * unsigned BuildIP(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This private function packs the test IP info to an unsigned value.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic unsigned
199767f8919635c4928607450d9e0abb932109ceToomas SoomeBuildIP(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ((p_ASCIIToDec(argv[1]) << 24) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome (p_ASCIIToDec(argv[2]) << 16) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome (p_ASCIIToDec(argv[3]) << 8) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_ASCIIToDec(argv[4]));
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * int StringToCommand(char *cPtr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This private function converts a command string to a command code.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas SoomeStringToCommand(char *cPtr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; CommandTable[i].command != COMMAND_FINAL_FLAG; ++i)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!strcmp(CommandTable[i].c_string, cPtr))
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (CommandTable[i].command);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (COMMAND_INVALID);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * int BreakCommand(char *)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This private function splits the buffer into separate strings as pointed
199767f8919635c4928607450d9e0abb932109ceToomas Soome * by argv and returns the number of parameters (< 0 on failure).
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas SoomeBreakCommand(char *buffer)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int pCount, cCount, state;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome state = pCount = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset((char*)argv, 0, sizeof(argv));
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (cCount = 0; cCount < MAX_INPUT_SIZE; ++cCount) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!state) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* look for next command */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!p_IsWhiteSpace(buffer[cCount])) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome argv[pCount++] = &buffer[cCount];
199767f8919635c4928607450d9e0abb932109ceToomas Soome state = 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome buffer[cCount] = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* in command, find next white space */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p_IsWhiteSpace(buffer[cCount])) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome buffer[cCount] = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome state = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (pCount >= MAX_COMMAND_PARAMS) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (pCount);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if 0
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas SoomeUpdateEEProm(int eeaddr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome while ((len = xmodem_rx(addr)) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\nDownloaded %u bytes.\n", len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome WriteEEPROM(eeaddr, 0, addr, len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas SoomeUpdateFlash(int offset)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *addr = (char *)SDRAM_BASE + (1 << 20); /* Load to base + 1MB */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int len, i, off;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome while ((len = xmodem_rx(addr)) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\nDownloaded %u bytes.\n", len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < len; i+= FLASH_PAGE_SIZE) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome off = i + offset;
199767f8919635c4928607450d9e0abb932109ceToomas Soome SPI_WriteFlash(off, addr + i, FLASH_PAGE_SIZE);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas SoomeLoadKernelFromSpi(char *addr)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i, off;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < KERNEL_LEN; i+= FLASH_PAGE_SIZE) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome off = i + KERNEL_OFFSET;
199767f8919635c4928607450d9e0abb932109ceToomas Soome SPI_ReadFlash(off, addr + i, FLASH_PAGE_SIZE);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void ParseCommand(char *)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This private function executes matching functions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas SoomeParseCommand(char *buffer)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int argc, i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((argc = BreakCommand(buffer)) < 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome switch (StringToCommand(argv[0])) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_DUMP:
199767f8919635c4928607450d9e0abb932109ceToomas Soome // display boot commands
199767f8919635c4928607450d9e0abb932109ceToomas Soome DumpBootCommands();
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_EXEC:
199767f8919635c4928607450d9e0abb932109ceToomas Soome {
199767f8919635c4928607450d9e0abb932109ceToomas Soome // "e <address>"
199767f8919635c4928607450d9e0abb932109ceToomas Soome // execute at address
199767f8919635c4928607450d9e0abb932109ceToomas Soome void (*execAddr)(unsigned, unsigned);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* in future, include machtypes (MACH_KB9200 = 612) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome execAddr = (void (*)(unsigned, unsigned))
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_ASCIIToHex(argv[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome (*execAddr)(0, 612);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_TFTP:
199767f8919635c4928607450d9e0abb932109ceToomas Soome {
199767f8919635c4928607450d9e0abb932109ceToomas Soome // "tftp <local_dest_addr filename>"
199767f8919635c4928607450d9e0abb932109ceToomas Soome // tftp download
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned address = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 2)
199767f8919635c4928607450d9e0abb932109ceToomas Soome address = p_ASCIIToHex(argv[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome TFTP_Download(address, argv[2]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_SERVER_IP:
199767f8919635c4928607450d9e0abb932109ceToomas Soome // "server_ip <server IP 192 200 1 20>"
199767f8919635c4928607450d9e0abb932109ceToomas Soome // set download server address
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 4)
199767f8919635c4928607450d9e0abb932109ceToomas Soome SetServerIPAddress(BuildIP());
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_LOCAL_IP:
199767f8919635c4928607450d9e0abb932109ceToomas Soome // "local_ip <local IP 192 200 1 21>
199767f8919635c4928607450d9e0abb932109ceToomas Soome // set ip of this module
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 4)
199767f8919635c4928607450d9e0abb932109ceToomas Soome SetLocalIPAddress(BuildIP());
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_MAC:
199767f8919635c4928607450d9e0abb932109ceToomas Soome {
199767f8919635c4928607450d9e0abb932109ceToomas Soome // "m <mac address 12 34 56 78 9a bc>
199767f8919635c4928607450d9e0abb932109ceToomas Soome // set mac address using 6 byte values
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned char mac[6];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 6) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < 6; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome mac[i] = p_ASCIIToHex(argv[i + 1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome EMAC_SetMACAddress(mac);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_LOAD_SPI_KERNEL:
199767f8919635c4928607450d9e0abb932109ceToomas Soome // "k <address>"
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome LoadKernelFromSpi((char *)p_ASCIIToHex(argv[1]));
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_XMODEM:
199767f8919635c4928607450d9e0abb932109ceToomas Soome // "x <address>"
199767f8919635c4928607450d9e0abb932109ceToomas Soome // download X-modem record at address
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome xmodem_rx((char *)p_ASCIIToHex(argv[1]));
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_RESET:
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Reset\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome reset();
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (1) continue;
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_REPLACE_KERNEL_VIA_XMODEM:
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Updating KERNEL image\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome UpdateFlash(KERNEL_OFFSET);
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_REPLACE_FLASH_VIA_XMODEM:
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Updating FLASH image\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome UpdateFlash(FLASH_OFFSET);
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_REPLACE_ID_EEPROM:
199767f8919635c4928607450d9e0abb932109ceToomas Soome {
199767f8919635c4928607450d9e0abb932109ceToomas Soome char buf[25];
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Testing Config EEPROM\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome EEWrite(0, "This is a test", 15);
199767f8919635c4928607450d9e0abb932109ceToomas Soome EERead(0, buf, 15);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Found '%s'\n", buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome default:
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void ServicePrompt(char)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This private function process each character checking for valid commands.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This function is only executed if the character is considered valid.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Each command is terminated with NULL (0) or ''.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas SoomeServicePrompt(char p_char)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p_char == '\r')
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_char = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (p_char == '\010') {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (buffCount) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* handle backspace BS */
199767f8919635c4928607450d9e0abb932109ceToomas Soome inputBuffer[--buffCount] = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(backspaceString);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (buffCount < MAX_INPUT_SIZE - 1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome inputBuffer[buffCount++] = p_char;
199767f8919635c4928607450d9e0abb932109ceToomas Soome putchar(p_char);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!p_char) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome ParseCommand(inputBuffer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset(inputBuffer, 0, MAX_INPUT_SIZE);
199767f8919635c4928607450d9e0abb932109ceToomas Soome buffCount = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\n>");
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* ************************** GLOBAL FUNCTIONS ********************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void Bootloader(void *inputFunction)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This global function is the entry point for the bootloader. If the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * inputFunction pointer is NULL, the loader input will be serviced from
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the uart. Otherwise, inputFunction is called to get characters which
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the loader will parse.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeBootloader(int(*inputFunction)(int))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int ch = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset((void*)inputBuffer, 0, sizeof(inputBuffer));
199767f8919635c4928607450d9e0abb932109ceToomas Soome buffCount = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("\n>");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((ch = ((*inputFunction)(0))) > 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome ServicePrompt(ch);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}