boot-mode.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_PH1_SLD3)
  19. case SOC_UNIPHIER_PH1_SLD3:
  20. return ph1_sld3_boot_device();
  21. #endif
  22. #if defined(CONFIG_ARCH_UNIPHIER_PH1_LD4) || \
  23. defined(CONFIG_ARCH_UNIPHIER_PH1_PRO4) || \
  24. defined(CONFIG_ARCH_UNIPHIER_PH1_SLD8)
  25. case SOC_UNIPHIER_PH1_LD4:
  26. case SOC_UNIPHIER_PH1_PRO4:
  27. case SOC_UNIPHIER_PH1_SLD8:
  28. return ph1_ld4_boot_device();
  29. #endif
  30. #if defined(CONFIG_ARCH_UNIPHIER_PH1_PRO5)
  31. case SOC_UNIPHIER_PH1_PRO5:
  32. return ph1_pro5_boot_device();
  33. #endif
  34. #if defined(CONFIG_ARCH_UNIPHIER_PROXSTREAM2) || \
  35. defined(CONFIG_ARCH_UNIPHIER_PH1_LD6B)
  36. case SOC_UNIPHIER_PROXSTREAM2:
  37. case SOC_UNIPHIER_PH1_LD6B:
  38. return proxstream2_boot_device();
  39. #endif
  40. default:
  41. return BOOT_DEVICE_NONE;
  42. }
  43. }
  44. u32 spl_boot_device(void)
  45. {
  46. u32 ret;
  47. ret = spl_boot_device_raw();
  48. return ret == BOOT_DEVICE_USB ? BOOT_DEVICE_NOR : ret;
  49. }
  50. u32 spl_boot_mode(void)
  51. {
  52. struct mmc *mmc;
  53. /*
  54. * work around a bug in the Boot ROM of PH1-sLD3, LD4, Pro4, and sLD8:
  55. *
  56. * The boot ROM in these SoCs breaks the PARTITION_CONFIG [179] of
  57. * Extended CSD register; when switching to the Boot Partition 1, the
  58. * Boot ROM should issue the SWITCH command (CMD6) with Set Bits for
  59. * the Access Bits, but in fact it uses Write Byte for the Access Bits.
  60. * As a result, the BOOT_PARTITION_ENABLE field of the PARTITION_CONFIG
  61. * is lost. This bug was fixed for PH1-Pro5 and later SoCs.
  62. *
  63. * Fixup mmc->part_config here because it is used to determine the
  64. * partition which the U-Boot image is read from.
  65. */
  66. mmc = find_mmc_device(0);
  67. mmc->part_config &= ~EXT_CSD_BOOT_PART_NUM(PART_ACCESS_MASK);
  68. mmc->part_config |= EXT_CSD_BOOT_PARTITION_ENABLE;
  69. return MMCSD_MODE_EMMCBOOT;
  70. }
  71. #if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD)
  72. static int find_first_mmc_device(void)
  73. {
  74. struct mmc *mmc;
  75. int i;
  76. for (i = 0; (mmc = find_mmc_device(i)); i++) {
  77. if (!mmc_init(mmc) && IS_MMC(mmc))
  78. return i;
  79. }
  80. return -ENODEV;
  81. }
  82. int mmc_get_env_dev(void)
  83. {
  84. return find_first_mmc_device();
  85. }
  86. static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  87. {
  88. int dev;
  89. dev = find_first_mmc_device();
  90. if (dev < 0)
  91. return CMD_RET_FAILURE;
  92. setenv_ulong("mmc_first_dev", dev);
  93. return CMD_RET_SUCCESS;
  94. }
  95. U_BOOT_CMD(
  96. mmcsetn, 1, 1, do_mmcsetn,
  97. "Set the first MMC (not SD) dev number to \"mmc_first_dev\" enviroment",
  98. ""
  99. );
  100. #endif