Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Sjoerd Simons | c8f3482 | 2015-04-13 22:54:20 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Sjoerd Simons | a5ddcbe | 2015-04-13 22:54:21 +0200 | [diff] [blame] | 4 | * Copyright (c) 2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk> |
Sjoerd Simons | c8f3482 | 2015-04-13 22:54:20 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 7 | #include <bootm.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 8 | #include <bootstage.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 9 | #include <image.h> |
Sjoerd Simons | c8f3482 | 2015-04-13 22:54:20 +0200 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | |
Sjoerd Simons | a5ddcbe | 2015-04-13 22:54:21 +0200 | [diff] [blame] | 12 | #define LINUX_ARM_ZIMAGE_MAGIC 0x016f2818 |
| 13 | |
| 14 | struct arm_z_header { |
| 15 | uint32_t code[9]; |
| 16 | uint32_t zi_magic; |
| 17 | uint32_t zi_start; |
| 18 | uint32_t zi_end; |
| 19 | } __attribute__ ((__packed__)); |
| 20 | |
| 21 | int bootz_setup(ulong image, ulong *start, ulong *end) |
| 22 | { |
| 23 | uint8_t *zimage = map_sysmem(image, 0); |
| 24 | struct arm_z_header *arm_hdr = (struct arm_z_header *)zimage; |
| 25 | int ret = 0; |
| 26 | |
| 27 | if (memcmp(zimage + 0x202, "HdrS", 4) == 0) { |
| 28 | uint8_t setup_sects = *(zimage + 0x1f1); |
| 29 | uint32_t syssize = |
| 30 | le32_to_cpu(*(uint32_t *)(zimage + 0x1f4)); |
| 31 | |
| 32 | *start = 0; |
| 33 | *end = (setup_sects + 1) * 512 + syssize * 16; |
| 34 | |
| 35 | printf("setting up X86 zImage [ %ld - %ld ]\n", |
| 36 | *start, *end); |
| 37 | } else if (le32_to_cpu(arm_hdr->zi_magic) == LINUX_ARM_ZIMAGE_MAGIC) { |
| 38 | *start = le32_to_cpu(arm_hdr->zi_start); |
| 39 | *end = le32_to_cpu(arm_hdr->zi_end); |
| 40 | |
| 41 | printf("setting up ARM zImage [ %ld - %ld ]\n", |
| 42 | *start, *end); |
| 43 | } else { |
| 44 | printf("Unrecognized zImage\n"); |
| 45 | ret = 1; |
| 46 | } |
| 47 | |
| 48 | unmap_sysmem((void *)image); |
| 49 | |
| 50 | return ret; |
| 51 | } |
| 52 | |
Simon Glass | 7514fd7 | 2022-10-11 09:47:14 -0600 | [diff] [blame] | 53 | /* Subcommand: PREP */ |
| 54 | static int boot_prep_linux(struct bootm_headers *images) |
| 55 | { |
| 56 | int ret; |
| 57 | |
Simon Glass | ae7ed57 | 2023-02-05 15:40:13 -0700 | [diff] [blame] | 58 | if (IS_ENABLED(CONFIG_LMB)) { |
Simon Glass | 7514fd7 | 2022-10-11 09:47:14 -0600 | [diff] [blame] | 59 | ret = image_setup_linux(images); |
| 60 | if (ret) |
| 61 | return ret; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 67 | int do_bootm_linux(int flag, struct bootm_info *bmi) |
Sjoerd Simons | c8f3482 | 2015-04-13 22:54:20 +0200 | [diff] [blame] | 68 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 69 | struct bootm_headers *images = bmi->images; |
| 70 | |
Simon Glass | 7514fd7 | 2022-10-11 09:47:14 -0600 | [diff] [blame] | 71 | if (flag & BOOTM_STATE_OS_PREP) |
| 72 | return boot_prep_linux(images); |
| 73 | |
Sjoerd Simons | c8f3482 | 2015-04-13 22:54:20 +0200 | [diff] [blame] | 74 | if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { |
| 75 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 76 | printf("## Transferring control to Linux (at address %08lx)...\n", |
| 77 | images->ep); |
Simon Glass | 43cdb79 | 2016-07-03 09:40:35 -0600 | [diff] [blame] | 78 | printf("sandbox: continuing, as we cannot run Linux\n"); |
Sjoerd Simons | c8f3482 | 2015-04-13 22:54:20 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
Simon Glass | 936d05d | 2023-10-01 19:15:24 -0600 | [diff] [blame] | 83 | |
| 84 | /* used for testing 'booti' command */ |
| 85 | int booti_setup(ulong image, ulong *relocated_addr, ulong *size, |
| 86 | bool force_reloc) |
| 87 | { |
| 88 | return 0; |
| 89 | } |