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