xref: /openbmc/u-boot/arch/sandbox/lib/bootm.c (revision e8f80a5a)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2011 The Chromium OS Authors.
4  * Copyright (c) 2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk>
5  */
6 
7 #include <common.h>
8 #include <asm/io.h>
9 
10 #define	LINUX_ARM_ZIMAGE_MAGIC	0x016f2818
11 
12 struct arm_z_header {
13 	uint32_t	code[9];
14 	uint32_t	zi_magic;
15 	uint32_t	zi_start;
16 	uint32_t	zi_end;
17 } __attribute__ ((__packed__));
18 
bootz_setup(ulong image,ulong * start,ulong * end)19 int bootz_setup(ulong image, ulong *start, ulong *end)
20 {
21 	uint8_t *zimage = map_sysmem(image, 0);
22 	struct arm_z_header *arm_hdr = (struct arm_z_header *)zimage;
23 	int ret = 0;
24 
25 	if (memcmp(zimage + 0x202, "HdrS", 4) == 0) {
26 		uint8_t setup_sects = *(zimage + 0x1f1);
27 		uint32_t syssize =
28 			le32_to_cpu(*(uint32_t *)(zimage + 0x1f4));
29 
30 		*start = 0;
31 		*end = (setup_sects + 1) * 512 + syssize * 16;
32 
33 		printf("setting up X86 zImage [ %ld - %ld ]\n",
34 		       *start, *end);
35 	} else if (le32_to_cpu(arm_hdr->zi_magic) == LINUX_ARM_ZIMAGE_MAGIC) {
36 		*start = le32_to_cpu(arm_hdr->zi_start);
37 		*end = le32_to_cpu(arm_hdr->zi_end);
38 
39 		printf("setting up ARM zImage [ %ld - %ld ]\n",
40 		       *start, *end);
41 	} else {
42 		printf("Unrecognized zImage\n");
43 		ret = 1;
44 	}
45 
46 	unmap_sysmem((void *)image);
47 
48 	return ret;
49 }
50 
do_bootm_linux(int flag,int argc,char * argv[],bootm_headers_t * images)51 int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
52 {
53 	if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
54 		bootstage_mark(BOOTSTAGE_ID_RUN_OS);
55 		printf("## Transferring control to Linux (at address %08lx)...\n",
56 		       images->ep);
57 		printf("sandbox: continuing, as we cannot run Linux\n");
58 	}
59 
60 	return 0;
61 }
62