wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <command.h> |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 13 | #include <fdt_support.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 14 | #include <image.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6bb9449 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 15 | #include <u-boot/zlib.h> |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 16 | #include <asm/bootparam.h> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 17 | #include <asm/byteorder.h> |
| 18 | #include <asm/zimage.h> |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 19 | #ifdef CONFIG_SYS_COREBOOT |
| 20 | #include <asm/arch/timestamp.h> |
| 21 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 22 | |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 23 | #define COMMAND_LINE_OFFSET 0x9000 |
| 24 | |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 25 | /* |
| 26 | * Implement a weak default function for boards that optionally |
| 27 | * need to clean up the system before jumping to the kernel. |
| 28 | */ |
| 29 | __weak void board_final_cleanup(void) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 30 | { |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 31 | } |
Graeme Russ | 2fe2a97 | 2008-09-07 07:08:42 +1000 | [diff] [blame] | 32 | |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 33 | void bootm_announce_and_cleanup(void) |
| 34 | { |
| 35 | printf("\nStarting kernel ...\n\n"); |
| 36 | |
| 37 | #ifdef CONFIG_SYS_COREBOOT |
| 38 | timestamp_add_now(TS_U_BOOT_START_KERNEL); |
| 39 | #endif |
| 40 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); |
| 41 | #ifdef CONFIG_BOOTSTAGE_REPORT |
| 42 | bootstage_report(); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 43 | #endif |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 44 | board_final_cleanup(); |
| 45 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 46 | |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 47 | #if defined(CONFIG_OF_LIBFDT) && !defined(CONFIG_OF_NO_KERNEL) |
| 48 | int arch_fixup_memory_node(void *blob) |
| 49 | { |
| 50 | bd_t *bd = gd->bd; |
| 51 | int bank; |
| 52 | u64 start[CONFIG_NR_DRAM_BANKS]; |
| 53 | u64 size[CONFIG_NR_DRAM_BANKS]; |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 54 | |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 55 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
| 56 | start[bank] = bd->bi_dram[bank].start; |
| 57 | size[bank] = bd->bi_dram[bank].size; |
| 58 | } |
| 59 | |
| 60 | return fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS); |
| 61 | } |
| 62 | #endif |
| 63 | |
| 64 | /* Subcommand: PREP */ |
| 65 | static int boot_prep_linux(bootm_headers_t *images) |
| 66 | { |
| 67 | char *cmd_line_dest = NULL; |
| 68 | image_header_t *hdr; |
| 69 | int is_zimage = 0; |
| 70 | void *data = NULL; |
| 71 | size_t len; |
| 72 | int ret; |
| 73 | |
| 74 | #ifdef CONFIG_OF_LIBFDT |
| 75 | if (images->ft_len) { |
| 76 | debug("using: FDT\n"); |
| 77 | if (image_setup_linux(images)) { |
| 78 | puts("FDT creation failed! hanging..."); |
| 79 | hang(); |
| 80 | } |
| 81 | } |
| 82 | #endif |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 83 | if (images->legacy_hdr_valid) { |
| 84 | hdr = images->legacy_hdr_os; |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 85 | if (image_check_type(hdr, IH_TYPE_MULTI)) { |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 86 | ulong os_data, os_len; |
| 87 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 88 | /* if multi-part image, we need to get first subimage */ |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 89 | image_multi_getimg(hdr, 0, &os_data, &os_len); |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 90 | data = (void *)os_data; |
| 91 | len = os_len; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 92 | } else { |
| 93 | /* otherwise get image data */ |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 94 | data = (void *)image_get_data(hdr); |
| 95 | len = image_get_data_size(hdr); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 96 | } |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 97 | is_zimage = 1; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 98 | #if defined(CONFIG_FIT) |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 99 | } else if (images->fit_uname_os && is_zimage) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 100 | ret = fit_image_get_data(images->fit_hdr_os, |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 101 | images->fit_noffset_os, |
| 102 | (const void **)&data, &len); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 103 | if (ret) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 104 | puts("Can't get image data/size!\n"); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 105 | goto error; |
| 106 | } |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 107 | is_zimage = 1; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 108 | #endif |
Wolfgang Denk | 44cacdc | 2006-07-21 11:30:18 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 111 | if (is_zimage) { |
| 112 | void *load_address; |
| 113 | char *base_ptr; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 114 | |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 115 | base_ptr = (char *)load_zimage(data, len, &load_address); |
| 116 | images->os.load = (ulong)load_address; |
| 117 | cmd_line_dest = base_ptr + COMMAND_LINE_OFFSET; |
| 118 | images->ep = (ulong)base_ptr; |
| 119 | } else if (images->ep) { |
| 120 | cmd_line_dest = (void *)images->ep + COMMAND_LINE_OFFSET; |
| 121 | } else { |
| 122 | printf("## Kernel loading failed (no setup) ...\n"); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 123 | goto error; |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 124 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 125 | |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 126 | printf("Setup at %#08lx\n", images->ep); |
| 127 | ret = setup_zimage((void *)images->ep, cmd_line_dest, |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 128 | 0, images->rd_start, |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 129 | images->rd_end - images->rd_start); |
| 130 | |
| 131 | if (ret) { |
Gabe Black | 540c262 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 132 | printf("## Setting up boot parameters failed ...\n"); |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 133 | return 1; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 134 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 136 | return 0; |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 137 | |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 138 | error: |
Kumar Gala | 48626aa | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 139 | return 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 140 | } |
Simon Glass | aa83f2b | 2014-10-19 21:11:20 -0600 | [diff] [blame] | 141 | |
| 142 | /* Subcommand: GO */ |
| 143 | static int boot_jump_linux(bootm_headers_t *images) |
| 144 | { |
| 145 | debug("## Transferring control to Linux (at address %08lx, kernel %08lx) ...\n", |
| 146 | images->ep, images->os.load); |
| 147 | |
| 148 | boot_zimage((struct boot_params *)images->ep, (void *)images->os.load); |
| 149 | /* does not return */ |
| 150 | |
| 151 | return 1; |
| 152 | } |
| 153 | |
| 154 | int do_bootm_linux(int flag, int argc, char * const argv[], |
| 155 | bootm_headers_t *images) |
| 156 | { |
| 157 | /* No need for those on x86 */ |
| 158 | if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) |
| 159 | return -1; |
| 160 | |
| 161 | if (flag & BOOTM_STATE_OS_PREP) |
| 162 | return boot_prep_linux(images); |
| 163 | |
| 164 | if (flag & BOOTM_STATE_OS_GO) { |
| 165 | boot_jump_linux(images); |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | return boot_jump_linux(images); |
| 170 | } |