PERFORCE change 97497 for review
Warner Losh
imp at FreeBSD.org
Sat May 20 06:04:43 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=97497
Change 97497 by imp at imp_plunger on 2006/05/20 06:03:47
We're going to boot the kernel directly, and that will be a ELF
file. Right now we're booting the .bin file, but there's
little reason why we can't boot the ELF file directly, I think,
when we boot off the SD card. Also, eliminate enough options
that we save 4 bytes.
Affected files ...
.. //depot/projects/arm/src/sys/boot/arm/at91/boot2/boot2.c#4 edit
Differences ...
==== //depot/projects/arm/src/sys/boot/arm/at91/boot2/boot2.c#4 (text+ko) ====
@@ -26,8 +26,6 @@
#include <stdarg.h>
-#include <a.out.h>
-
#include "lib.h"
#define SECOND 18 /* Circa that many ticks in a second. */
@@ -44,11 +42,11 @@
/* 0x9 is reserved for log2(RB_MINIROOT). */
#define RBX_CONFIG 0xa /* -c */
#define RBX_VERBOSE 0xb /* -v */
-#define RBX_SERIAL 0xc /* -h */
-#define RBX_CDROM 0xd /* -C */
+/* #define RBX_SERIAL 0xc -h */
+/* #define RBX_CDROM 0xd -C */
/* 0xe is reserved for log2(RB_POWEROFF). */
#define RBX_GDB 0xf /* -g */
-#define RBX_MUTE 0x10 /* -m */
+/* #define RBX_MUTE 0x10 -m */
/* 0x11 is reserved for log2(RB_SELFTEST). */
/* 0x12 is reserved for boot programs. */
/* 0x13 is reserved for boot programs. */
@@ -56,22 +54,21 @@
#define RBX_QUIET 0x15 /* -q */
#define RBX_NOINTR 0x1c /* -n */
/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */
-#define RBX_DUAL 0x1d /* -D */
+/* #define RBX_DUAL 0x1d -D */
/* 0x1f is reserved for log2(RB_BOOTINFO). */
-/* pass: -a, -s, -r, -d, -c, -v, -h, -C, -g, -m, -p, -D */
+/* pass: -a, -s, -r, -d, -c, -v, -g, -p */
#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \
OPT_SET(RBX_DFLTROOT) | OPT_SET(RBX_KDB ) | \
OPT_SET(RBX_CONFIG) | OPT_SET(RBX_VERBOSE) | \
- OPT_SET(RBX_SERIAL) | OPT_SET(RBX_CDROM) | \
- OPT_SET(RBX_GDB ) | OPT_SET(RBX_MUTE) | \
- OPT_SET(RBX_PAUSE) | OPT_SET(RBX_DUAL))
+ OPT_SET(RBX_GDB) | \
+ OPT_SET(RBX_PAUSE))
#define PATH_CONFIG "/boot.config"
#define PATH_KERNEL "/boot/kernel/kernel"
#define ARGS 0x900
-#define NOPT 12
+#define NOPT 8
#define NDEV 3
#define MEM_BASE 0x12
#define MEM_EXT 0x15
@@ -89,14 +86,10 @@
extern uint32_t _end;
-static const char optstr[NOPT] = "DhaCgmnpqrsv"; /* Also 'P' */
+static const char optstr[NOPT] = "agnpqrsv"; /* Also 'P' */
static const unsigned char flags[NOPT] = {
- RBX_DUAL,
- RBX_SERIAL,
RBX_ASKNAME,
- RBX_CDROM,
RBX_GDB,
- RBX_MUTE,
RBX_NOINTR,
RBX_PAUSE,
RBX_QUIET,
@@ -105,16 +98,12 @@
RBX_VERBOSE
};
-static const char *const dev_nm[NDEV] = {"ad", "da", "fd"};
-static const unsigned char dev_maj[NDEV] = {30, 4, 2};
-
int dsk_start;
static char cmd[512];
static char kname[1024];
static uint32_t opts;
//static int comspeed = SIOSPD;
-void exit(int);
static void load(void);
static int parse(void);
static int xfsread(ino_t, void *, size_t);
@@ -234,88 +223,54 @@
static void
load(void)
{
- union {
- struct exec ex;
- Elf32_Ehdr eh;
- } hdr;
+ Elf32_Ehdr eh;
static Elf32_Phdr ep[2];
static Elf32_Shdr es[2];
caddr_t p;
ino_t ino;
- uint32_t addr, x;
- int fmt, i, j;
+ uint32_t addr;
+ int i, j;
if (!(ino = lookup(kname))) {
if (!ls)
printf("No %s\n", kname);
return;
}
- if (xfsread(ino, &hdr, sizeof(hdr)))
+ if (xfsread(ino, &eh, sizeof(eh)))
return;
- if (N_GETMAGIC(hdr.ex) == ZMAGIC)
- fmt = 0;
- else if (IS_ELF(hdr.eh))
- fmt = 1;
- else {
- printf("Invalid %s\n", "format");
+ if (!IS_ELF(eh)) {
+ printf("Invalid format\r\n");
return;
}
- if (fmt == 0) {
- addr = hdr.ex.a_entry;
- p = (caddr_t)addr;
- fs_off = PAGE_SIZE;
- if (xfsread(ino, p, hdr.ex.a_text))
+ fs_off = eh.e_phoff;
+ for (j = i = 0; i < eh.e_phnum && j < 2; i++) {
+ if (xfsread(ino, ep + j, sizeof(ep[0])))
+ return;
+ if (ep[j].p_type == PT_LOAD)
+ j++;
+ }
+ for (i = 0; i < 2; i++) {
+ p = (caddr_t)ep[i].p_paddr;
+ fs_off = ep[i].p_offset;
+ if (xfsread(ino, p, ep[i].p_filesz))
return;
- p += roundup2(hdr.ex.a_text, PAGE_SIZE);
- if (xfsread(ino, p, hdr.ex.a_data))
+ }
+ p += roundup2(ep[1].p_memsz, PAGE_SIZE);
+ if (eh.e_shnum == eh.e_shstrndx + 3) {
+ fs_off = eh.e_shoff + sizeof(es[0]) *
+ (eh.e_shstrndx + 1);
+ if (xfsread(ino, &es, sizeof(es)))
return;
- p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE);
- memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
- p += sizeof(hdr.ex.a_syms);
- if (hdr.ex.a_syms) {
- if (xfsread(ino, p, hdr.ex.a_syms))
- return;
- p += hdr.ex.a_syms;
- if (xfsread(ino, p, sizeof(int)))
- return;
- x = *(uint32_t *)p;
- p += sizeof(int);
- x -= sizeof(int);
- if (xfsread(ino, p, x))
- return;
- p += x;
- }
- } else {
- fs_off = hdr.eh.e_phoff;
- for (j = i = 0; i < hdr.eh.e_phnum && j < 2; i++) {
- if (xfsread(ino, ep + j, sizeof(ep[0])))
- return;
- if (ep[j].p_type == PT_LOAD)
- j++;
- }
for (i = 0; i < 2; i++) {
- p = (caddr_t)ep[i].p_paddr;
- fs_off = ep[i].p_offset;
- if (xfsread(ino, p, ep[i].p_filesz))
+ memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
+ p += sizeof(es[i].sh_size);
+ fs_off = es[i].sh_offset;
+ if (xfsread(ino, p, es[i].sh_size))
return;
- }
- p += roundup2(ep[1].p_memsz, PAGE_SIZE);
- if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) {
- fs_off = hdr.eh.e_shoff + sizeof(es[0]) *
- (hdr.eh.e_shstrndx + 1);
- if (xfsread(ino, &es, sizeof(es)))
- return;
- for (i = 0; i < 2; i++) {
- memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
- p += sizeof(es[i].sh_size);
- fs_off = es[i].sh_offset;
- if (xfsread(ino, p, es[i].sh_size))
- return;
- p += es[i].sh_size;
- }
+ p += es[i].sh_size;
}
- addr = hdr.eh.e_entry;
}
+ addr = eh.e_entry;
((void(*)(int))addr)(RB_BOOTINFO | (opts & RBX_MASK));
}
More information about the p4-projects
mailing list