Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2008 Semihalf |
| 4 | * |
| 5 | * (C) Copyright 2000-2006 |
| 6 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 9 | #include <config.h> |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 10 | #include <bootm.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 11 | #include <bootstage.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 12 | #include <cpu_func.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 13 | #include <env.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 14 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 16 | #include <watchdog.h> |
| 17 | #include <command.h> |
| 18 | #include <image.h> |
| 19 | #include <malloc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6bb9449 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 21 | #include <u-boot/zlib.h> |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 22 | #include <bzlib.h> |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 23 | #include <asm/byteorder.h> |
Kumar Gala | 365024c | 2011-01-31 15:51:20 -0600 | [diff] [blame] | 24 | #include <asm/mp.h> |
Christophe Leroy | 4a4750b | 2017-07-13 15:10:08 +0200 | [diff] [blame] | 25 | #include <bootm.h> |
| 26 | #include <vxworks.h> |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 27 | |
| 28 | #if defined(CONFIG_OF_LIBFDT) |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 29 | #include <linux/libfdt.h> |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 30 | #include <fdt_support.h> |
Wolfgang Denk | 1e0f07e | 2009-07-26 23:28:02 +0200 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | #ifdef CONFIG_SYS_INIT_RAM_LOCK |
| 34 | #include <asm/cache.h> |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 35 | #endif |
| 36 | |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 37 | DECLARE_GLOBAL_DATA_PTR; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 38 | |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 39 | extern void ft_fixup_num_cores(void *blob); |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 40 | static void set_clocks_in_mhz (struct bd_info *kbd); |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 41 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 42 | static void boot_jump_linux(struct bootm_headers *images) |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 43 | { |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 44 | void (*kernel)(struct bd_info *, ulong r4, ulong r5, ulong r6, |
| 45 | ulong r7, ulong r8, ulong r9); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 46 | #ifdef CONFIG_OF_LIBFDT |
| 47 | char *of_flat_tree = images->ft_addr; |
| 48 | #endif |
| 49 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 50 | kernel = (void (*)(struct bd_info *, ulong, ulong, ulong, |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 51 | ulong, ulong, ulong))images->ep; |
Simon Glass | 8f055af | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 52 | debug("## Transferring control to Linux (at address %08lx) ...\n", |
| 53 | (ulong)kernel); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 54 | |
Simon Glass | 0169e6b | 2012-02-13 13:51:18 +0000 | [diff] [blame] | 55 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 56 | |
Mela Custodio | be11d89 | 2014-02-20 00:16:57 +0900 | [diff] [blame] | 57 | #ifdef CONFIG_BOOTSTAGE_FDT |
| 58 | bootstage_fdt_add_report(); |
| 59 | #endif |
| 60 | #ifdef CONFIG_BOOTSTAGE_REPORT |
| 61 | bootstage_report(); |
| 62 | #endif |
| 63 | |
Wolfgang Denk | 1e0f07e | 2009-07-26 23:28:02 +0200 | [diff] [blame] | 64 | #if defined(CONFIG_SYS_INIT_RAM_LOCK) && !defined(CONFIG_E500) |
| 65 | unlock_ram_in_cache(); |
| 66 | #endif |
| 67 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 68 | #if defined(CONFIG_OF_LIBFDT) |
| 69 | if (of_flat_tree) { /* device tree; boot new style */ |
| 70 | /* |
| 71 | * Linux Kernel Parameters (passing device tree): |
| 72 | * r3: pointer to the fdt |
| 73 | * r4: 0 |
| 74 | * r5: 0 |
| 75 | * r6: epapr magic |
| 76 | * r7: size of IMA in bytes |
| 77 | * r8: 0 |
| 78 | * r9: 0 |
| 79 | */ |
Simon Glass | 8f055af | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 80 | debug(" Booting using OF flat tree...\n"); |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 81 | schedule(); |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 82 | (*kernel) ((struct bd_info *)of_flat_tree, 0, 0, EPAPR_MAGIC, |
Simon Glass | da1a134 | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 83 | env_get_bootm_mapsize(), 0, 0); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 84 | /* does not return */ |
| 85 | } else |
| 86 | #endif |
| 87 | { |
| 88 | /* |
| 89 | * Linux Kernel Parameters (passing board info data): |
| 90 | * r3: ptr to board info data |
| 91 | * r4: initrd_start or 0 if no initrd |
| 92 | * r5: initrd_end - unused if r4 is 0 |
| 93 | * r6: Start of command line string |
| 94 | * r7: End of command line string |
| 95 | * r8: 0 |
| 96 | * r9: 0 |
| 97 | */ |
| 98 | ulong cmd_start = images->cmdline_start; |
| 99 | ulong cmd_end = images->cmdline_end; |
| 100 | ulong initrd_start = images->initrd_start; |
| 101 | ulong initrd_end = images->initrd_end; |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 102 | struct bd_info *kbd = images->kbd; |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 103 | |
Simon Glass | 8f055af | 2020-05-10 11:40:04 -0600 | [diff] [blame] | 104 | debug(" Booting using board info...\n"); |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 105 | schedule(); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 106 | (*kernel) (kbd, initrd_start, initrd_end, |
| 107 | cmd_start, cmd_end, 0, 0); |
| 108 | /* does not return */ |
| 109 | } |
Bin Meng | 75a6a37 | 2022-10-26 12:40:07 +0800 | [diff] [blame] | 110 | return; |
Kumar Gala | b02d722 | 2008-10-16 21:52:08 -0500 | [diff] [blame] | 111 | } |
| 112 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 113 | static void boot_prep_linux(struct bootm_headers *images) |
Kumar Gala | 180c581 | 2011-12-07 04:42:58 +0000 | [diff] [blame] | 114 | { |
| 115 | #ifdef CONFIG_MP |
| 116 | /* |
| 117 | * if we are MP make sure to flush the device tree so any changes are |
| 118 | * made visibile to all other cores. In AMP boot scenarios the cores |
| 119 | * might not be HW cache coherent with each other. |
| 120 | */ |
| 121 | flush_cache((unsigned long)images->ft_addr, images->ft_len); |
| 122 | #endif |
| 123 | } |
| 124 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 125 | static int boot_cmdline_linux(struct bootm_headers *images) |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 126 | { |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 127 | ulong of_size = images->ft_len; |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 128 | ulong *cmd_start = &images->cmdline_start; |
| 129 | ulong *cmd_end = &images->cmdline_end; |
Kumar Gala | b02d722 | 2008-10-16 21:52:08 -0500 | [diff] [blame] | 130 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 131 | int ret = 0; |
Kumar Gala | b02d722 | 2008-10-16 21:52:08 -0500 | [diff] [blame] | 132 | |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 133 | if (!of_size) { |
| 134 | /* allocate space and init command line */ |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 135 | ret = boot_get_cmdline(cmd_start, cmd_end); |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 136 | if (ret) { |
| 137 | puts("ERROR with allocation of cmdline\n"); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 138 | return ret; |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 139 | } |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 145 | static int boot_bd_t_linux(struct bootm_headers *images) |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 146 | { |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 147 | ulong of_size = images->ft_len; |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 148 | struct bd_info **kbd = &images->kbd; |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 149 | |
| 150 | int ret = 0; |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 151 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 152 | if (!of_size) { |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 153 | /* allocate space for kernel copy of board info */ |
Sughosh Ganu | 291bf9c | 2024-08-26 17:29:18 +0530 | [diff] [blame] | 154 | ret = boot_get_kbd(kbd); |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 155 | if (ret) { |
| 156 | puts("ERROR with allocation of kernel bd\n"); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 157 | return ret; |
Kumar Gala | b937bb7 | 2008-02-27 21:51:49 -0600 | [diff] [blame] | 158 | } |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 159 | set_clocks_in_mhz(*kbd); |
Kumar Gala | a56d7d5 | 2008-02-27 21:51:44 -0600 | [diff] [blame] | 160 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 161 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 162 | return ret; |
| 163 | } |
| 164 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 165 | static int boot_body_linux(struct bootm_headers *images) |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 166 | { |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 167 | int ret; |
| 168 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 169 | /* allocate space for kernel copy of board info */ |
| 170 | ret = boot_bd_t_linux(images); |
| 171 | if (ret) |
| 172 | return ret; |
| 173 | |
Simon Glass | ae7ed57 | 2023-02-05 15:40:13 -0700 | [diff] [blame] | 174 | if (IS_ENABLED(CONFIG_LMB)) { |
Ashok Reddy Soma | 8aaae3d | 2022-07-07 10:45:37 +0200 | [diff] [blame] | 175 | ret = image_setup_linux(images); |
| 176 | if (ret) |
| 177 | return ret; |
| 178 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 179 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 180 | return 0; |
| 181 | } |
Kumar Gala | 56bdf1d | 2008-02-27 21:51:45 -0600 | [diff] [blame] | 182 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 183 | int do_bootm_linux(int flag, struct bootm_info *bmi) |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 184 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 185 | struct bootm_headers *images = bmi->images; |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 186 | int ret; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 187 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 188 | if (flag & BOOTM_STATE_OS_CMDLINE) { |
| 189 | boot_cmdline_linux(images); |
| 190 | return 0; |
| 191 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 192 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 193 | if (flag & BOOTM_STATE_OS_BD_T) { |
| 194 | boot_bd_t_linux(images); |
| 195 | return 0; |
| 196 | } |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 197 | |
Kumar Gala | 180c581 | 2011-12-07 04:42:58 +0000 | [diff] [blame] | 198 | if (flag & BOOTM_STATE_OS_PREP) { |
| 199 | boot_prep_linux(images); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 200 | return 0; |
Kumar Gala | 180c581 | 2011-12-07 04:42:58 +0000 | [diff] [blame] | 201 | } |
Kumar Gala | dcdcfea | 2008-08-15 08:24:31 -0500 | [diff] [blame] | 202 | |
Kumar Gala | 180c581 | 2011-12-07 04:42:58 +0000 | [diff] [blame] | 203 | boot_prep_linux(images); |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 204 | ret = boot_body_linux(images); |
| 205 | if (ret) |
| 206 | return ret; |
| 207 | boot_jump_linux(images); |
Kumar Gala | 18f4c0f | 2008-02-27 21:51:46 -0600 | [diff] [blame] | 208 | |
Kumar Gala | ffccb57 | 2008-10-21 17:25:46 -0500 | [diff] [blame] | 209 | return 0; |
Marian Balakowicz | 2437cf2 | 2008-01-08 18:11:43 +0100 | [diff] [blame] | 210 | } |
Marian Balakowicz | 28fb615 | 2008-01-31 13:20:08 +0100 | [diff] [blame] | 211 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 212 | static void set_clocks_in_mhz (struct bd_info *kbd) |
Marian Balakowicz | 2efc264 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 213 | { |
| 214 | char *s; |
| 215 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 216 | s = env_get("clocks_in_mhz"); |
| 217 | if (s) { |
Marian Balakowicz | 2efc264 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 218 | /* convert all clock information to MHz */ |
| 219 | kbd->bi_intfreq /= 1000000L; |
| 220 | kbd->bi_busfreq /= 1000000L; |
Marian Balakowicz | 2efc264 | 2008-01-31 13:58:13 +0100 | [diff] [blame] | 221 | } |
Marian Balakowicz | 351d3e3 | 2008-02-27 11:02:26 +0100 | [diff] [blame] | 222 | } |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 223 | |
| 224 | #if defined(CONFIG_BOOTM_VXWORKS) |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 225 | void boot_prep_vxworks(struct bootm_headers *images) |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 226 | { |
| 227 | #if defined(CONFIG_OF_LIBFDT) |
| 228 | int off; |
| 229 | u64 base, size; |
| 230 | |
| 231 | if (!images->ft_addr) |
| 232 | return; |
| 233 | |
Stefan Roese | a13a2aa | 2020-08-12 13:16:36 +0200 | [diff] [blame] | 234 | base = (u64)gd->ram_base; |
| 235 | size = (u64)gd->ram_size; |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 236 | |
| 237 | off = fdt_path_offset(images->ft_addr, "/memory"); |
| 238 | if (off < 0) |
| 239 | fdt_fixup_memory(images->ft_addr, base, size); |
| 240 | |
| 241 | #if defined(CONFIG_MP) |
| 242 | #if defined(CONFIG_MPC85xx) |
| 243 | ft_fixup_cpu(images->ft_addr, base + size); |
| 244 | ft_fixup_num_cores(images->ft_addr); |
| 245 | #elif defined(CONFIG_MPC86xx) |
| 246 | off = fdt_add_mem_rsv(images->ft_addr, |
| 247 | determine_mp_bootpg(NULL), (u64)4096); |
| 248 | if (off < 0) |
| 249 | printf("## WARNING %s: %s\n", __func__, fdt_strerror(off)); |
| 250 | ft_fixup_num_cores(images->ft_addr); |
| 251 | #endif |
| 252 | flush_cache((unsigned long)images->ft_addr, images->ft_len); |
| 253 | #endif |
| 254 | #endif |
| 255 | } |
| 256 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 257 | void boot_jump_vxworks(struct bootm_headers *images) |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 258 | { |
| 259 | /* PowerPC VxWorks boot interface conforms to the ePAPR standard |
| 260 | * general purpuse registers: |
| 261 | * |
| 262 | * r3: Effective address of the device tree image |
| 263 | * r4: 0 |
| 264 | * r5: 0 |
| 265 | * r6: ePAPR magic value |
| 266 | * r7: shall be the size of the boot IMA in bytes |
| 267 | * r8: 0 |
| 268 | * r9: 0 |
| 269 | * TCR: WRC = 0, no watchdog timer reset will occur |
| 270 | */ |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 271 | schedule(); |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 272 | |
| 273 | ((void (*)(void *, ulong, ulong, ulong, |
| 274 | ulong, ulong, ulong))images->ep)(images->ft_addr, |
Simon Glass | da1a134 | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 275 | 0, 0, EPAPR_MAGIC, env_get_bootm_mapsize(), 0, 0); |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 276 | } |
| 277 | #endif |