[packages] flashrom: update source url, use PKG_INSTALL & MAKE_FLAGS, refresh patches
[openwrt/svn-archive/archive.git] / utils / petitboot / patches / 010-petitboot-fixups.diff
1 12 files changed, 96 insertions(+), 40 deletions(-)
2
3 diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c
4 index 23d48a4..7c7cb5d 100644
5 --- a/discover/kboot-parser.c
6 +++ b/discover/kboot-parser.c
7 @@ -133,7 +133,7 @@ static int kboot_parse(struct discover_context *dc)
8 conf = talloc_zero(dc, struct conf_context);
9
10 if (!conf)
11 - return -1;
12 + return 0;
13
14 conf->dc = dc;
15 conf->global_options = kboot_global_options,
16 diff --git a/discover/parser.c b/discover/parser.c
17 index 2b4ddd2..8f2735c 100644
18 --- a/discover/parser.c
19 +++ b/discover/parser.c
20 @@ -13,16 +13,16 @@ extern struct parser __start_parsers[], __stop_parsers[];
21 void iterate_parsers(struct discover_context *ctx)
22 {
23 struct parser *parser;
24 + unsigned int count = 0;
25
26 pb_log("trying parsers for %s\n", ctx->device_path);
27
28 for (parser = __start_parsers; parser < __stop_parsers; parser++) {
29 pb_log("\ttrying parser '%s'\n", parser->name);
30 - /* just use a dummy device path for now */
31 - if (parser->parse(ctx))
32 - return;
33 + count += parser->parse(ctx);
34 }
35 - pb_log("\tno boot_options found\n");
36 + if (!count)
37 + pb_log("\tno boot_options found\n");
38 }
39
40 static int compare_parsers(const void *a, const void *b)
41 diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c
42 index 1000505..6101cd8 100644
43 --- a/discover/yaboot-parser.c
44 +++ b/discover/yaboot-parser.c
45 @@ -295,7 +295,7 @@ static int yaboot_parse(struct discover_context *dc)
46 conf = talloc_zero(dc, struct conf_context);
47
48 if (!conf)
49 - return -1;
50 + return 0;
51
52 conf->dc = dc;
53 conf->global_options = yaboot_global_options,
54 diff --git a/lib/log/log.h b/lib/log/log.h
55 index 2a5d375..6f44bea 100644
56 --- a/lib/log/log.h
57 +++ b/lib/log/log.h
58 @@ -3,7 +3,7 @@
59
60 #include <stdio.h>
61
62 -void pb_log(const char *fmt, ...);
63 +void __attribute__ ((format (printf, 1, 2))) pb_log(const char *fmt, ...);
64 void pb_log_set_stream(FILE *stream);
65 FILE * pb_log_get_stream(void);
66 void pb_log_always_flush(int state);
67 diff --git a/lib/system/system.c b/lib/system/system.c
68 index 65bd6bf..7371445 100644
69 --- a/lib/system/system.c
70 +++ b/lib/system/system.c
71 @@ -20,6 +20,7 @@ const struct pb_system_apps pb_system_apps = {
72 .cp = "/bin/cp",
73 .kexec = "/sbin/kexec",
74 .mount = "/bin/mount",
75 + .shutdown = "/sbin/shutdown",
76 .sftp = "/usr/bin/sftp",
77 .tftp = "/usr/bin/tftp",
78 .umount = "/bin/umount",
79 diff --git a/lib/system/system.h b/lib/system/system.h
80 index 47c7c02..1918309 100644
81 --- a/lib/system/system.h
82 +++ b/lib/system/system.h
83 @@ -5,6 +5,7 @@ struct pb_system_apps {
84 const char *cp;
85 const char *kexec;
86 const char *mount;
87 + const char *shutdown;
88 const char *sftp;
89 const char *tftp;
90 const char *umount;
91 diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c
92 index e8ce4dd..5b42b6c 100644
93 --- a/ui/common/discover-client.c
94 +++ b/ui/common/discover-client.c
95 @@ -46,7 +46,7 @@ struct discover_client* discover_client_init(
96 client->ops.cb_arg = cb_arg;
97
98 client->fd = socket(AF_UNIX, SOCK_STREAM, 0);
99 - if (!client->fd < 0) {
100 + if (client->fd < 0) {
101 pb_log("%s: socket: %s\n", __func__, strerror(errno));
102 goto out_err;
103 }
104 diff --git a/ui/common/loader.c b/ui/common/loader.c
105 index 0fe62a0..5c69533 100644
106 --- a/ui/common/loader.c
107 +++ b/ui/common/loader.c
108 @@ -263,16 +263,22 @@ fail:
109 /**
110 * pb_load_file - Loads a remote file and returns the local file path.
111 * @ctx: The talloc context to associate with the returned string.
112 + * @remote: The remote file URL.
113 + * @tempfile: An optional variable pointer to be set when a temporary local
114 + * file is created.
115 *
116 * Returns the local file path in a talloc'ed character string on success,
117 * or NULL on error.
118 */
119
120 -char *pb_load_file(void *ctx, const char *remote)
121 +char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile)
122 {
123 char *local;
124 struct pb_url *url = pb_url_parse(NULL, remote);
125
126 + if (tempfile)
127 + *tempfile = 0;
128 +
129 if (!url)
130 return NULL;
131
132 @@ -280,19 +286,28 @@ char *pb_load_file(void *ctx, const char *remote)
133 case pb_url_ftp:
134 case pb_url_http:
135 local = pb_load_wget(ctx, url, 0);
136 + if (tempfile && local)
137 + *tempfile = 1;
138 break;
139 case pb_url_https:
140 - local = pb_load_wget(ctx, url,
141 - wget_no_check_certificate);
142 + local = pb_load_wget(ctx, url, wget_no_check_certificate);
143 + if (tempfile && local)
144 + *tempfile = 1;
145 break;
146 case pb_url_nfs:
147 local = pb_load_nfs(ctx, url);
148 + if (tempfile && local)
149 + *tempfile = 1;
150 break;
151 case pb_url_sftp:
152 local = pb_load_sftp(ctx, url);
153 + if (tempfile && local)
154 + *tempfile = 1;
155 break;
156 case pb_url_tftp:
157 local = pb_load_tftp(ctx, url);
158 + if (tempfile && local)
159 + *tempfile = 1;
160 break;
161 default:
162 local = talloc_strdup(ctx, url->full);
163 diff --git a/ui/common/loader.h b/ui/common/loader.h
164 index b06bb43..42d4d4b 100644
165 --- a/ui/common/loader.h
166 +++ b/ui/common/loader.h
167 @@ -19,6 +19,6 @@
168 #if !defined(_PB_FILE_LOADER_H)
169 #define _PB_FILE_LOADER_H
170
171 -char *pb_load_file(void *ctx, const char *remote);
172 +char *pb_load_file(void *ctx, const char *remote, unsigned int *tempfile);
173
174 #endif
175 diff --git a/ui/common/ps3.c b/ui/common/ps3.c
176 index cb1c8d1..c62a10d 100644
177 --- a/ui/common/ps3.c
178 +++ b/ui/common/ps3.c
179 @@ -87,7 +87,7 @@ static int ps3_flash_open(struct ps3_flash_ctx *fc, const char *mode)
180 result = os_area_fixed_read(&fc->header, &fc->params, fc->dev);
181
182 if (result) {
183 - pb_log("%s: os_area_fixed_read failed: %s\n", __func__);
184 + pb_log("%s: os_area_fixed_read failed\n", __func__);
185 goto fail;
186 }
187
188 @@ -114,7 +114,7 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
189 result = ps3_flash_open(&fc, "r");
190
191 if (result)
192 - goto done;
193 + goto fail;
194
195 result = os_area_db_read(&fc.db, &fc.header, fc.dev);
196
197 @@ -123,7 +123,7 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
198 if (result) {
199 pb_log("%s: os_area_db_read failed: %s\n", __func__,
200 strerror(errno));
201 - goto done;
202 + goto fail;
203 }
204
205 sum = result = os_area_db_get(&fc.db, &id_default_item, &tmp);
206 @@ -141,14 +141,13 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
207 if (!result)
208 values->video_mode = (uint16_t)tmp;
209
210 -done:
211 pb_log("%s: default_item: %x\n", __func__,
212 (unsigned int)values->default_item);
213 pb_log("%s: timeout: %u\n", __func__,
214 (unsigned int)values->timeout);
215 pb_log("%s: video_mode: %u\n", __func__,
216 (unsigned int)values->video_mode);
217 -
218 +fail:
219 return (result || sum) ? -1 : 0;
220 }
221
222 diff --git a/ui/common/ui-system.c b/ui/common/ui-system.c
223 index bd6dd31..0140f0e 100644
224 --- a/ui/common/ui-system.c
225 +++ b/ui/common/ui-system.c
226 @@ -33,13 +33,13 @@
227 #include "ui-system.h"
228
229 /**
230 - * run_kexec_local - Final kexec helper.
231 + * kexec_load - kexec load helper.
232 * @l_image: The local image file for kexec to execute.
233 * @l_initrd: Optional local initrd file for kexec --initrd, can be NULL.
234 * @args: Optional command line args for kexec --append, can be NULL.
235 */
236
237 -static int run_kexec_local(const char *l_image, const char *l_initrd,
238 +static int kexec_load(const char *l_image, const char *l_initrd,
239 const char *args)
240 {
241 int result;
242 @@ -49,34 +49,64 @@ static int run_kexec_local(const char *l_image, const char *l_initrd,
243 char *s_args = NULL;
244
245 p = argv;
246 - *p++ = pb_system_apps.kexec; /* 1 */
247 + *p++ = pb_system_apps.kexec; /* 1 */
248 + *p++ = "-l"; /* 2 */
249
250 if (l_initrd) {
251 s_initrd = talloc_asprintf(NULL, "--initrd=%s", l_initrd);
252 assert(s_initrd);
253 - *p++ = s_initrd; /* 2 */
254 + *p++ = s_initrd; /* 3 */
255 }
256
257 if (args) {
258 s_args = talloc_asprintf(NULL, "--append=%s", args);
259 assert(s_args);
260 - *p++ = s_args; /* 3 */
261 + *p++ = s_args; /* 4 */
262 }
263
264 - /* First try by telling kexec to run shutdown */
265 + *p++ = l_image; /* 5 */
266 + *p++ = NULL; /* 6 */
267
268 - *(p + 0) = l_image;
269 - *(p + 1) = NULL;
270 + result = pb_run_cmd(argv);
271 +
272 + if (result)
273 + pb_log("%s: failed: (%d)\n", __func__, result);
274 +
275 + talloc_free(s_initrd);
276 + talloc_free(s_args);
277 +
278 + return result;
279 +}
280 +
281 +/**
282 + * kexec_reboot - Helper to boot the new kernel.
283 + *
284 + * Must only be called after a successful call to kexec_load().
285 + */
286 +
287 +static int kexec_reboot(void)
288 +{
289 + int result;
290 + const char *argv[4];
291 + const char **p;
292 +
293 + /* First try running shutdown. Init scripts should run 'exec -e' */
294 +
295 + p = argv;
296 + *p++ = pb_system_apps.shutdown; /* 1 */
297 + *p++ = "-r"; /* 2 */
298 + *p++ = "now"; /* 3 */
299 + *p++ = NULL; /* 4 */
300
301 result = pb_run_cmd(argv);
302
303 - /* kexec will return zero on success */
304 - /* On error, force a kexec with the -f option */
305 + /* On error, force a kexec with the -e option */
306
307 if (result) {
308 - *(p + 0) = "-f"; /* 4 */
309 - *(p + 1) = l_image; /* 5 */
310 - *(p + 2) = NULL; /* 6 */
311 + p = argv;
312 + *p++ = pb_system_apps.kexec; /* 1 */
313 + *p++ = "-e"; /* 2 */
314 + *p++ = NULL; /* 3 */
315
316 result = pb_run_cmd(argv);
317 }
318 @@ -84,9 +114,6 @@ static int run_kexec_local(const char *l_image, const char *l_initrd,
319 if (result)
320 pb_log("%s: failed: (%d)\n", __func__, result);
321
322 - talloc_free(s_initrd);
323 - talloc_free(s_args);
324 -
325 return result;
326 }
327
328 @@ -99,31 +126,44 @@ int pb_run_kexec(const struct pb_kexec_data *kd)
329 int result;
330 char *l_image = NULL;
331 char *l_initrd = NULL;
332 + unsigned int clean_image = 0;
333 + unsigned int clean_initrd = 0;
334
335 pb_log("%s: image: '%s'\n", __func__, kd->image);
336 pb_log("%s: initrd: '%s'\n", __func__, kd->initrd);
337 pb_log("%s: args: '%s'\n", __func__, kd->args);
338
339 + result = -1;
340 +
341 if (kd->image) {
342 - l_image = pb_load_file(NULL, kd->image);
343 + l_image = pb_load_file(NULL, kd->image, &clean_image);
344 if (!l_image)
345 - return -1;
346 + goto no_load;
347 }
348
349 if (kd->initrd) {
350 - l_initrd = pb_load_file(NULL, kd->initrd);
351 + l_initrd = pb_load_file(NULL, kd->initrd, &clean_initrd);
352 if (!l_initrd)
353 - return -1;
354 + goto no_load;
355 }
356
357 if (!l_image && !l_initrd)
358 - return -1;
359 + goto no_load;
360 +
361 + result = kexec_load(l_image, l_initrd, kd->args);
362
363 - result = run_kexec_local(l_image, l_initrd, kd->args);
364 +no_load:
365 + if (clean_image)
366 + unlink(l_image);
367 + if (clean_initrd)
368 + unlink(l_initrd);
369
370 talloc_free(l_image);
371 talloc_free(l_initrd);
372
373 + if (!result)
374 + result = kexec_reboot();
375 +
376 return result;
377 }
378
379 diff --git a/ui/common/url.c b/ui/common/url.c
380 index 0de0f58..544eee2 100644
381 --- a/ui/common/url.c
382 +++ b/ui/common/url.c
383 @@ -140,7 +140,7 @@ struct pb_url *pb_url_parse(void *ctx, const char *url_str)
384 path = strchr(p, '/');
385
386 if (!path) {
387 - pb_log("%s: parse path failed '%s'\n", p);
388 + pb_log("%s: parse path failed '%s'\n", __func__ , p);
389 goto fail;
390 }
391