blob: ff158dd6a9d940c823bfc59059ce6151bc60d675 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
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 Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk591dda52002-11-18 00:14:45 +00009 */
10
11#include <common.h>
12#include <command.h>
wdenk591dda52002-11-18 00:14:45 +000013#include <image.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020014#include <u-boot/zlib.h>
Gabe Black540c2622011-12-05 12:09:26 +000015#include <asm/bootparam.h>
wdenk591dda52002-11-18 00:14:45 +000016#include <asm/byteorder.h>
17#include <asm/zimage.h>
18
Gabe Black540c2622011-12-05 12:09:26 +000019#define COMMAND_LINE_OFFSET 0x9000
20
wdenk57b2d802003-06-27 21:31:46 +000021/*cmd_boot.c*/
Graeme Russ883c6032011-11-08 02:33:15 +000022int do_bootm_linux(int flag, int argc, char * const argv[],
23 bootm_headers_t *images)
wdenk591dda52002-11-18 00:14:45 +000024{
Gabe Black540c2622011-12-05 12:09:26 +000025 struct boot_params *base_ptr = NULL;
26 ulong os_data, os_len;
27 image_header_t *hdr;
28 void *load_address;
Graeme Russ2fe2a972008-09-07 07:08:42 +100029
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010030#if defined(CONFIG_FIT)
31 const void *data;
32 size_t len;
33#endif
wdenk57b2d802003-06-27 21:31:46 +000034
Simon Glassf059d0a2013-07-10 23:08:09 -070035 if (flag & BOOTM_STATE_OS_PREP)
36 return 0;
Kumar Gala18178bc2008-10-21 17:25:45 -050037 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
38 return 1;
39
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010040 if (images->legacy_hdr_valid) {
41 hdr = images->legacy_hdr_os;
Graeme Russ883c6032011-11-08 02:33:15 +000042 if (image_check_type(hdr, IH_TYPE_MULTI)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010043 /* if multi-part image, we need to get first subimage */
Graeme Russ883c6032011-11-08 02:33:15 +000044 image_multi_getimg(hdr, 0, &os_data, &os_len);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010045 } else {
46 /* otherwise get image data */
Graeme Russ883c6032011-11-08 02:33:15 +000047 os_data = image_get_data(hdr);
48 os_len = image_get_data_size(hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010049 }
50#if defined(CONFIG_FIT)
51 } else if (images->fit_uname_os) {
Simon Glass42fc60a2013-06-11 11:14:34 -070052 int ret;
53
Graeme Russ883c6032011-11-08 02:33:15 +000054 ret = fit_image_get_data(images->fit_hdr_os,
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010055 images->fit_noffset_os, &data, &len);
56 if (ret) {
Graeme Russ883c6032011-11-08 02:33:15 +000057 puts("Can't get image data/size!\n");
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010058 goto error;
59 }
60 os_data = (ulong)data;
61 os_len = (ulong)len;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +010062#endif
Marian Balakowiczb4a12a92008-01-08 18:12:17 +010063 } else {
Graeme Russ883c6032011-11-08 02:33:15 +000064 puts("Could not find kernel image!\n");
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010065 goto error;
Wolfgang Denk44cacdc2006-07-21 11:30:18 +020066 }
67
Graeme Russ19fc0d52011-11-08 02:33:20 +000068#ifdef CONFIG_CMD_ZBOOT
Gabe Black540c2622011-12-05 12:09:26 +000069 base_ptr = load_zimage((void *)os_data, os_len, &load_address);
Graeme Russ19fc0d52011-11-08 02:33:20 +000070#endif
wdenk591dda52002-11-18 00:14:45 +000071
72 if (NULL == base_ptr) {
Graeme Russ883c6032011-11-08 02:33:15 +000073 printf("## Kernel loading failed ...\n");
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010074 goto error;
Gabe Black540c2622011-12-05 12:09:26 +000075 }
wdenk57b2d802003-06-27 21:31:46 +000076
Gabe Black540c2622011-12-05 12:09:26 +000077 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;
wdenk591dda52002-11-18 00:14:45 +000082 }
wdenk57b2d802003-06-27 21:31:46 +000083
Gabe Blackc67a9482011-12-05 12:09:24 +000084 boot_zimage(base_ptr, load_address);
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010085 /* does not return */
wdenk591dda52002-11-18 00:14:45 +000086
Marian Balakowiczdf8ff332008-03-12 10:33:00 +010087error:
Kumar Gala48626aa2008-08-15 08:24:45 -050088 return 1;
wdenk57b2d802003-06-27 21:31:46 +000089}