boot-mode.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <mmc.h>
  8. #include <spl.h>
  9. #include <linux/err.h>
  10. #include "../sbc/sbc-regs.h"
  11. #include "../soc-info.h"
  12. #include "boot-device.h"
  13. u32 spl_boot_device_raw(void)
  14. {
  15. if (boot_is_swapped())
  16. return BOOT_DEVICE_NOR;
  17. switch (uniphier_get_soc_type()) {
  18. #if defined(CONFIG_ARCH_UNIPHIER_SLD3)
  19. case SOC_UNIPHIER_SLD3:
  20. return uniphier_sld3_boot_device();
  21. #endif
  22. #if defined(CONFIG_ARCH_UNIPHIER_LD4) || defined(CONFIG_ARCH_UNIPHIER_PRO4) || \
  23. defined(CONFIG_ARCH_UNIPHIER_SLD8)
  24. case SOC_UNIPHIER_LD4:
  25. case SOC_UNIPHIER_PRO4:
  26. case SOC_UNIPHIER_SLD8:
  27. return uniphier_ld4_boot_device();
  28. #endif
  29. #if defined(CONFIG_ARCH_UNIPHIER_PRO5)
  30. case SOC_UNIPHIER_PRO5:
  31. return uniphier_pro5_boot_device();
  32. #endif
  33. #if defined(CONFIG_ARCH_UNIPHIER_PXS2) || defined(CONFIG_ARCH_UNIPHIER_LD6B)
  34. case SOC_UNIPHIER_PXS2:
  35. case SOC_UNIPHIER_LD6B:
  36. return uniphier_pxs2_boot_device();
  37. #endif
  38. #if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20)
  39. case SOC_UNIPHIER_LD11:
  40. case SOC_UNIPHIER_LD20:
  41. return uniphier_ld20_boot_device();
  42. #endif
  43. default:
  44. return BOOT_DEVICE_NONE;
  45. }
  46. }
  47. u32 spl_boot_device(void)
  48. {
  49. u32 mode;
  50. mode = spl_boot_device_raw();
  51. switch (uniphier_get_soc_type()) {
  52. #if defined(CONFIG_ARCH_UNIPHIER_PXS2) || defined(CONFIG_ARCH_UNIPHIER_LD6B)
  53. case SOC_UNIPHIER_PXS2:
  54. case SOC_UNIPHIER_LD6B:
  55. if (mode == BOOT_DEVICE_USB)
  56. mode = BOOT_DEVICE_NOR;
  57. break;
  58. #endif
  59. #if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20)
  60. case SOC_UNIPHIER_LD11:
  61. case SOC_UNIPHIER_LD20:
  62. if (mode == BOOT_DEVICE_MMC1 || mode == BOOT_DEVICE_USB)
  63. mode = BOOT_DEVICE_BOARD;
  64. break;
  65. #endif
  66. default:
  67. break;
  68. }
  69. return mode;
  70. }
  71. u32 spl_boot_mode(const u32 boot_device)
  72. {
  73. struct mmc *mmc;
  74. /*
  75. * work around a bug in the Boot ROM of PH1-sLD3, LD4, Pro4, and sLD8:
  76. *
  77. * The boot ROM in these SoCs breaks the PARTITION_CONFIG [179] of
  78. * Extended CSD register; when switching to the Boot Partition 1, the
  79. * Boot ROM should issue the SWITCH command (CMD6) with Set Bits for
  80. * the Access Bits, but in fact it uses Write Byte for the Access Bits.
  81. * As a result, the BOOT_PARTITION_ENABLE field of the PARTITION_CONFIG
  82. * is lost. This bug was fixed for PH1-Pro5 and later SoCs.
  83. *
  84. * Fixup mmc->part_config here because it is used to determine the
  85. * partition which the U-Boot image is read from.
  86. */
  87. mmc = find_mmc_device(0);
  88. mmc->part_config &= ~EXT_CSD_BOOT_PART_NUM(PART_ACCESS_MASK);
  89. mmc->part_config |= EXT_CSD_BOOT_PARTITION_ENABLE;
  90. return MMCSD_MODE_EMMCBOOT;
  91. }
  92. #if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD)
  93. static int find_first_mmc_device(void)
  94. {
  95. struct mmc *mmc;
  96. int i;
  97. for (i = 0; (mmc = find_mmc_device(i)); i++) {
  98. if (!mmc_init(mmc) && IS_MMC(mmc))
  99. return i;
  100. }
  101. return -ENODEV;
  102. }
  103. int mmc_get_env_dev(void)
  104. {
  105. return find_first_mmc_device();
  106. }
  107. static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  108. {
  109. int dev;
  110. dev = find_first_mmc_device();
  111. if (dev < 0)
  112. return CMD_RET_FAILURE;
  113. setenv_ulong("mmc_first_dev", dev);
  114. return CMD_RET_SUCCESS;
  115. }
  116. U_BOOT_CMD(
  117. mmcsetn, 1, 1, do_mmcsetn,
  118. "Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment",
  119. ""
  120. );
  121. #endif