xref: /openbmc/u-boot/arch/x86/lib/bootm.c (revision 3765b3e7)
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  * SPDX-License-Identifier:	GPL-2.0+
9  */
10 
11 #include <common.h>
12 #include <command.h>
13 #include <image.h>
14 #include <u-boot/zlib.h>
15 #include <asm/bootparam.h>
16 #include <asm/byteorder.h>
17 #include <asm/zimage.h>
18 
19 #define COMMAND_LINE_OFFSET 0x9000
20 
21 /*cmd_boot.c*/
22 int do_bootm_linux(int flag, int argc, char * const argv[],
23 		bootm_headers_t *images)
24 {
25 	struct boot_params *base_ptr = NULL;
26 	ulong os_data, os_len;
27 	image_header_t *hdr;
28 	void *load_address;
29 
30 #if defined(CONFIG_FIT)
31 	const void	*data;
32 	size_t		len;
33 #endif
34 
35 	if (flag & BOOTM_STATE_OS_PREP)
36 		return 0;
37 	if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
38 		return 1;
39 
40 	if (images->legacy_hdr_valid) {
41 		hdr = images->legacy_hdr_os;
42 		if (image_check_type(hdr, IH_TYPE_MULTI)) {
43 			/* if multi-part image, we need to get first subimage */
44 			image_multi_getimg(hdr, 0, &os_data, &os_len);
45 		} else {
46 			/* otherwise get image data */
47 			os_data = image_get_data(hdr);
48 			os_len = image_get_data_size(hdr);
49 		}
50 #if defined(CONFIG_FIT)
51 	} else if (images->fit_uname_os) {
52 		int ret;
53 
54 		ret = fit_image_get_data(images->fit_hdr_os,
55 					images->fit_noffset_os, &data, &len);
56 		if (ret) {
57 			puts("Can't get image data/size!\n");
58 			goto error;
59 		}
60 		os_data = (ulong)data;
61 		os_len = (ulong)len;
62 #endif
63 	} else {
64 		puts("Could not find kernel image!\n");
65 		goto error;
66 	}
67 
68 #ifdef CONFIG_CMD_ZBOOT
69 	base_ptr = load_zimage((void *)os_data, os_len, &load_address);
70 #endif
71 
72 	if (NULL == base_ptr) {
73 		printf("## Kernel loading failed ...\n");
74 		goto error;
75 	}
76 
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;
82 	}
83 
84 	boot_zimage(base_ptr, load_address);
85 	/* does not return */
86 
87 error:
88 	return 1;
89 }
90