diff --git a/elf2mzip/elf2img.c b/elf2mzip/elf2img.c index 33bcb64..a7873d7 100644 --- a/elf2mzip/elf2img.c +++ b/elf2mzip/elf2img.c @@ -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 + * + * Licensed under the GNU General Public License v2. See COPYING + * in the distribution source directory for more information. + * + */ + #include #include diff --git a/include/promlib.h b/include/promlib.h index 9a61951..09e31fb 100644 --- a/include/promlib.h +++ b/include/promlib.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 */ diff --git a/include/string.h b/include/string.h index 0546c90..26dc91d 100644 --- a/include/string.h +++ b/include/string.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 */ diff --git a/mach/c3600/promlib.c b/mach/c3600/promlib.c index 3665466..5b58ce4 100644 --- a/mach/c3600/promlib.c +++ b/mach/c3600/promlib.c @@ -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" + ); +} diff --git a/main.c b/main.c index 1ff6a29..3a2933b 100644 --- a/main.c +++ b/main.c @@ -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); diff --git a/string.c b/string.c index 64a9384..6d5bccc 100644 --- a/string.c +++ b/string.c @@ -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; +}