xref: /openbmc/u-boot/arch/x86/lib/bootm.c (revision b899fa39)
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  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26 
27 #include <common.h>
28 #include <command.h>
29 #include <image.h>
30 #include <u-boot/zlib.h>
31 #include <asm/bootparam.h>
32 #include <asm/byteorder.h>
33 #include <asm/zimage.h>
34 
35 #define COMMAND_LINE_OFFSET 0x9000
36 
37 /*cmd_boot.c*/
38 int do_bootm_linux(int flag, int argc, char * const argv[],
39 		bootm_headers_t *images)
40 {
41 	struct boot_params *base_ptr = NULL;
42 	ulong os_data, os_len;
43 	image_header_t *hdr;
44 	void *load_address;
45 
46 #if defined(CONFIG_FIT)
47 	const void	*data;
48 	size_t		len;
49 #endif
50 
51 	if (flag & BOOTM_STATE_OS_PREP)
52 		return 0;
53 	if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
54 		return 1;
55 
56 	if (images->legacy_hdr_valid) {
57 		hdr = images->legacy_hdr_os;
58 		if (image_check_type(hdr, IH_TYPE_MULTI)) {
59 			/* if multi-part image, we need to get first subimage */
60 			image_multi_getimg(hdr, 0, &os_data, &os_len);
61 		} else {
62 			/* otherwise get image data */
63 			os_data = image_get_data(hdr);
64 			os_len = image_get_data_size(hdr);
65 		}
66 #if defined(CONFIG_FIT)
67 	} else if (images->fit_uname_os) {
68 		int ret;
69 
70 		ret = fit_image_get_data(images->fit_hdr_os,
71 					images->fit_noffset_os, &data, &len);
72 		if (ret) {
73 			puts("Can't get image data/size!\n");
74 			goto error;
75 		}
76 		os_data = (ulong)data;
77 		os_len = (ulong)len;
78 #endif
79 	} else {
80 		puts("Could not find kernel image!\n");
81 		goto error;
82 	}
83 
84 #ifdef CONFIG_CMD_ZBOOT
85 	base_ptr = load_zimage((void *)os_data, os_len, &load_address);
86 #endif
87 
88 	if (NULL == base_ptr) {
89 		printf("## Kernel loading failed ...\n");
90 		goto error;
91 	}
92 
93 	if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
94 			0, images->rd_start,
95 			images->rd_end - images->rd_start)) {
96 		printf("## Setting up boot parameters failed ...\n");
97 		goto error;
98 	}
99 
100 	boot_zimage(base_ptr, load_address);
101 	/* does not return */
102 
103 error:
104 	return 1;
105 }
106