Added console parameter defaulting (so that boot console baud rate

can be passed to kernel).

Added copyright header to elf2img.
master
Philippe Vachon 16 years ago
parent ec5896e6ea
commit eddec83ce7

@ -1,3 +1,13 @@
/* elf2img - convert an ELF loadable object to a raw binary image or a Cisco-
* specific loadabe image.
*
* (c) 2008 Philippe Vachoon <philippe@cowpig.ca>
*
* Licensed under the GNU General Public License v2. See COPYING
* in the distribution source directory for more information.
*
*/
#include <elf.h>
#include <types.h>

@ -12,6 +12,8 @@
#define TIMER 0
#define GETBAUD 62
/* Promlib Calls */
void c_putc(const char c);
void c_puts(const char *s);
@ -21,5 +23,6 @@ int c_memsz(void);
long c_timer(void);
int c_strnlen(const char *c, int maxlen);
char *c_verstr(void);
int c_baud(void);
#endif /* _PROMLIB_H */

@ -11,10 +11,12 @@ char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, uint32_t n);
uint32_t strlen(char *s);
uint32_t strlen(const char *s);
int memcpy(void *dst, const void *src, int n);
const char *strchr(const char *s, int c);
const char *strstr(const char *haystack, const char *needle);
#endif /* _STRING_H */

@ -183,3 +183,22 @@ int c_strnlen(const char *s, int maxlen)
return i;
}
/* baud - get console baud rate
* @return boot console baud rate
*/
int c_baud(void)
{
int b = 0;
asm volatile (".set noreorder\n"
"li $a0, %[syscall]\n"
"syscall\n"
"nop\n"
"move %[result], $a0\n"
".set reorder\n"
: [result]"=r"(b)
: [syscall]"g"(GETBAUD)
: "a0", "v0"
);
}

@ -87,6 +87,9 @@ void start_bootloader()
enter_filename:
printf("\nEnter filename to boot:\n> ");
c_gets(buf, 128);
int baud = c_baud(); /* get console baud rate */
printf("Boot console baud rate: %d\n", baud);
/* determine if a command line string has been appended to kernel name */
if ((cmd_line_append = strchr(buf, ' ')) != NULL) {
@ -95,9 +98,16 @@ enter_filename:
uint32_t kernel_name_len = cmd_line_append - buf;
strncpy(kernel, buf, kernel_name_len);
kernel[kernel_name_len + 1] = '\0';
/* determine if console is set in the command line; if not,
* append it.
*/
if (!strstr(cmd_line,"console")) {
sprintf(cmd_line, "%s console=ttyS0,%d", cmd_line, baud);
}
} else {
cmd_line[0] = '\0';
strncpy(kernel, buf, 48);
sprintf(cmd_line, "console=ttyS0,%d", baud);
}
printf("\n\nAttempting to load file %s\n", kernel);

@ -56,7 +56,7 @@ char *strncpy(char *dest, const char *src, uint32_t n)
return dest;
}
uint32_t strlen(char *s)
uint32_t strlen(const char *s)
{
int i = 0;
@ -104,3 +104,20 @@ const char *strchr(const char *s, int c)
return NULL;
}
const char *strstr(const char *haystack, const char *needle)
{
int npos = 0; /* position within needle */
int nlen = strlen(needle);
char *start;
while (*haystack != '\0') {
if (npos == 0) start = haystack;
if (needle[npos] == *(haystack++)) npos++;
else npos = 0;
if (npos == nlen - 1) return start;
}
return NULL;
}

Loading…
Cancel
Save