bootm.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
  4. */
  5. #include <common.h>
  6. #include <bootstage.h>
  7. #include <env.h>
  8. #include <image.h>
  9. #include <irq_func.h>
  10. #include <log.h>
  11. #include <asm/cache.h>
  12. #include <asm/global_data.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. static int cleanup_before_linux(void)
  15. {
  16. disable_interrupts();
  17. sync_n_cleanup_cache_all();
  18. return 0;
  19. }
  20. __weak int board_prep_linux(struct bootm_headers *images) { return 0; }
  21. /* Subcommand: PREP */
  22. static int boot_prep_linux(struct bootm_headers *images)
  23. {
  24. int ret;
  25. if (IS_ENABLED(CONFIG_LMB)) {
  26. ret = image_setup_linux(images);
  27. if (ret)
  28. return ret;
  29. }
  30. return board_prep_linux(images);
  31. }
  32. /* Generic implementation for single core CPU */
  33. __weak void board_jump_and_run(ulong entry, int zero, int arch, uint params)
  34. {
  35. void (*kernel_entry)(int zero, int arch, uint params);
  36. kernel_entry = (void (*)(int, int, uint))entry;
  37. kernel_entry(zero, arch, params);
  38. }
  39. /* Subcommand: GO */
  40. static void boot_jump_linux(struct bootm_headers *images, int flag)
  41. {
  42. ulong kernel_entry;
  43. unsigned int r0, r2;
  44. int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
  45. kernel_entry = images->ep;
  46. debug("## Transferring control to Linux (at address %08lx)...\n",
  47. kernel_entry);
  48. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  49. printf("\nStarting kernel ...%s\n\n", fake ?
  50. "(fake run for tracing)" : "");
  51. bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
  52. if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
  53. r0 = 2;
  54. r2 = (unsigned int)images->ft_addr;
  55. } else {
  56. r0 = 1;
  57. r2 = (unsigned int)env_get("bootargs");
  58. }
  59. cleanup_before_linux();
  60. if (!fake)
  61. board_jump_and_run(kernel_entry, r0, 0, r2);
  62. }
  63. int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images)
  64. {
  65. /* No need for those on ARC */
  66. if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
  67. return -1;
  68. if (flag & BOOTM_STATE_OS_PREP)
  69. return boot_prep_linux(images);
  70. if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
  71. boot_jump_linux(images, flag);
  72. return 0;
  73. }
  74. return -1;
  75. }