78 lines
1.6 KiB
C
78 lines
1.6 KiB
C
#include <crt.h>
|
|
#include <dtb.h>
|
|
#include <log.h>
|
|
#include <mem.h>
|
|
#include <memory.h>
|
|
#include <power.h>
|
|
#include <serial.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <synchronize.h>
|
|
#include <tag.h>
|
|
|
|
extern int main(int, char *const *);
|
|
|
|
extern char __bss_start;
|
|
extern char _etext[];
|
|
extern char _end[];
|
|
|
|
#define PROPTAG_GET_COMMAND_LINE 0x00050001
|
|
|
|
struct __attribute__((packed)) command_line {
|
|
uint32_t id;
|
|
uint32_t value_len;
|
|
uint32_t param_len;
|
|
uint8_t str[2048];
|
|
};
|
|
|
|
static size_t split(char *src, char *dst[], size_t len) {
|
|
int i = 0;
|
|
char *rem = src;
|
|
|
|
while (rem != NULL && *rem != '\0' && i < len) {
|
|
char *e = strstr(rem, " ");
|
|
dst[i++] = rem;
|
|
if (e != NULL) {
|
|
*e = '\0';
|
|
while (*(++e) == ' ')
|
|
;
|
|
}
|
|
rem = e;
|
|
}
|
|
|
|
return (i);
|
|
}
|
|
|
|
void gilbraltar_sysinit(void) {
|
|
enable_fiqs();
|
|
enable_irqs();
|
|
memset(&__bss_start, 0, (uintptr_t)_end - (uintptr_t)__bss_start);
|
|
crt_init_ssp();
|
|
|
|
gilbraltar_serial_init();
|
|
gilbraltar_memory_init();
|
|
|
|
struct command_line p;
|
|
char *cmdline[64] = {NULL};
|
|
size_t ac = 1;
|
|
cmdline[0] = "gilbraltar";
|
|
|
|
if (!gilbraltar_get_tag(PROPTAG_GET_COMMAND_LINE, &p, sizeof(p), 2048)) {
|
|
gilbraltar_log(ERROR, "Impossible to retrieve cmdline.txt.\r\n");
|
|
ac = 1;
|
|
} else if (p.param_len >= sizeof(p.str)) {
|
|
gilbraltar_log(ERROR, "cmdline.txt too long.\r\n");
|
|
ac = 1;
|
|
} else {
|
|
p.str[p.param_len] = '\0';
|
|
ac = split((char *)p.str, cmdline + 1, 62);
|
|
}
|
|
|
|
gilbraltar_dtb_init();
|
|
|
|
int ret = main(ac + 1, cmdline);
|
|
gilbraltar_log(DEBUG, "End of program: %3d.", ret);
|
|
|
|
if (ret == 0)
|
|
poweroff();
|
|
}
|