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