bootm.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2011 Andes Technology Corporation
  4. * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
  5. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  6. * Rick Chen, Andes Technology Corporation <rick@andestech.com>
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <image.h>
  11. #include <asm/byteorder.h>
  12. #include <asm/csr.h>
  13. #include <dm/device.h>
  14. #include <dm/root.h>
  15. #include <u-boot/zlib.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. __weak void board_quiesce_devices(void)
  18. {
  19. }
  20. int arch_fixup_fdt(void *blob)
  21. {
  22. return 0;
  23. }
  24. int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
  25. {
  26. void (*kernel)(ulong hart, void *dtb);
  27. /*
  28. * allow the PREP bootm subcommand, it is required for bootm to work
  29. */
  30. if (flag & BOOTM_STATE_OS_PREP)
  31. return 0;
  32. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  33. return 1;
  34. kernel = (void (*)(ulong, void *))images->ep;
  35. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  36. debug("## Transferring control to Linux (at address %08lx) ...\n",
  37. (ulong)kernel);
  38. if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
  39. #ifdef CONFIG_OF_LIBFDT
  40. debug("using: FDT\n");
  41. if (image_setup_linux(images)) {
  42. printf("FDT creation failed! hanging...");
  43. hang();
  44. }
  45. #endif
  46. }
  47. /* we assume that the kernel is in place */
  48. printf("\nStarting kernel ...\n\n");
  49. /*
  50. * Call remove function of all devices with a removal flag set.
  51. * This may be useful for last-stage operations, like cancelling
  52. * of DMA operation or releasing device internal buffers.
  53. */
  54. dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
  55. cleanup_before_linux();
  56. if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
  57. kernel(csr_read(mhartid), images->ft_addr);
  58. /* does not return */
  59. return 1;
  60. }