[POWERPC] bootwrapper: Add a fatal error helper
Add a macro fatal that calls printf then exit. User must include stdio.h. Typically replaces 3 lines with 1, although I added back some whitespace. Signed-off-by: Milton Miller <miltonm@bga.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
This commit is contained in:
committed by
Paul Mackerras
parent
3771f2d9a4
commit
6a923216aa
@@ -52,18 +52,14 @@ void gunzip_start(struct gunzip_state *state, void *src, int srclen)
|
|||||||
int r, flags;
|
int r, flags;
|
||||||
|
|
||||||
state->s.workspace = state->scratch;
|
state->s.workspace = state->scratch;
|
||||||
if (zlib_inflate_workspacesize() > sizeof(state->scratch)) {
|
if (zlib_inflate_workspacesize() > sizeof(state->scratch))
|
||||||
printf("insufficient scratch space for gunzip\n\r");
|
fatal("insufficient scratch space for gunzip\n\r");
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* skip header */
|
/* skip header */
|
||||||
hdrlen = 10;
|
hdrlen = 10;
|
||||||
flags = hdr[3];
|
flags = hdr[3];
|
||||||
if (hdr[2] != Z_DEFLATED || (flags & RESERVED) != 0) {
|
if (hdr[2] != Z_DEFLATED || (flags & RESERVED) != 0)
|
||||||
printf("bad gzipped data\n\r");
|
fatal("bad gzipped data\n\r");
|
||||||
exit();
|
|
||||||
}
|
|
||||||
if ((flags & EXTRA_FIELD) != 0)
|
if ((flags & EXTRA_FIELD) != 0)
|
||||||
hdrlen = 12 + hdr[10] + (hdr[11] << 8);
|
hdrlen = 12 + hdr[10] + (hdr[11] << 8);
|
||||||
if ((flags & ORIG_NAME) != 0)
|
if ((flags & ORIG_NAME) != 0)
|
||||||
@@ -74,16 +70,12 @@ void gunzip_start(struct gunzip_state *state, void *src, int srclen)
|
|||||||
;
|
;
|
||||||
if ((flags & HEAD_CRC) != 0)
|
if ((flags & HEAD_CRC) != 0)
|
||||||
hdrlen += 2;
|
hdrlen += 2;
|
||||||
if (hdrlen >= srclen) {
|
if (hdrlen >= srclen)
|
||||||
printf("gunzip_start: ran out of data in header\n\r");
|
fatal("gunzip_start: ran out of data in header\n\r");
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
r = zlib_inflateInit2(&state->s, -MAX_WBITS);
|
r = zlib_inflateInit2(&state->s, -MAX_WBITS);
|
||||||
if (r != Z_OK) {
|
if (r != Z_OK)
|
||||||
printf("inflateInit2 returned %d\n\r", r);
|
fatal("inflateInit2 returned %d\n\r", r);
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state->s.next_in = src + hdrlen;
|
state->s.next_in = src + hdrlen;
|
||||||
@@ -117,10 +109,8 @@ int gunzip_partial(struct gunzip_state *state, void *dst, int dstlen)
|
|||||||
state->s.next_out = dst;
|
state->s.next_out = dst;
|
||||||
state->s.avail_out = dstlen;
|
state->s.avail_out = dstlen;
|
||||||
r = zlib_inflate(&state->s, Z_FULL_FLUSH);
|
r = zlib_inflate(&state->s, Z_FULL_FLUSH);
|
||||||
if (r != Z_OK && r != Z_STREAM_END) {
|
if (r != Z_OK && r != Z_STREAM_END)
|
||||||
printf("inflate returned %d msg: %s\n\r", r, state->s.msg);
|
fatal("inflate returned %d msg: %s\n\r", r, state->s.msg);
|
||||||
exit();
|
|
||||||
}
|
|
||||||
len = state->s.next_out - (unsigned char *)dst;
|
len = state->s.next_out - (unsigned char *)dst;
|
||||||
} else {
|
} else {
|
||||||
/* uncompressed image */
|
/* uncompressed image */
|
||||||
@@ -151,10 +141,8 @@ void gunzip_exactly(struct gunzip_state *state, void *dst, int dstlen)
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = gunzip_partial(state, dst, dstlen);
|
len = gunzip_partial(state, dst, dstlen);
|
||||||
if (len < dstlen) {
|
if (len < dstlen)
|
||||||
printf("gunzip_block: ran out of data\n\r");
|
fatal("gunzip_block: ran out of data\n\r");
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -118,10 +118,9 @@ static struct addr_range prep_kernel(void)
|
|||||||
gunzip_start(&gzstate, vmlinuz_addr, vmlinuz_size);
|
gunzip_start(&gzstate, vmlinuz_addr, vmlinuz_size);
|
||||||
gunzip_exactly(&gzstate, elfheader, sizeof(elfheader));
|
gunzip_exactly(&gzstate, elfheader, sizeof(elfheader));
|
||||||
|
|
||||||
if (!parse_elf64(elfheader, &ei) && !parse_elf32(elfheader, &ei)) {
|
if (!parse_elf64(elfheader, &ei) && !parse_elf32(elfheader, &ei))
|
||||||
printf("Error: not a valid PPC32 or PPC64 ELF file!\n\r");
|
fatal("Error: not a valid PPC32 or PPC64 ELF file!\n\r");
|
||||||
exit();
|
|
||||||
}
|
|
||||||
if (platform_ops.image_hdr)
|
if (platform_ops.image_hdr)
|
||||||
platform_ops.image_hdr(elfheader);
|
platform_ops.image_hdr(elfheader);
|
||||||
|
|
||||||
@@ -135,11 +134,9 @@ static struct addr_range prep_kernel(void)
|
|||||||
if (platform_ops.vmlinux_alloc) {
|
if (platform_ops.vmlinux_alloc) {
|
||||||
addr = platform_ops.vmlinux_alloc(ei.memsize);
|
addr = platform_ops.vmlinux_alloc(ei.memsize);
|
||||||
} else {
|
} else {
|
||||||
if ((unsigned long)_start < ei.memsize) {
|
if ((unsigned long)_start < ei.memsize)
|
||||||
printf("Insufficient memory for kernel at address 0!"
|
fatal("Insufficient memory for kernel at address 0!"
|
||||||
" (_start=%lx)\n\r", _start);
|
" (_start=%lx)\n\r", _start);
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finally, gunzip the kernel */
|
/* Finally, gunzip the kernel */
|
||||||
@@ -189,11 +186,9 @@ static struct addr_range prep_initrd(struct addr_range vmlinux,
|
|||||||
printf("Allocating 0x%lx bytes for initrd ...\n\r",
|
printf("Allocating 0x%lx bytes for initrd ...\n\r",
|
||||||
initrd_size);
|
initrd_size);
|
||||||
initrd_addr = (unsigned long)malloc(initrd_size);
|
initrd_addr = (unsigned long)malloc(initrd_size);
|
||||||
if (! initrd_addr) {
|
if (! initrd_addr)
|
||||||
printf("Can't allocate memory for initial "
|
fatal("Can't allocate memory for initial "
|
||||||
"ramdisk !\n\r");
|
"ramdisk !\n\r");
|
||||||
exit();
|
|
||||||
}
|
|
||||||
printf("Relocating initrd 0x%p <- 0x%p (0x%lx bytes)\n\r",
|
printf("Relocating initrd 0x%p <- 0x%p (0x%lx bytes)\n\r",
|
||||||
initrd_addr, old_addr, initrd_size);
|
initrd_addr, old_addr, initrd_size);
|
||||||
memmove((void *)initrd_addr, old_addr, initrd_size);
|
memmove((void *)initrd_addr, old_addr, initrd_size);
|
||||||
@@ -203,10 +198,8 @@ static struct addr_range prep_initrd(struct addr_range vmlinux,
|
|||||||
|
|
||||||
/* Tell the kernel initrd address via device tree */
|
/* Tell the kernel initrd address via device tree */
|
||||||
devp = finddevice("/chosen");
|
devp = finddevice("/chosen");
|
||||||
if (! devp) {
|
if (! devp)
|
||||||
printf("Device tree has no chosen node!\n\r");
|
fatal("Device tree has no chosen node!\n\r");
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
initrd_start = (u32)initrd_addr;
|
initrd_start = (u32)initrd_addr;
|
||||||
initrd_end = (u32)initrd_addr + initrd_size;
|
initrd_end = (u32)initrd_addr + initrd_size;
|
||||||
@@ -303,7 +296,6 @@ void start(void *sp)
|
|||||||
kentry((unsigned long)initrd.addr, initrd.size,
|
kentry((unsigned long)initrd.addr, initrd.size,
|
||||||
loader_info.promptr);
|
loader_info.promptr);
|
||||||
|
|
||||||
/* console closed so printf below may not work */
|
/* console closed so printf in fatal below may not work */
|
||||||
printf("Error: Linux kernel returned to zImage boot wrapper!\n\r");
|
fatal("Error: Linux kernel returned to zImage boot wrapper!\n\r");
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
@@ -212,10 +212,9 @@ static void *of_vmlinux_alloc(unsigned long size)
|
|||||||
{
|
{
|
||||||
void *p = malloc(size);
|
void *p = malloc(size);
|
||||||
|
|
||||||
if (!p) {
|
if (!p)
|
||||||
printf("Can't allocate memory for kernel image!\n\r");
|
fatal("Can't allocate memory for kernel image!\n\r");
|
||||||
exit();
|
|
||||||
}
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -158,6 +158,8 @@ static inline void exit(void)
|
|||||||
platform_ops.exit();
|
platform_ops.exit();
|
||||||
for(;;);
|
for(;;);
|
||||||
}
|
}
|
||||||
|
#define fatal(args...) { printf(args); exit(); }
|
||||||
|
|
||||||
|
|
||||||
#define BSS_STACK(size) \
|
#define BSS_STACK(size) \
|
||||||
static char _bss_stack[size]; \
|
static char _bss_stack[size]; \
|
||||||
|
Reference in New Issue
Block a user