aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMilton Miller <miltonm@bga.com>2007-03-21 11:02:44 -0400
committerPaul Mackerras <paulus@samba.org>2007-03-26 01:11:20 -0400
commit6a923216aac01d0f3eeea606377b81541f1a2773 (patch)
tree77e88aa9ce939ba895d49c17ca7dcb28fe8672df /arch
parent3771f2d9a46ca3b57e473afe929196efad7f3aa6 (diff)
[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>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/boot/gunzip_util.c36
-rw-r--r--arch/powerpc/boot/main.c30
-rw-r--r--arch/powerpc/boot/of.c7
-rw-r--r--arch/powerpc/boot/ops.h2
4 files changed, 28 insertions, 47 deletions
diff --git a/arch/powerpc/boot/gunzip_util.c b/arch/powerpc/boot/gunzip_util.c
index f7c95f24fcdd..8a97adfac659 100644
--- a/arch/powerpc/boot/gunzip_util.c
+++ b/arch/powerpc/boot/gunzip_util.c
@@ -52,18 +52,14 @@ void gunzip_start(struct gunzip_state *state, void *src, int srclen)
52 int r, flags; 52 int r, flags;
53 53
54 state->s.workspace = state->scratch; 54 state->s.workspace = state->scratch;
55 if (zlib_inflate_workspacesize() > sizeof(state->scratch)) { 55 if (zlib_inflate_workspacesize() > sizeof(state->scratch))
56 printf("insufficient scratch space for gunzip\n\r"); 56 fatal("insufficient scratch space for gunzip\n\r");
57 exit();
58 }
59 57
60 /* skip header */ 58 /* skip header */
61 hdrlen = 10; 59 hdrlen = 10;
62 flags = hdr[3]; 60 flags = hdr[3];
63 if (hdr[2] != Z_DEFLATED || (flags & RESERVED) != 0) { 61 if (hdr[2] != Z_DEFLATED || (flags & RESERVED) != 0)
64 printf("bad gzipped data\n\r"); 62 fatal("bad gzipped data\n\r");
65 exit();
66 }
67 if ((flags & EXTRA_FIELD) != 0) 63 if ((flags & EXTRA_FIELD) != 0)
68 hdrlen = 12 + hdr[10] + (hdr[11] << 8); 64 hdrlen = 12 + hdr[10] + (hdr[11] << 8);
69 if ((flags & ORIG_NAME) != 0) 65 if ((flags & ORIG_NAME) != 0)
@@ -74,16 +70,12 @@ void gunzip_start(struct gunzip_state *state, void *src, int srclen)
74 ; 70 ;
75 if ((flags & HEAD_CRC) != 0) 71 if ((flags & HEAD_CRC) != 0)
76 hdrlen += 2; 72 hdrlen += 2;
77 if (hdrlen >= srclen) { 73 if (hdrlen >= srclen)
78 printf("gunzip_start: ran out of data in header\n\r"); 74 fatal("gunzip_start: ran out of data in header\n\r");
79 exit();
80 }
81 75
82 r = zlib_inflateInit2(&state->s, -MAX_WBITS); 76 r = zlib_inflateInit2(&state->s, -MAX_WBITS);
83 if (r != Z_OK) { 77 if (r != Z_OK)
84 printf("inflateInit2 returned %d\n\r", r); 78 fatal("inflateInit2 returned %d\n\r", r);
85 exit();
86 }
87 } 79 }
88 80
89 state->s.next_in = src + hdrlen; 81 state->s.next_in = src + hdrlen;
@@ -117,10 +109,8 @@ int gunzip_partial(struct gunzip_state *state, void *dst, int dstlen)
117 state->s.next_out = dst; 109 state->s.next_out = dst;
118 state->s.avail_out = dstlen; 110 state->s.avail_out = dstlen;
119 r = zlib_inflate(&state->s, Z_FULL_FLUSH); 111 r = zlib_inflate(&state->s, Z_FULL_FLUSH);
120 if (r != Z_OK && r != Z_STREAM_END) { 112 if (r != Z_OK && r != Z_STREAM_END)
121 printf("inflate returned %d msg: %s\n\r", r, state->s.msg); 113 fatal("inflate returned %d msg: %s\n\r", r, state->s.msg);
122 exit();
123 }
124 len = state->s.next_out - (unsigned char *)dst; 114 len = state->s.next_out - (unsigned char *)dst;
125 } else { 115 } else {
126 /* uncompressed image */ 116 /* uncompressed image */
@@ -151,10 +141,8 @@ void gunzip_exactly(struct gunzip_state *state, void *dst, int dstlen)
151 int len; 141 int len;
152 142
153 len = gunzip_partial(state, dst, dstlen); 143 len = gunzip_partial(state, dst, dstlen);
154 if (len < dstlen) { 144 if (len < dstlen)
155 printf("gunzip_block: ran out of data\n\r"); 145 fatal("gunzip_block: ran out of data\n\r");
156 exit();
157 }
158} 146}
159 147
160/** 148/**
diff --git a/arch/powerpc/boot/main.c b/arch/powerpc/boot/main.c
index d872b758ef14..df9e95a84015 100644
--- a/arch/powerpc/boot/main.c
+++ b/arch/powerpc/boot/main.c
@@ -118,10 +118,9 @@ static struct addr_range prep_kernel(void)
118 gunzip_start(&gzstate, vmlinuz_addr, vmlinuz_size); 118 gunzip_start(&gzstate, vmlinuz_addr, vmlinuz_size);
119 gunzip_exactly(&gzstate, elfheader, sizeof(elfheader)); 119 gunzip_exactly(&gzstate, elfheader, sizeof(elfheader));
120 120
121 if (!parse_elf64(elfheader, &ei) && !parse_elf32(elfheader, &ei)) { 121 if (!parse_elf64(elfheader, &ei) && !parse_elf32(elfheader, &ei))
122 printf("Error: not a valid PPC32 or PPC64 ELF file!\n\r"); 122 fatal("Error: not a valid PPC32 or PPC64 ELF file!\n\r");
123 exit(); 123
124 }
125 if (platform_ops.image_hdr) 124 if (platform_ops.image_hdr)
126 platform_ops.image_hdr(elfheader); 125 platform_ops.image_hdr(elfheader);
127 126
@@ -135,11 +134,9 @@ static struct addr_range prep_kernel(void)
135 if (platform_ops.vmlinux_alloc) { 134 if (platform_ops.vmlinux_alloc) {
136 addr = platform_ops.vmlinux_alloc(ei.memsize); 135 addr = platform_ops.vmlinux_alloc(ei.memsize);
137 } else { 136 } else {
138 if ((unsigned long)_start < ei.memsize) { 137 if ((unsigned long)_start < ei.memsize)
139 printf("Insufficient memory for kernel at address 0!" 138 fatal("Insufficient memory for kernel at address 0!"
140 " (_start=%lx)\n\r", _start); 139 " (_start=%lx)\n\r", _start);
141 exit();
142 }
143 } 140 }
144 141
145 /* Finally, gunzip the kernel */ 142 /* Finally, gunzip the kernel */
@@ -189,11 +186,9 @@ static struct addr_range prep_initrd(struct addr_range vmlinux,
189 printf("Allocating 0x%lx bytes for initrd ...\n\r", 186 printf("Allocating 0x%lx bytes for initrd ...\n\r",
190 initrd_size); 187 initrd_size);
191 initrd_addr = (unsigned long)malloc(initrd_size); 188 initrd_addr = (unsigned long)malloc(initrd_size);
192 if (! initrd_addr) { 189 if (! initrd_addr)
193 printf("Can't allocate memory for initial " 190 fatal("Can't allocate memory for initial "
194 "ramdisk !\n\r"); 191 "ramdisk !\n\r");
195 exit();
196 }
197 printf("Relocating initrd 0x%p <- 0x%p (0x%lx bytes)\n\r", 192 printf("Relocating initrd 0x%p <- 0x%p (0x%lx bytes)\n\r",
198 initrd_addr, old_addr, initrd_size); 193 initrd_addr, old_addr, initrd_size);
199 memmove((void *)initrd_addr, old_addr, initrd_size); 194 memmove((void *)initrd_addr, old_addr, initrd_size);
@@ -203,10 +198,8 @@ static struct addr_range prep_initrd(struct addr_range vmlinux,
203 198
204 /* Tell the kernel initrd address via device tree */ 199 /* Tell the kernel initrd address via device tree */
205 devp = finddevice("/chosen"); 200 devp = finddevice("/chosen");
206 if (! devp) { 201 if (! devp)
207 printf("Device tree has no chosen node!\n\r"); 202 fatal("Device tree has no chosen node!\n\r");
208 exit();
209 }
210 203
211 initrd_start = (u32)initrd_addr; 204 initrd_start = (u32)initrd_addr;
212 initrd_end = (u32)initrd_addr + initrd_size; 205 initrd_end = (u32)initrd_addr + initrd_size;
@@ -303,7 +296,6 @@ void start(void *sp)
303 kentry((unsigned long)initrd.addr, initrd.size, 296 kentry((unsigned long)initrd.addr, initrd.size,
304 loader_info.promptr); 297 loader_info.promptr);
305 298
306 /* console closed so printf below may not work */ 299 /* console closed so printf in fatal below may not work */
307 printf("Error: Linux kernel returned to zImage boot wrapper!\n\r"); 300 fatal("Error: Linux kernel returned to zImage boot wrapper!\n\r");
308 exit();
309} 301}
diff --git a/arch/powerpc/boot/of.c b/arch/powerpc/boot/of.c
index c6f0d9701485..2cec5c17fb60 100644
--- a/arch/powerpc/boot/of.c
+++ b/arch/powerpc/boot/of.c
@@ -212,10 +212,9 @@ static void *of_vmlinux_alloc(unsigned long size)
212{ 212{
213 void *p = malloc(size); 213 void *p = malloc(size);
214 214
215 if (!p) { 215 if (!p)
216 printf("Can't allocate memory for kernel image!\n\r"); 216 fatal("Can't allocate memory for kernel image!\n\r");
217 exit(); 217
218 }
219 return p; 218 return p;
220} 219}
221 220
diff --git a/arch/powerpc/boot/ops.h b/arch/powerpc/boot/ops.h
index 93608b772db5..ea5368caca59 100644
--- a/arch/powerpc/boot/ops.h
+++ b/arch/powerpc/boot/ops.h
@@ -158,6 +158,8 @@ static inline void exit(void)
158 platform_ops.exit(); 158 platform_ops.exit();
159 for(;;); 159 for(;;);
160} 160}
161#define fatal(args...) { printf(args); exit(); }
162
161 163
162#define BSS_STACK(size) \ 164#define BSS_STACK(size) \
163 static char _bss_stack[size]; \ 165 static char _bss_stack[size]; \