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 <fdt_support.h> 14 #include <image.h> 15 #include <u-boot/zlib.h> 16 #include <asm/bootparam.h> 17 #include <asm/byteorder.h> 18 #include <asm/zimage.h> 19 #ifdef CONFIG_SYS_COREBOOT 20 #include <asm/arch/timestamp.h> 21 #endif 22 23 #define COMMAND_LINE_OFFSET 0x9000 24 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) 30 { 31 } 32 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(); 43 #endif 44 board_final_cleanup(); 45 } 46 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]; 54 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 83 if (images->legacy_hdr_valid) { 84 hdr = images->legacy_hdr_os; 85 if (image_check_type(hdr, IH_TYPE_MULTI)) { 86 ulong os_data, os_len; 87 88 /* if multi-part image, we need to get first subimage */ 89 image_multi_getimg(hdr, 0, &os_data, &os_len); 90 data = (void *)os_data; 91 len = os_len; 92 } else { 93 /* otherwise get image data */ 94 data = (void *)image_get_data(hdr); 95 len = image_get_data_size(hdr); 96 } 97 is_zimage = 1; 98 #if defined(CONFIG_FIT) 99 } else if (images->fit_uname_os && is_zimage) { 100 ret = fit_image_get_data(images->fit_hdr_os, 101 images->fit_noffset_os, 102 (const void **)&data, &len); 103 if (ret) { 104 puts("Can't get image data/size!\n"); 105 goto error; 106 } 107 is_zimage = 1; 108 #endif 109 } 110 111 if (is_zimage) { 112 void *load_address; 113 char *base_ptr; 114 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"); 123 goto error; 124 } 125 126 printf("Setup at %#08lx\n", images->ep); 127 ret = setup_zimage((void *)images->ep, cmd_line_dest, 128 0, images->rd_start, 129 images->rd_end - images->rd_start); 130 131 if (ret) { 132 printf("## Setting up boot parameters failed ...\n"); 133 return 1; 134 } 135 136 return 0; 137 138 error: 139 return 1; 140 } 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 } 171