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#ifdef SUPPORT_TAG_LIST
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "tag_list.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "emac.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "loader_prompt.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "env_vars.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "lib.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
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 Soomestatic const char *backspaceString = "\010 \010";
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic const command_entry_t CommandTable[] = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_COPY, "c"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_DUMP, "d"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_EXEC, "e"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_HELP, "?"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_LOCAL_IP, "ip"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_MAC, "m"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_SERVER_IP, "server_ip"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_SET, "s"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef SUPPORT_TAG_LIST
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_TAG, "t"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_TFTP, "tftp"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_WRITE, "w"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_XMODEM, "x"},
199767f8919635c4928607450d9e0abb932109ceToomas Soome {COMMAND_FINAL_FLAG, 0}
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic unsigned tagAddress;
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 * void RestoreSpace(int)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This private function restores NULL characters to spaces in order to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * process the remaining args as a string. The number passed is the argc
199767f8919635c4928607450d9e0abb932109ceToomas Soome * of the first entry to begin restoring space in the inputBuffer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas SoomeRestoreSpace(int startArgc)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *cPtr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (startArgc++; startArgc < MAX_COMMAND_PARAMS; startArgc++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((cPtr = argv[startArgc]))
199767f8919635c4928607450d9e0abb932109ceToomas Soome *(cPtr - 1) = ' ';
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
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
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_COPY:
199767f8919635c4928607450d9e0abb932109ceToomas Soome {
199767f8919635c4928607450d9e0abb932109ceToomas Soome // "c <to> <from> <size in bytes>"
199767f8919635c4928607450d9e0abb932109ceToomas Soome // copy memory
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *to, *from;
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 3) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome to = (char *)p_ASCIIToHex(argv[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome from = (char *)p_ASCIIToHex(argv[2]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome size = p_ASCIIToHex(argv[3]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome memcpy(to, from, size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
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, unsigned);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* in future, include machtypes (MACH_KB9200 = 612) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome execAddr = (void (*)(unsigned, unsigned, unsigned))
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_ASCIIToHex(argv[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome (*execAddr)(0, 612, tagAddress);
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_HELP:
199767f8919635c4928607450d9e0abb932109ceToomas Soome // dump command info
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Commands:\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\tc\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\td\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\te\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\tip\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\tserver_ip\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\tm\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\ttftp\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\ts\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef SUPPORT_TAG_LIST
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\tt\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\tw\n"
199767f8919635c4928607450d9e0abb932109ceToomas Soome "\tx\n");
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_SET:
199767f8919635c4928607450d9e0abb932109ceToomas Soome {
199767f8919635c4928607450d9e0abb932109ceToomas Soome // s <index> <new boot command>
199767f8919635c4928607450d9e0abb932109ceToomas Soome // set the boot command at index (0-based)
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned index;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome RestoreSpace(2);
199767f8919635c4928607450d9e0abb932109ceToomas Soome index = p_ASCIIToHex(argv[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome SetBootCommand(index, argv[2]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef SUPPORT_TAG_LIST
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_TAG:
199767f8919635c4928607450d9e0abb932109ceToomas Soome // t <address> <boot command line>
199767f8919635c4928607450d9e0abb932109ceToomas Soome // create tag-list for linux boot
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (argc > 2) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome RestoreSpace(2);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tagAddress = p_ASCIIToHex(argv[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome InitTagList(argv[2], (void*)tagAddress);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_WRITE:
199767f8919635c4928607450d9e0abb932109ceToomas Soome // write the command table to non-volatile
199767f8919635c4928607450d9e0abb932109ceToomas Soome WriteCommandTable();
199767f8919635c4928607450d9e0abb932109ceToomas Soome break;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome case COMMAND_XMODEM:
199767f8919635c4928607450d9e0abb932109ceToomas Soome {
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
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
199767f8919635c4928607450d9e0abb932109ceToomas Soome buffCount = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!inputFunction) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome inputFunction = getc;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
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}