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 <elf.h>
#include <types.h> #include <types.h>

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

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

@ -183,3 +183,22 @@ int c_strnlen(const char *s, int maxlen)
return i; 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"
);
}

@ -88,6 +88,9 @@ enter_filename:
printf("\nEnter filename to boot:\n> "); printf("\nEnter filename to boot:\n> ");
c_gets(buf, 128); 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 */ /* determine if a command line string has been appended to kernel name */
if ((cmd_line_append = strchr(buf, ' ')) != NULL) { if ((cmd_line_append = strchr(buf, ' ')) != NULL) {
strcpy(cmd_line, (char *)(cmd_line_append + 1)); strcpy(cmd_line, (char *)(cmd_line_append + 1));
@ -95,9 +98,16 @@ enter_filename:
uint32_t kernel_name_len = cmd_line_append - buf; uint32_t kernel_name_len = cmd_line_append - buf;
strncpy(kernel, buf, kernel_name_len); strncpy(kernel, buf, kernel_name_len);
kernel[kernel_name_len + 1] = '\0'; 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 { } else {
cmd_line[0] = '\0';
strncpy(kernel, buf, 48); strncpy(kernel, buf, 48);
sprintf(cmd_line, "console=ttyS0,%d", baud);
} }
printf("\n\nAttempting to load file %s\n", kernel); 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; return dest;
} }
uint32_t strlen(char *s) uint32_t strlen(const char *s)
{ {
int i = 0; int i = 0;
@ -104,3 +104,20 @@ const char *strchr(const char *s, int c)
return NULL; 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