/* * .KB_C_FN_DEFINITION_START * void ServicePrompt(char) * This private function process each character checking for valid commands. * This function is only executed if the character is considered valid. * Each command is terminated with NULL (0) or ''. * .KB_C_FN_DEFINITION_END */ static void ServicePrompt(char p_char) { if (p_char == '\r') p_char = 0; if (p_char == '\010') { if (buffCount) { /* handle backspace BS */ inputBuffer[--buffCount] = 0; printf(backspaceString); } return; } if (buffCount < MAX_INPUT_SIZE - 1) { inputBuffer[buffCount++] = p_char; putchar(p_char); } if (!p_char) { printf("\n"); ParseCommand(inputBuffer); p_memset(inputBuffer, 0, MAX_INPUT_SIZE); buffCount = 0; printf("\n>"); } }
/* * .KB_C_FN_DEFINITION_START * void WriteCommandTable(void) * This global function write the current command table to the non-volatile * memory. * .KB_C_FN_DEFINITION_END */ void WriteCommandTable(void) { int i, size = MAX_ENV_SIZE_BYTES, copySize; char *cPtr = env_table; p_memset(env_table, 0, sizeof(env_table)); for (i = 0; i < MAX_BOOT_COMMANDS; ++i) { copySize = p_strlen(boot_commands[i]); size -= copySize + 1; if (size < 0) { continue; } memcpy(cPtr, boot_commands[i], copySize); cPtr += copySize; *cPtr++ = 0; } /* We're executing in low RAM so addr in ram == offset in eeprom */ WriteEEPROM((unsigned)&BootCommandSection, env_table, sizeof(env_table)); }
/* * .KB_C_FN_DEFINITION_START * int BreakCommand(char *) * This private function splits the buffer into separate strings as pointed * by argv and returns the number of parameters (< 0 on failure). * .KB_C_FN_DEFINITION_END */ static int BreakCommand(char *buffer) { int pCount, cCount, state; state = pCount = 0; p_memset((char*)argv, 0, sizeof(argv)); for (cCount = 0; cCount < MAX_INPUT_SIZE; ++cCount) { if (!state) { /* look for next command */ if (!p_IsWhiteSpace(buffer[cCount])) { argv[pCount++] = &buffer[cCount]; state = 1; } else { buffer[cCount] = 0; } } else { /* in command, find next white space */ if (p_IsWhiteSpace(buffer[cCount])) { buffer[cCount] = 0; state = 0; } } if (pCount >= MAX_COMMAND_PARAMS) { return (-1); } } return (pCount); }
/* * .KB_C_FN_DEFINITION_START * void LoadBootCommands(void) * This global function loads the existing boot commands from raw format and * coverts it to the standard, command-index format. Notice, the processed * boot command table has much more space allocated than the actual table * stored in non-volatile memory. This is because the processed table * exists in RAM which is larger than the non-volatile space. * .KB_C_FN_DEFINITION_END */ void LoadBootCommands(void) { int index, j; char *cptr; p_memset((char*)boot_commands, 0, sizeof(boot_commands)); cptr = &BootCommandSection; for (index = 0; *cptr; index++) { for (j = 0; *cptr; j++) boot_commands[index][j] = *cptr++; cptr++; } }
/* * .KB_C_FN_DEFINITION_START * void Bootloader(void *inputFunction) * This global function is the entry point for the bootloader. If the * inputFunction pointer is NULL, the loader input will be serviced from * the uart. Otherwise, inputFunction is called to get characters which * the loader will parse. * .KB_C_FN_DEFINITION_END */ void Bootloader(int(*inputFunction)(int)) { int ch = 0; p_memset((void*)inputBuffer, 0, sizeof(inputBuffer)); buffCount = 0; printf("\n>"); while (1) if ((ch = ((*inputFunction)(0))) > 0) ServicePrompt(ch); }
/* * .KB_C_FN_DEFINITION_START * void SetBootCommand(int index, char *command) * This global function replaces the specified index with the string residing * at command. Execute this function with a NULL string to clear the * associated command index. * .KB_C_FN_DEFINITION_END */ void SetBootCommand(int index, char *command) { int i; if ((unsigned)index < MAX_BOOT_COMMANDS) { p_memset(boot_commands[index], 0, MAX_INPUT_SIZE); if (!command) return ; for (i = 0; i < MAX_INPUT_SIZE; ++i) { boot_commands[index][i] = command[i]; if (!(boot_commands[index][i])) return; } } }
/* * .KB_C_FN_DEFINITION_START * void LoadBootCommands(void) * This global function loads the existing boot commands from raw format and * coverts it to the standard, command-index format. Notice, the processed * boot command table has much more space allocated than the actual table * stored in non-volatile memory. This is because the processed table * exists in RAM which is larger than the non-volatile space. * .KB_C_FN_DEFINITION_END */ void LoadBootCommands(void) { int index, j, size; char *cPtr; p_memset((char*)boot_commands, 0, sizeof(boot_commands)); cPtr = &BootCommandSection; size = MAX_ENV_SIZE_BYTES; for (index = 0; (index < MAX_BOOT_COMMANDS) && size; ++index) { for (j = 0; (j < MAX_INPUT_SIZE) && size; ++j) { size--; boot_commands[index][j] = *cPtr++; if (!(boot_commands[index][j])) { break; } } } }