199767f8919635c4928607450d9e0abb932109ceToomas Soome/******************************************************************************
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Filename: env_vars.c
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Instantiation of environment variables, structures, and other globals.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Revision information:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 20AUG2004 kb_admin initial creation
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 "env_vars.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "loader_prompt.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "lib.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/******************************* GLOBALS *************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soomechar boot_commands[MAX_BOOT_COMMANDS][MAX_INPUT_SIZE];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomechar env_table[MAX_ENV_SIZE_BYTES];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeextern char BootCommandSection;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/************************** PRIVATE FUNCTIONS ********************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int currentIndex;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int currentOffset;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * int ReadCharFromEnvironment(char *)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This private function reads characters from the enviroment variables
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to service the command prompt during auto-boot or just to setup the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * default environment. Returns positive value if valid character was
199767f8919635c4928607450d9e0abb932109ceToomas Soome * set in the pointer. Returns negative value to signal input stream
199767f8919635c4928607450d9e0abb932109ceToomas Soome * terminated. Returns 0 to indicate _wait_ condition.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int
199767f8919635c4928607450d9e0abb932109ceToomas SoomeReadCharFromEnvironment(int timeout)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int ch;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (currentIndex < MAX_BOOT_COMMANDS) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome ch = boot_commands[currentIndex][currentOffset++];
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (ch == '\0' || (currentOffset >= MAX_INPUT_SIZE)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome currentOffset = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome ++currentIndex;
199767f8919635c4928607450d9e0abb932109ceToomas Soome ch = '\r';
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (ch);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
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 DumpBootCommands(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This global function displays the current boot commands.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeDumpBootCommands(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int i;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; boot_commands[i][0]; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("0x%x : %s[E]\n", i, boot_commands[i]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void LoadBootCommands(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This global function loads the existing boot commands from raw format and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * coverts it to the standard, command-index format. Notice, the processed
199767f8919635c4928607450d9e0abb932109ceToomas Soome * boot command table has much more space allocated than the actual table
199767f8919635c4928607450d9e0abb932109ceToomas Soome * stored in non-volatile memory. This is because the processed table
199767f8919635c4928607450d9e0abb932109ceToomas Soome * exists in RAM which is larger than the non-volatile space.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeLoadBootCommands(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int index, j;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *cptr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset((char*)boot_commands, 0, sizeof(boot_commands));
199767f8919635c4928607450d9e0abb932109ceToomas Soome cptr = &BootCommandSection;
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (index = 0; *cptr; index++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (j = 0; *cptr; j++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome boot_commands[index][j] = *cptr++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cptr++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void ExecuteEnvironmentFunctions(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This global function executes applicable entries in the environment.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeExecuteEnvironmentFunctions(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome currentIndex = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome currentOffset = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome DumpBootCommands();
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("Autoboot...\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome Bootloader(ReadCharFromEnvironment);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}