wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 4 | * Marius Groeger <mgroeger@sysgo.de> |
| 5 | * |
| 6 | * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <command.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 13 | #include <image.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6bb9449 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 14 | #include <u-boot/zlib.h> |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 15 | #include <asm/bootparam.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 16 | #include <asm/byteorder.h> |
| 17 | #include <asm/zimage.h> |
| 18 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 19 | #define COMMAND_LINE_OFFSET 0x9000 |
| 20 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 21 | /*cmd_boot.c*/ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 22 | int do_bootm_linux(int flag, int argc, char * const argv[], |
| 23 | bootm_headers_t *images) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 24 | { |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 25 | struct boot_params *base_ptr = NULL; |
| 26 | ulong os_data, os_len; |
| 27 | image_header_t *hdr; |
| 28 | void *load_address; |
Graeme Russ | 2fe2a97 | 2008-09-07 07:08:42 +1000 | [diff] [blame] | 29 | |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 30 | #if defined(CONFIG_FIT) |
| 31 | const void *data; |
| 32 | size_t len; |
| 33 | #endif |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 34 | |
Simon Glass | f059d0a | 2013-07-10 23:08:09 -0700 | [diff] [blame] | 35 | if (flag & BOOTM_STATE_OS_PREP) |
| 36 | return 0; |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 37 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 38 | return 1; |
| 39 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 40 | if (images->legacy_hdr_valid) { |
| 41 | hdr = images->legacy_hdr_os; |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 42 | if (image_check_type(hdr, IH_TYPE_MULTI)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 43 | /* if multi-part image, we need to get first subimage */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 44 | image_multi_getimg(hdr, 0, &os_data, &os_len); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 45 | } else { |
| 46 | /* otherwise get image data */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 47 | os_data = image_get_data(hdr); |
| 48 | os_len = image_get_data_size(hdr); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 49 | } |
| 50 | #if defined(CONFIG_FIT) |
| 51 | } else if (images->fit_uname_os) { |
Simon Glass | 42fc60a | 2013-06-11 11:14:34 -0700 | [diff] [blame] | 52 | int ret; |
| 53 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 54 | ret = fit_image_get_data(images->fit_hdr_os, |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 55 | images->fit_noffset_os, &data, &len); |
| 56 | if (ret) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 57 | puts("Can't get image data/size!\n"); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 58 | goto error; |
| 59 | } |
| 60 | os_data = (ulong)data; |
| 61 | os_len = (ulong)len; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 62 | #endif |
Marian Balakowicz | b4a12a9 | 2008-01-08 18:12:17 +0100 | [diff] [blame] | 63 | } else { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 64 | puts("Could not find kernel image!\n"); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 65 | goto error; |
Wolfgang Denk | 44cacdc | 2006-07-21 11:30:18 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 68 | #ifdef CONFIG_CMD_ZBOOT |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 69 | base_ptr = load_zimage((void *)os_data, os_len, &load_address); |
Graeme Russ | 19fc0d5 | 2011-11-08 02:33:20 +0000 | [diff] [blame] | 70 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 71 | |
| 72 | if (NULL == base_ptr) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 73 | printf("## Kernel loading failed ...\n"); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 74 | goto error; |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 75 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 76 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 77 | if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, |
| 78 | 0, images->rd_start, |
| 79 | images->rd_end - images->rd_start)) { |
| 80 | printf("## Setting up boot parameters failed ...\n"); |
| 81 | goto error; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 82 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 83 | |
Gabe Black | c67a948 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 84 | boot_zimage(base_ptr, load_address); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 85 | /* does not return */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 86 | |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 87 | error: |
Kumar Gala | 48626aa | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 88 | return 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 89 | } |