aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware
diff options
context:
space:
mode:
authorRoy Franz <roy.franz@linaro.org>2013-09-22 18:45:39 -0400
committerMatt Fleming <matt.fleming@intel.com>2013-09-25 07:34:43 -0400
commit46f4582e7cbc5f30127183812d4da875782518f5 (patch)
tree64ec73c1251abeac12d1e1da6a37fb05ba60bd55 /drivers/firmware
parent0e1cadb05bba2293b4575c8cab275313d181d94f (diff)
efi: Generalize handle_ramdisks() and rename to handle_cmdline_files().
The handle_cmdline_files now takes the option to handle as a string, and returns the loaded data through parameters, rather than taking an x86 specific setup_header structure. For ARM, this will be used to load a device tree blob in addition to initrd images. Signed-off-by: Roy Franz <roy.franz@linaro.org> Acked-by: Mark Salter <msalter@redhat.com> Reviewed-by: Grant Likely <grant.likely@linaro.org> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'drivers/firmware')
-rw-r--r--drivers/firmware/efi/efi-stub-helper.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c
index fda510fa3579..8c7839437c14 100644
--- a/drivers/firmware/efi/efi-stub-helper.c
+++ b/drivers/firmware/efi/efi-stub-helper.c
@@ -269,9 +269,12 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
269 * We only support loading an initrd from the same filesystem as the 269 * We only support loading an initrd from the same filesystem as the
270 * kernel image. 270 * kernel image.
271 */ 271 */
272static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg, 272static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
273 efi_loaded_image_t *image, 273 efi_loaded_image_t *image,
274 struct setup_header *hdr) 274 char *cmd_line, char *option_string,
275 unsigned long max_addr,
276 unsigned long *load_addr,
277 unsigned long *load_size)
275{ 278{
276 struct initrd *initrds; 279 struct initrd *initrds;
277 unsigned long initrd_addr; 280 unsigned long initrd_addr;
@@ -287,19 +290,25 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg,
287 initrd_addr = 0; 290 initrd_addr = 0;
288 initrd_total = 0; 291 initrd_total = 0;
289 292
290 str = (char *)(unsigned long)hdr->cmd_line_ptr; 293 str = cmd_line;
291 294
292 j = 0; /* See close_handles */ 295 j = 0; /* See close_handles */
293 296
297 if (!load_addr || !load_size)
298 return EFI_INVALID_PARAMETER;
299
300 *load_addr = 0;
301 *load_size = 0;
302
294 if (!str || !*str) 303 if (!str || !*str)
295 return EFI_SUCCESS; 304 return EFI_SUCCESS;
296 305
297 for (nr_initrds = 0; *str; nr_initrds++) { 306 for (nr_initrds = 0; *str; nr_initrds++) {
298 str = strstr(str, "initrd="); 307 str = strstr(str, option_string);
299 if (!str) 308 if (!str)
300 break; 309 break;
301 310
302 str += 7; 311 str += strlen(option_string);
303 312
304 /* Skip any leading slashes */ 313 /* Skip any leading slashes */
305 while (*str == '/' || *str == '\\') 314 while (*str == '/' || *str == '\\')
@@ -317,11 +326,11 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg,
317 nr_initrds * sizeof(*initrds), 326 nr_initrds * sizeof(*initrds),
318 &initrds); 327 &initrds);
319 if (status != EFI_SUCCESS) { 328 if (status != EFI_SUCCESS) {
320 efi_printk(sys_table_arg, "Failed to alloc mem for initrds\n"); 329 efi_printk(sys_table_arg, "Failed to alloc mem for file load\n");
321 goto fail; 330 goto fail;
322 } 331 }
323 332
324 str = (char *)(unsigned long)hdr->cmd_line_ptr; 333 str = cmd_line;
325 for (i = 0; i < nr_initrds; i++) { 334 for (i = 0; i < nr_initrds; i++) {
326 struct initrd *initrd; 335 struct initrd *initrd;
327 efi_file_handle_t *h; 336 efi_file_handle_t *h;
@@ -332,11 +341,11 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg,
332 efi_char16_t *p; 341 efi_char16_t *p;
333 u64 file_sz; 342 u64 file_sz;
334 343
335 str = strstr(str, "initrd="); 344 str = strstr(str, option_string);
336 if (!str) 345 if (!str)
337 break; 346 break;
338 347
339 str += 7; 348 str += strlen(option_string);
340 349
341 initrd = &initrds[i]; 350 initrd = &initrds[i];
342 p = filename_16; 351 p = filename_16;
@@ -382,7 +391,7 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg,
382 status = efi_call_phys5(fh->open, fh, &h, filename_16, 391 status = efi_call_phys5(fh->open, fh, &h, filename_16,
383 EFI_FILE_MODE_READ, (u64)0); 392 EFI_FILE_MODE_READ, (u64)0);
384 if (status != EFI_SUCCESS) { 393 if (status != EFI_SUCCESS) {
385 efi_printk(sys_table_arg, "Failed to open initrd file: "); 394 efi_printk(sys_table_arg, "Failed to open file: ");
386 efi_char16_printk(sys_table_arg, filename_16); 395 efi_char16_printk(sys_table_arg, filename_16);
387 efi_printk(sys_table_arg, "\n"); 396 efi_printk(sys_table_arg, "\n");
388 goto close_handles; 397 goto close_handles;
@@ -394,7 +403,7 @@ static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg,
394 status = efi_call_phys4(h->get_info, h, &info_guid, 403 status = efi_call_phys4(h->get_info, h, &info_guid,
395 &info_sz, NULL); 404 &info_sz, NULL);
396 if (status != EFI_BUFFER_TOO_SMALL) { 405 if (status != EFI_BUFFER_TOO_SMALL) {
397 efi_printk(sys_table_arg, "Failed to get initrd info size\n"); 406 efi_printk(sys_table_arg, "Failed to get file info size\n");
398 goto close_handles; 407 goto close_handles;
399 } 408 }
400 409
@@ -402,7 +411,7 @@ grow:
402 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, 411 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
403 EFI_LOADER_DATA, info_sz, &info); 412 EFI_LOADER_DATA, info_sz, &info);
404 if (status != EFI_SUCCESS) { 413 if (status != EFI_SUCCESS) {
405 efi_printk(sys_table_arg, "Failed to alloc mem for initrd info\n"); 414 efi_printk(sys_table_arg, "Failed to alloc mem for file info\n");
406 goto close_handles; 415 goto close_handles;
407 } 416 }
408 417
@@ -418,7 +427,7 @@ grow:
418 efi_call_phys1(sys_table_arg->boottime->free_pool, info); 427 efi_call_phys1(sys_table_arg->boottime->free_pool, info);
419 428
420 if (status != EFI_SUCCESS) { 429 if (status != EFI_SUCCESS) {
421 efi_printk(sys_table_arg, "Failed to get initrd info\n"); 430 efi_printk(sys_table_arg, "Failed to get file info\n");
422 goto close_handles; 431 goto close_handles;
423 } 432 }
424 433
@@ -435,14 +444,14 @@ grow:
435 * all the initrd's. 444 * all the initrd's.
436 */ 445 */
437 status = efi_high_alloc(sys_table_arg, initrd_total, 0x1000, 446 status = efi_high_alloc(sys_table_arg, initrd_total, 0x1000,
438 &initrd_addr, hdr->initrd_addr_max); 447 &initrd_addr, max_addr);
439 if (status != EFI_SUCCESS) { 448 if (status != EFI_SUCCESS) {
440 efi_printk(sys_table_arg, "Failed to alloc highmem for initrds\n"); 449 efi_printk(sys_table_arg, "Failed to alloc highmem for initrds\n");
441 goto close_handles; 450 goto close_handles;
442 } 451 }
443 452
444 /* We've run out of free low memory. */ 453 /* We've run out of free low memory. */
445 if (initrd_addr > hdr->initrd_addr_max) { 454 if (initrd_addr > max_addr) {
446 efi_printk(sys_table_arg, "We've run out of free low memory\n"); 455 efi_printk(sys_table_arg, "We've run out of free low memory\n");
447 status = EFI_INVALID_PARAMETER; 456 status = EFI_INVALID_PARAMETER;
448 goto free_initrd_total; 457 goto free_initrd_total;
@@ -463,7 +472,7 @@ grow:
463 initrds[j].handle, 472 initrds[j].handle,
464 &chunksize, addr); 473 &chunksize, addr);
465 if (status != EFI_SUCCESS) { 474 if (status != EFI_SUCCESS) {
466 efi_printk(sys_table_arg, "Failed to read initrd\n"); 475 efi_printk(sys_table_arg, "Failed to read file\n");
467 goto free_initrd_total; 476 goto free_initrd_total;
468 } 477 }
469 addr += chunksize; 478 addr += chunksize;
@@ -477,8 +486,8 @@ grow:
477 486
478 efi_call_phys1(sys_table_arg->boottime->free_pool, initrds); 487 efi_call_phys1(sys_table_arg->boottime->free_pool, initrds);
479 488
480 hdr->ramdisk_image = initrd_addr; 489 *load_addr = initrd_addr;
481 hdr->ramdisk_size = initrd_total; 490 *load_size = initrd_total;
482 491
483 return status; 492 return status;
484 493
@@ -491,8 +500,8 @@ close_handles:
491free_initrds: 500free_initrds:
492 efi_call_phys1(sys_table_arg->boottime->free_pool, initrds); 501 efi_call_phys1(sys_table_arg->boottime->free_pool, initrds);
493fail: 502fail:
494 hdr->ramdisk_image = 0; 503 *load_addr = 0;
495 hdr->ramdisk_size = 0; 504 *load_size = 0;
496 505
497 return status; 506 return status;
498} 507}