bootoctlinux.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 Stefan Roese <sr@denx.de>
  4. */
  5. #include <command.h>
  6. #include <config.h>
  7. #include <cpu_func.h>
  8. #include <dm.h>
  9. #include <elf.h>
  10. #include <env.h>
  11. #include <asm/io.h>
  12. #include <linux/compat.h>
  13. #include <linux/ctype.h>
  14. #include <linux/delay.h>
  15. #include <linux/io.h>
  16. #include <mach/cvmx-coremask.h>
  17. #include <mach/cvmx-bootinfo.h>
  18. #include <mach/cvmx-bootmem.h>
  19. #include <mach/cvmx-regs.h>
  20. #include <mach/cvmx-fuse.h>
  21. #include <mach/octeon-model.h>
  22. #include <mach/octeon-feature.h>
  23. #include <mach/bootoct_cmd.h>
  24. DECLARE_GLOBAL_DATA_PTR;
  25. /* ToDo: Revisit these settings */
  26. #define OCTEON_RESERVED_LOW_MEM_SIZE (512 * 1024)
  27. #define OCTEON_RESERVED_LOW_BOOT_MEM_SIZE (1024 * 1024)
  28. #define BOOTLOADER_BOOTMEM_DESC_SPACE (1024 * 1024)
  29. /* Default stack and heap sizes, in bytes */
  30. #define DEFAULT_STACK_SIZE (1 * 1024 * 1024)
  31. #define DEFAULT_HEAP_SIZE (3 * 1024 * 1024)
  32. /**
  33. * NOTE: This must duplicate octeon_boot_descriptor_t in the toolchain
  34. * octeon-app-init.h file.
  35. */
  36. enum {
  37. /* If set, core should do app-wide init, only one core per app will have
  38. * this flag set.
  39. */
  40. BOOT_FLAG_INIT_CORE = 1,
  41. OCTEON_BL_FLAG_DEBUG = 1 << 1,
  42. OCTEON_BL_FLAG_NO_MAGIC = 1 << 2,
  43. /* If set, use uart1 for console */
  44. OCTEON_BL_FLAG_CONSOLE_UART1 = 1 << 3,
  45. OCTEON_BL_FLAG_CONSOLE_PCI = 1 << 4, /* If set, use PCI console */
  46. /* Call exit on break on serial port */
  47. OCTEON_BL_FLAG_BREAK = 1 << 5,
  48. /*
  49. * Be sure to update OCTEON_APP_INIT_H_VERSION when new fields are added
  50. * and to conditionalize the new flag's usage based on the version.
  51. */
  52. } octeon_boot_descriptor_flag;
  53. /**
  54. * NOTE: This must duplicate octeon_boot_descriptor_t in the toolchain
  55. * octeon-app-init.h file.
  56. */
  57. #ifndef OCTEON_CURRENT_DESC_VERSION
  58. # define OCTEON_CURRENT_DESC_VERSION 7
  59. #endif
  60. /**
  61. * NOTE: This must duplicate octeon_boot_descriptor_t in the toolchain
  62. * octeon-app-init.h file.
  63. */
  64. /* Version 7 changes: Change names of deprecated fields */
  65. #ifndef OCTEON_ARGV_MAX_ARGS
  66. # define OCTEON_ARGV_MAX_ARGS 64
  67. #endif
  68. /**
  69. * NOTE: This must duplicate octeon_boot_descriptor_t in the toolchain
  70. * octeon-app-init.h file.
  71. */
  72. #ifndef OCTEON_SERIAL_LEN
  73. # define OCTEON_SERIAL_LEN 20
  74. #endif
  75. /**
  76. * Bootloader structure used to pass info to Octeon executive startup code.
  77. * NOTE: all fields are deprecated except for:
  78. * * desc_version
  79. * * desc_size,
  80. * * heap_base
  81. * * heap_end
  82. * * eclock_hz
  83. * * flags
  84. * * argc
  85. * * argv
  86. * * cvmx_desc_vaddr
  87. * * debugger_flags_base_addr
  88. *
  89. * All other fields have been moved to the cvmx_descriptor, and the new
  90. * fields should be added there. They are left as placeholders in this
  91. * structure for binary compatibility.
  92. *
  93. * NOTE: This structure must match what is in the toolchain octeon-app-init.h
  94. * file.
  95. */
  96. struct octeon_boot_descriptor {
  97. /* Start of block referenced by assembly code - do not change! */
  98. u32 desc_version;
  99. u32 desc_size;
  100. u64 stack_top;
  101. u64 heap_base;
  102. u64 heap_end;
  103. u64 deprecated17;
  104. u64 deprecated16;
  105. /* End of block referenced by assembly code - do not change! */
  106. u32 deprecated18;
  107. u32 deprecated15;
  108. u32 deprecated14;
  109. u32 argc; /* argc for main() */
  110. u32 argv[OCTEON_ARGV_MAX_ARGS]; /* argv for main() */
  111. u32 flags; /* Flags for application */
  112. u32 core_mask; /* Coremask running this image */
  113. u32 dram_size; /* DEPRECATED, DRAM size in megabyes. Used up to SDK 1.8.1 */
  114. u32 phy_mem_desc_addr;
  115. u32 debugger_flags_base_addr; /* used to pass flags from app to debugger. */
  116. u32 eclock_hz; /* CPU clock speed, in hz. */
  117. u32 deprecated10;
  118. u32 deprecated9;
  119. u16 deprecated8;
  120. u8 deprecated7;
  121. u8 deprecated6;
  122. u16 deprecated5;
  123. u8 deprecated4;
  124. u8 deprecated3;
  125. char deprecated2[OCTEON_SERIAL_LEN];
  126. u8 deprecated1[6];
  127. u8 deprecated0;
  128. u64 cvmx_desc_vaddr; /* Address of cvmx descriptor */
  129. };
  130. static struct octeon_boot_descriptor boot_desc[CVMX_MIPS_MAX_CORES];
  131. static struct cvmx_bootinfo cvmx_bootinfo_array[CVMX_MIPS_MAX_CORES];
  132. /**
  133. * Programs the boot bus moveable region
  134. * @param base base address to place the boot bus moveable region
  135. * (bits [31:7])
  136. * @param region_num Selects which region, 0 or 1 for node 0,
  137. * 2 or 3 for node 1
  138. * @param enable Set true to enable, false to disable
  139. * @param data Pointer to data to put in the region, up to
  140. * 16 dwords.
  141. * @param num_words Number of data dwords (up to 32)
  142. *
  143. * @return 0 for success, -1 on error
  144. */
  145. static int octeon_set_moveable_region(u32 base, int region_num,
  146. bool enable, const u64 *data,
  147. unsigned int num_words)
  148. {
  149. int node = region_num >> 1;
  150. u64 val;
  151. int i;
  152. u8 node_mask = 0x01; /* ToDo: Currently only one node is supported */
  153. debug("%s(0x%x, %d, %d, %p, %u)\n", __func__, base, region_num, enable,
  154. data, num_words);
  155. if (num_words > 32) {
  156. printf("%s: Too many words (%d) for region %d\n", __func__,
  157. num_words, region_num);
  158. return -1;
  159. }
  160. if (base & 0x7f) {
  161. printf("%s: Error: base address 0x%x must be 128 byte aligned\n",
  162. __func__, base);
  163. return -1;
  164. }
  165. if (region_num > (node_mask > 1 ? 3 : 1)) {
  166. printf("%s: Region number %d out of range\n",
  167. __func__, region_num);
  168. return -1;
  169. }
  170. if (!data && num_words > 0) {
  171. printf("%s: Error: NULL data\n", __func__);
  172. return -1;
  173. }
  174. region_num &= 1;
  175. val = MIO_BOOT_LOC_CFG_EN |
  176. FIELD_PREP(MIO_BOOT_LOC_CFG_BASE, base >> 7);
  177. debug("%s: Setting MIO_BOOT_LOC_CFG(%d) on node %d to 0x%llx\n",
  178. __func__, region_num, node, val);
  179. csr_wr(CVMX_MIO_BOOT_LOC_CFGX(region_num & 1), val);
  180. val = FIELD_PREP(MIO_BOOT_LOC_ADR_ADR, (region_num ? 0x80 : 0x00) >> 3);
  181. debug("%s: Setting MIO_BOOT_LOC_ADR start to 0x%llx\n", __func__, val);
  182. csr_wr(CVMX_MIO_BOOT_LOC_ADR, val);
  183. for (i = 0; i < num_words; i++) {
  184. debug(" 0x%02llx: 0x%016llx\n",
  185. csr_rd(CVMX_MIO_BOOT_LOC_ADR), data[i]);
  186. csr_wr(CVMX_MIO_BOOT_LOC_DAT, data[i]);
  187. }
  188. return 0;
  189. }
  190. /**
  191. * Parse comma separated numbers into an array
  192. *
  193. * @param[out] values values read for each node
  194. * @param[in] str string to parse
  195. * @param base 0 for auto, otherwise 8, 10 or 16 for the number base
  196. *
  197. * @return number of values read.
  198. */
  199. static int octeon_parse_nodes(u64 values[CVMX_MAX_NODES],
  200. const char *str, int base)
  201. {
  202. int node = 0;
  203. char *sep;
  204. do {
  205. debug("Parsing node %d: \"%s\"\n", node, str);
  206. values[node] = simple_strtoull(str, &sep, base);
  207. debug(" node %d: 0x%llx\n", node, values[node]);
  208. str = sep + 1;
  209. } while (++node < CVMX_MAX_NODES && *sep == ',');
  210. debug("%s: returning %d\n", __func__, node);
  211. return node;
  212. }
  213. /**
  214. * Parse command line arguments
  215. *
  216. * @param argc number of arguments
  217. * @param[in] argv array of argument strings
  218. * @param cmd command type
  219. * @param[out] boot_args parsed values
  220. *
  221. * @return number of arguments parsed
  222. */
  223. int octeon_parse_bootopts(int argc, char *const argv[],
  224. enum octeon_boot_cmd_type cmd,
  225. struct octeon_boot_args *boot_args)
  226. {
  227. u64 node_values[CVMX_MAX_NODES];
  228. int arg, j;
  229. int num_values;
  230. int node;
  231. u8 node_mask = 0x01; /* ToDo: Currently only one node is supported */
  232. debug("%s(%d, %p, %d, %p)\n", __func__, argc, argv, cmd, boot_args);
  233. memset(boot_args, 0, sizeof(*boot_args));
  234. boot_args->stack_size = DEFAULT_STACK_SIZE;
  235. boot_args->heap_size = DEFAULT_HEAP_SIZE;
  236. boot_args->node_mask = 0;
  237. for (arg = 0; arg < argc; arg++) {
  238. debug(" argv[%d]: %s\n", arg, argv[arg]);
  239. if (cmd == BOOTOCT && !strncmp(argv[arg], "stack=", 6)) {
  240. boot_args->stack_size = simple_strtoul(argv[arg] + 6,
  241. NULL, 0);
  242. } else if (cmd == BOOTOCT && !strncmp(argv[arg], "heap=", 5)) {
  243. boot_args->heap_size = simple_strtoul(argv[arg] + 5,
  244. NULL, 0);
  245. } else if (!strncmp(argv[arg], "debug", 5)) {
  246. puts("setting debug flag!\n");
  247. boot_args->boot_flags |= OCTEON_BL_FLAG_DEBUG;
  248. } else if (cmd == BOOTOCT && !strncmp(argv[arg], "break", 5)) {
  249. puts("setting break flag!\n");
  250. boot_args->boot_flags |= OCTEON_BL_FLAG_BREAK;
  251. } else if (!strncmp(argv[arg], "forceboot", 9)) {
  252. boot_args->forceboot = true;
  253. } else if (!strncmp(argv[arg], "nodemask=", 9)) {
  254. boot_args->node_mask = simple_strtoul(argv[arg] + 9,
  255. NULL, 16);
  256. } else if (!strncmp(argv[arg], "numcores=", 9)) {
  257. memset(node_values, 0, sizeof(node_values));
  258. num_values = octeon_parse_nodes(node_values,
  259. argv[arg] + 9, 0);
  260. for (j = 0; j < num_values; j++)
  261. boot_args->num_cores[j] = node_values[j];
  262. boot_args->num_cores_set = true;
  263. } else if (!strncmp(argv[arg], "skipcores=", 10)) {
  264. memset(node_values, 0, sizeof(node_values));
  265. num_values = octeon_parse_nodes(node_values,
  266. argv[arg] + 10, 0);
  267. for (j = 0; j < num_values; j++)
  268. boot_args->num_skipped[j] = node_values[j];
  269. boot_args->num_skipped_set = true;
  270. } else if (!strncmp(argv[arg], "console_uart=", 13)) {
  271. boot_args->console_uart = simple_strtoul(argv[arg] + 13,
  272. NULL, 0);
  273. if (boot_args->console_uart == 1) {
  274. boot_args->boot_flags |=
  275. OCTEON_BL_FLAG_CONSOLE_UART1;
  276. } else if (!boot_args->console_uart) {
  277. boot_args->boot_flags &=
  278. ~OCTEON_BL_FLAG_CONSOLE_UART1;
  279. }
  280. } else if (!strncmp(argv[arg], "coremask=", 9)) {
  281. memset(node_values, 0, sizeof(node_values));
  282. num_values = octeon_parse_nodes(node_values,
  283. argv[arg] + 9, 16);
  284. for (j = 0; j < num_values; j++)
  285. cvmx_coremask_set64_node(&boot_args->coremask,
  286. j, node_values[j]);
  287. boot_args->coremask_set = true;
  288. } else if (cmd == BOOTOCTLINUX &&
  289. !strncmp(argv[arg], "namedblock=", 11)) {
  290. boot_args->named_block = argv[arg] + 11;
  291. } else if (!strncmp(argv[arg], "endbootargs", 11)) {
  292. boot_args->endbootargs = 1;
  293. arg++;
  294. if (argc >= arg && cmd != BOOTOCTLINUX)
  295. boot_args->app_name = argv[arg];
  296. break;
  297. } else {
  298. debug(" Unknown argument \"%s\"\n", argv[arg]);
  299. }
  300. }
  301. if (boot_args->coremask_set && boot_args->num_cores_set) {
  302. puts("Warning: both coremask and numcores are set, using coremask.\n");
  303. } else if (!boot_args->coremask_set && !boot_args->num_cores_set) {
  304. cvmx_coremask_set_core(&boot_args->coremask, 0);
  305. boot_args->coremask_set = true;
  306. } else if ((!boot_args->coremask_set) && boot_args->num_cores_set) {
  307. cvmx_coremask_for_each_node(node, node_mask)
  308. cvmx_coremask_set64_node(&boot_args->coremask, node,
  309. ((1ull << boot_args->num_cores[node]) - 1) <<
  310. boot_args->num_skipped[node]);
  311. boot_args->coremask_set = true;
  312. }
  313. /* Update the node mask based on the coremask or the number of cores */
  314. for (j = 0; j < CVMX_MAX_NODES; j++) {
  315. if (cvmx_coremask_get64_node(&boot_args->coremask, j))
  316. boot_args->node_mask |= 1 << j;
  317. }
  318. debug("%s: return %d\n", __func__, arg);
  319. return arg;
  320. }
  321. int do_bootoctlinux(struct cmd_tbl *cmdtp, int flag, int argc,
  322. char *const argv[])
  323. {
  324. typedef void __noreturn (*kernel_entry_t)(int, ulong, ulong, ulong);
  325. kernel_entry_t kernel;
  326. struct octeon_boot_args boot_args;
  327. int arg_start = 1;
  328. int arg_count;
  329. u64 addr = 0; /* Address of the ELF image */
  330. int arg0;
  331. u64 arg1;
  332. u64 arg2;
  333. u64 arg3;
  334. int ret;
  335. struct cvmx_coremask core_mask;
  336. struct cvmx_coremask coremask_to_run;
  337. struct cvmx_coremask avail_coremask;
  338. int first_core;
  339. int core;
  340. const u64 *nmi_code;
  341. int num_dwords;
  342. u8 node_mask = 0x01;
  343. int i;
  344. cvmx_coremask_clear_all(&core_mask);
  345. cvmx_coremask_clear_all(&coremask_to_run);
  346. if (argc >= 2 && (isxdigit(argv[1][0]) && (isxdigit(argv[1][1]) ||
  347. argv[1][1] == 'x' ||
  348. argv[1][1] == 'X' ||
  349. argv[1][1] == '\0'))) {
  350. addr = simple_strtoul(argv[1], NULL, 16);
  351. if (!addr)
  352. addr = CONFIG_SYS_LOAD_ADDR;
  353. arg_start++;
  354. }
  355. if (addr == 0)
  356. addr = CONFIG_SYS_LOAD_ADDR;
  357. debug("%s: arg start: %d\n", __func__, arg_start);
  358. arg_count = octeon_parse_bootopts(argc - arg_start, argv + arg_start,
  359. BOOTOCTLINUX, &boot_args);
  360. debug("%s:\n"
  361. " named block: %s\n"
  362. " node mask: 0x%x\n"
  363. " stack size: 0x%x\n"
  364. " heap size: 0x%x\n"
  365. " boot flags: 0x%x\n"
  366. " force boot: %s\n"
  367. " coremask set: %s\n"
  368. " num cores set: %s\n"
  369. " num skipped set: %s\n"
  370. " endbootargs: %s\n",
  371. __func__,
  372. boot_args.named_block ? boot_args.named_block : "none",
  373. boot_args.node_mask,
  374. boot_args.stack_size,
  375. boot_args.heap_size,
  376. boot_args.boot_flags,
  377. boot_args.forceboot ? "true" : "false",
  378. boot_args.coremask_set ? "true" : "false",
  379. boot_args.num_cores_set ? "true" : "false",
  380. boot_args.num_skipped_set ? "true" : "false",
  381. boot_args.endbootargs ? "true" : "false");
  382. debug(" num cores: ");
  383. for (i = 0; i < CVMX_MAX_NODES; i++)
  384. debug("%s%d", i > 0 ? ", " : "", boot_args.num_cores[i]);
  385. debug("\n num skipped: ");
  386. for (i = 0; i < CVMX_MAX_NODES; i++) {
  387. debug("%s%d", i > 0 ? ", " : "", boot_args.num_skipped[i]);
  388. debug("\n coremask:\n");
  389. cvmx_coremask_dprint(&boot_args.coremask);
  390. }
  391. if (boot_args.endbootargs) {
  392. debug("endbootargs set, adjusting argc from %d to %d, arg_count: %d, arg_start: %d\n",
  393. argc, argc - (arg_count + arg_start), arg_count,
  394. arg_start);
  395. argc -= (arg_count + arg_start);
  396. argv += (arg_count + arg_start);
  397. }
  398. /*
  399. * numcores specification overrides a coremask on the same command line
  400. */
  401. cvmx_coremask_copy(&core_mask, &boot_args.coremask);
  402. /*
  403. * Remove cores from coremask based on environment variable stored in
  404. * flash
  405. */
  406. if (validate_coremask(&core_mask) != 0) {
  407. puts("Invalid coremask.\n");
  408. return 1;
  409. } else if (cvmx_coremask_is_empty(&core_mask)) {
  410. puts("Coremask is empty after coremask_override mask. Nothing to do.\n");
  411. return 0;
  412. }
  413. if (cvmx_coremask_intersects(&core_mask, &coremask_to_run)) {
  414. puts("ERROR: Can't load code on core twice! Provided coremask:\n");
  415. cvmx_coremask_print(&core_mask);
  416. puts("overlaps previously loaded coremask:\n");
  417. cvmx_coremask_print(&coremask_to_run);
  418. return -1;
  419. }
  420. debug("Setting up boot descriptor block with core mask:\n");
  421. cvmx_coremask_dprint(&core_mask);
  422. /*
  423. * Add coremask to global mask of cores that have been set up and are
  424. * runable
  425. */
  426. cvmx_coremask_or(&coremask_to_run, &coremask_to_run, &core_mask);
  427. /*
  428. * Load kernel ELF image, or try binary if ELF is not detected.
  429. * This way the much smaller vmlinux.bin can also be started but
  430. * has to be loaded at the correct address (ep as parameter).
  431. */
  432. if (!valid_elf_image(addr))
  433. printf("Booting binary image instead (vmlinux.bin)...\n");
  434. else
  435. addr = load_elf_image_shdr(addr);
  436. /* Set kernel entry point */
  437. kernel = (kernel_entry_t)addr;
  438. /* Init bootmem list for Linux kernel booting */
  439. if (!cvmx_bootmem_phy_mem_list_init(
  440. gd->ram_size, OCTEON_RESERVED_LOW_MEM_SIZE,
  441. (void *)CKSEG0ADDR(BOOTLOADER_BOOTMEM_DESC_SPACE))) {
  442. printf("FATAL: Error initializing free memory list\n");
  443. return 0;
  444. }
  445. first_core = cvmx_coremask_get_first_core(&coremask_to_run);
  446. cvmx_coremask_for_each_core(core, &coremask_to_run) {
  447. debug("%s: Activating core %d\n", __func__, core);
  448. cvmx_bootinfo_array[core].core_mask =
  449. cvmx_coremask_get32(&coremask_to_run);
  450. cvmx_coremask_copy(&cvmx_bootinfo_array[core].ext_core_mask,
  451. &coremask_to_run);
  452. if (core == first_core)
  453. cvmx_bootinfo_array[core].flags |= BOOT_FLAG_INIT_CORE;
  454. cvmx_bootinfo_array[core].dram_size = gd->ram_size /
  455. (1024 * 1024);
  456. cvmx_bootinfo_array[core].dclock_hz = gd->mem_clk * 1000000;
  457. cvmx_bootinfo_array[core].eclock_hz = gd->cpu_clk;
  458. cvmx_bootinfo_array[core].led_display_base_addr = 0;
  459. cvmx_bootinfo_array[core].phy_mem_desc_addr =
  460. ((u32)(u64)__cvmx_bootmem_internal_get_desc_ptr()) &
  461. 0x7ffffff;
  462. cvmx_bootinfo_array[core].major_version = CVMX_BOOTINFO_MAJ_VER;
  463. cvmx_bootinfo_array[core].minor_version = CVMX_BOOTINFO_MIN_VER;
  464. cvmx_bootinfo_array[core].fdt_addr = virt_to_phys(gd->fdt_blob);
  465. boot_desc[core].dram_size = gd->ram_size / (1024 * 1024);
  466. boot_desc[core].cvmx_desc_vaddr =
  467. virt_to_phys(&cvmx_bootinfo_array[core]);
  468. boot_desc[core].desc_version = OCTEON_CURRENT_DESC_VERSION;
  469. boot_desc[core].desc_size = sizeof(boot_desc[0]);
  470. boot_desc[core].flags = cvmx_bootinfo_array[core].flags;
  471. boot_desc[core].eclock_hz = cvmx_bootinfo_array[core].eclock_hz;
  472. boot_desc[core].argc = argc;
  473. for (i = 0; i < argc; i++)
  474. boot_desc[core].argv[i] = (u32)virt_to_phys(argv[i]);
  475. }
  476. core = 0;
  477. arg0 = argc;
  478. arg1 = (u64)argv;
  479. arg2 = 0x1; /* Core 0 sets init core for Linux */
  480. arg3 = XKPHYS | virt_to_phys(&boot_desc[core]);
  481. debug("## Transferring control to Linux (at address %p) ...\n", kernel);
  482. /*
  483. * Flush cache before jumping to application. Let's flush the
  484. * whole SDRAM area, since we don't know the size of the image
  485. * that was loaded.
  486. */
  487. flush_cache(gd->ram_base, gd->ram_top - gd->ram_base);
  488. /* Take all cores out of reset */
  489. csr_wr(CVMX_CIU_PP_RST, 0);
  490. sync();
  491. /* Wait a short while for the other cores... */
  492. mdelay(100);
  493. /* Install boot code into moveable bus for NMI (other cores) */
  494. nmi_code = (const u64 *)nmi_bootvector;
  495. num_dwords = (((u64)&nmi_handler_para[0] - (u64)nmi_code) + 7) / 8;
  496. ret = octeon_set_moveable_region(0x1fc00000, 0, true, nmi_code,
  497. num_dwords);
  498. if (ret) {
  499. printf("Error installing NMI handler for SMP core startup\n");
  500. return 0;
  501. }
  502. /* Write NMI handler parameters for Linux kernel booting */
  503. nmi_handler_para[0] = (u64)kernel;
  504. nmi_handler_para[1] = arg0;
  505. nmi_handler_para[2] = arg1;
  506. nmi_handler_para[3] = 0; /* Don't set init core for secondary cores */
  507. nmi_handler_para[4] = arg3;
  508. sync();
  509. /* Wait a short while for the other cores... */
  510. mdelay(100);
  511. /*
  512. * Cores have already been taken out of reset to conserve power.
  513. * We need to send a NMI to get the cores out of their wait loop
  514. */
  515. octeon_get_available_coremask(&avail_coremask);
  516. debug("Available coremask:\n");
  517. cvmx_coremask_dprint(&avail_coremask);
  518. debug("Starting coremask:\n");
  519. cvmx_coremask_dprint(&coremask_to_run);
  520. debug("Sending NMIs to other cores\n");
  521. if (octeon_has_feature(OCTEON_FEATURE_CIU3)) {
  522. u64 avail_cm;
  523. int node;
  524. cvmx_coremask_for_each_node(node, node_mask) {
  525. avail_cm = cvmx_coremask_get64_node(&avail_coremask,
  526. node);
  527. if (avail_cm != 0) {
  528. debug("Sending NMI to node %d, coremask=0x%llx, CIU3_NMI=0x%llx\n",
  529. node, avail_cm,
  530. (node > 0 ? -1ull : -2ull) & avail_cm);
  531. csr_wr(CVMX_CIU3_NMI,
  532. (node > 0 ? -1ull : -2ull) & avail_cm);
  533. }
  534. }
  535. } else {
  536. csr_wr(CVMX_CIU_NMI,
  537. -2ull & cvmx_coremask_get64(&avail_coremask));
  538. }
  539. debug("Done sending NMIs\n");
  540. /* Wait a short while for the other cores... */
  541. mdelay(100);
  542. /*
  543. * pass address parameter as argv[0] (aka command name),
  544. * and all remaining args
  545. * a0 = argc
  546. * a1 = argv (32 bit physical addresses, not pointers)
  547. * a2 = init core
  548. * a3 = boot descriptor address
  549. * a4/t0 = entry point (only used by assembly stub)
  550. */
  551. kernel(arg0, arg1, arg2, arg3);
  552. return 0;
  553. }
  554. U_BOOT_CMD(bootoctlinux, 32, 0, do_bootoctlinux,
  555. "Boot from a linux ELF image in memory",
  556. "elf_address [coremask=mask_to_run | numcores=core_cnt_to_run] "
  557. "[forceboot] [skipcores=core_cnt_to_skip] [namedblock=name] [endbootargs] [app_args ...]\n"
  558. "elf_address - address of ELF image to load. If 0, default load address\n"
  559. " is used.\n"
  560. "coremask - mask of cores to run on. Anded with coremask_override\n"
  561. " environment variable to ensure only working cores are used\n"
  562. "numcores - number of cores to run on. Runs on specified number of cores,\n"
  563. " taking into account the coremask_override.\n"
  564. "skipcores - only meaningful with numcores. Skips this many cores\n"
  565. " (starting from 0) when loading the numcores cores.\n"
  566. " For example, setting skipcores to 1 will skip core 0\n"
  567. " and load the application starting at the next available core.\n"
  568. "forceboot - if set, boots application even if core 0 is not in mask\n"
  569. "namedblock - specifies a named block to load the kernel\n"
  570. "endbootargs - if set, bootloader does not process any further arguments and\n"
  571. " only passes the arguments that follow to the kernel.\n"
  572. " If not set, the kernel gets the entire commnad line as\n"
  573. " arguments.\n" "\n");