1 /******************************************************************************
5 * Instantiation of environment variables, structures, and other globals.
7 * Revision information:
9 * 20AUG2004 kb_admin initial creation
12 * No warranty, expressed or implied, is included with this software. It is
13 * provided "AS IS" and no warranty of any kind including statutory or aspects
14 * relating to merchantability or fitness for any purpose is provided. All
15 * intellectual property rights of others is maintained with the respective
16 * owners. This software is not copyrighted and is intended for reference
21 *****************************************************************************/
24 #include "loader_prompt.h"
27 /******************************* GLOBALS *************************************/
28 char boot_commands[MAX_BOOT_COMMANDS][MAX_INPUT_SIZE];
30 char env_table[MAX_ENV_SIZE_BYTES];
32 extern char BootCommandSection;
34 /************************** PRIVATE FUNCTIONS ********************************/
37 static int currentIndex;
38 static int currentOffset;
42 * .KB_C_FN_DEFINITION_START
43 * int ReadCharFromEnvironment(char *)
44 * This private function reads characters from the enviroment variables
45 * to service the command prompt during auto-boot or just to setup the
46 * default environment. Returns positive value if valid character was
47 * set in the pointer. Returns negative value to signal input stream
48 * terminated. Returns 0 to indicate _wait_ condition.
49 * .KB_C_FN_DEFINITION_END
52 ReadCharFromEnvironment(int timeout)
56 if (currentIndex < MAX_BOOT_COMMANDS) {
57 ch = boot_commands[currentIndex][currentOffset++];
58 if (ch == '\0' || (currentOffset >= MAX_INPUT_SIZE)) {
70 /*************************** GLOBAL FUNCTIONS ********************************/
74 * .KB_C_FN_DEFINITION_START
75 * void WriteCommandTable(void)
76 * This global function write the current command table to the non-volatile
78 * .KB_C_FN_DEFINITION_END
81 WriteCommandTable(void)
83 int i, size = MAX_ENV_SIZE_BYTES, copySize;
84 char *cPtr = env_table;
86 p_memset(env_table, 0, sizeof(env_table));
88 for (i = 0; i < MAX_BOOT_COMMANDS; ++i) {
90 copySize = p_strlen(boot_commands[i]);
96 memcpy(cPtr, boot_commands[i], copySize);
101 /* We're executing in low RAM so addr in ram == offset in eeprom */
102 WriteEEPROM((unsigned)&BootCommandSection, env_table,
108 * .KB_C_FN_DEFINITION_START
109 * void SetBootCommand(int index, char *command)
110 * This global function replaces the specified index with the string residing
111 * at command. Execute this function with a NULL string to clear the
112 * associated command index.
113 * .KB_C_FN_DEFINITION_END
116 SetBootCommand(int index, char *command)
120 if ((unsigned)index < MAX_BOOT_COMMANDS) {
122 p_memset(boot_commands[index], 0, MAX_INPUT_SIZE);
127 for (i = 0; i < MAX_INPUT_SIZE; ++i) {
128 boot_commands[index][i] = command[i];
129 if (!(boot_commands[index][i]))
137 * .KB_C_FN_DEFINITION_START
138 * void DumpBootCommands(void)
139 * This global function displays the current boot commands.
140 * .KB_C_FN_DEFINITION_END
143 DumpBootCommands(void)
147 for (i = 0; i < MAX_BOOT_COMMANDS; ++i) {
148 printf("0x%x : ", i);
149 for (j = 0; j < MAX_INPUT_SIZE; ++j) {
150 putchar(boot_commands[i][j]);
151 if (!(boot_commands[i][j]))
160 * .KB_C_FN_DEFINITION_START
161 * void LoadBootCommands(void)
162 * This global function loads the existing boot commands from raw format and
163 * coverts it to the standard, command-index format. Notice, the processed
164 * boot command table has much more space allocated than the actual table
165 * stored in non-volatile memory. This is because the processed table
166 * exists in RAM which is larger than the non-volatile space.
167 * .KB_C_FN_DEFINITION_END
170 LoadBootCommands(void)
175 p_memset((char*)boot_commands, 0, sizeof(boot_commands));
177 cPtr = &BootCommandSection;
179 size = MAX_ENV_SIZE_BYTES;
181 for (index = 0; (index < MAX_BOOT_COMMANDS) && size; ++index) {
182 for (j = 0; (j < MAX_INPUT_SIZE) && size; ++j) {
184 boot_commands[index][j] = *cPtr++;
185 if (!(boot_commands[index][j])) {
194 * .KB_C_FN_DEFINITION_START
195 * void ExecuteEnvironmentFunctions(void)
196 * This global function executes applicable entries in the environment.
197 * .KB_C_FN_DEFINITION_END
200 ExecuteEnvironmentFunctions(void)
206 Bootloader(ReadCharFromEnvironment);