board_late_init.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <spl.h>
  8. #include <libfdt.h>
  9. #include <nand.h>
  10. #include <linux/io.h>
  11. #include <../drivers/mtd/nand/denali.h>
  12. #include "boot-mode/boot-device.h"
  13. static void nand_denali_wp_disable(void)
  14. {
  15. #ifdef CONFIG_NAND_DENALI
  16. /*
  17. * Since the boot rom enables the write protection for NAND boot mode,
  18. * it must be disabled somewhere for "nand write", "nand erase", etc.
  19. * The workaround is here to not disturb the Denali NAND controller
  20. * driver just for a really SoC-specific thing.
  21. */
  22. void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
  23. writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
  24. #endif
  25. }
  26. #define VENDOR_PREFIX "socionext,"
  27. #define DTB_FILE_PREFIX "uniphier-"
  28. static int uniphier_set_fdt_file(void)
  29. {
  30. DECLARE_GLOBAL_DATA_PTR;
  31. const char *compat;
  32. char dtb_name[256];
  33. int buf_len = 256;
  34. int ret;
  35. ret = fdt_get_string(gd->fdt_blob, 0, "compatible", &compat);
  36. if (ret)
  37. return -EINVAL;
  38. if (strncmp(compat, VENDOR_PREFIX, strlen(VENDOR_PREFIX)))
  39. return -EINVAL;
  40. compat += strlen(VENDOR_PREFIX);
  41. strncat(dtb_name, DTB_FILE_PREFIX, buf_len);
  42. buf_len -= strlen(DTB_FILE_PREFIX);
  43. strncat(dtb_name, compat, buf_len);
  44. buf_len -= strlen(compat);
  45. strncat(dtb_name, ".dtb", buf_len);
  46. return setenv("fdt_file", dtb_name);
  47. }
  48. int board_late_init(void)
  49. {
  50. puts("MODE: ");
  51. switch (spl_boot_device_raw()) {
  52. case BOOT_DEVICE_MMC1:
  53. printf("eMMC Boot\n");
  54. setenv("bootmode", "emmcboot");
  55. break;
  56. case BOOT_DEVICE_NAND:
  57. printf("NAND Boot\n");
  58. setenv("bootmode", "nandboot");
  59. nand_denali_wp_disable();
  60. break;
  61. case BOOT_DEVICE_NOR:
  62. printf("NOR Boot\n");
  63. setenv("bootmode", "norboot");
  64. break;
  65. case BOOT_DEVICE_USB:
  66. printf("USB Boot\n");
  67. setenv("bootmode", "usbboot");
  68. break;
  69. default:
  70. printf("Unknown\n");
  71. break;
  72. }
  73. if (uniphier_set_fdt_file())
  74. printf("fdt_file environment was not set correctly\n");
  75. return 0;
  76. }