do_fuse.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2014-2016, Toradex AG
  4. */
  5. /*
  6. * Helpers for i.MX OTP fusing during module production
  7. */
  8. #include <common.h>
  9. #ifndef CONFIG_SPL_BUILD
  10. #include <console.h>
  11. #include <fuse.h>
  12. static int mfgr_fuse(void)
  13. {
  14. unsigned val, val6;
  15. fuse_sense(0, 5, &val);
  16. printf("Fuse 0, 5: %8x\n", val);
  17. fuse_sense(0, 6, &val6);
  18. printf("Fuse 0, 6: %8x\n", val6);
  19. fuse_sense(4, 3, &val);
  20. printf("Fuse 4, 3: %8x\n", val);
  21. fuse_sense(4, 2, &val);
  22. printf("Fuse 4, 2: %8x\n", val);
  23. if (val6 & 0x10) {
  24. puts("BT_FUSE_SEL already fused, will do nothing\n");
  25. return CMD_RET_FAILURE;
  26. }
  27. /* boot cfg */
  28. fuse_prog(0, 5, 0x00005062);
  29. /* BT_FUSE_SEL */
  30. fuse_prog(0, 6, 0x00000010);
  31. return CMD_RET_SUCCESS;
  32. }
  33. int do_mfgr_fuse(cmd_tbl_t *cmdtp, int flag, int argc,
  34. char * const argv[])
  35. {
  36. int ret;
  37. puts("Fusing...\n");
  38. ret = mfgr_fuse();
  39. if (ret == CMD_RET_SUCCESS)
  40. puts("done.\n");
  41. else
  42. puts("failed.\n");
  43. return ret;
  44. }
  45. int do_updt_fuse(cmd_tbl_t *cmdtp, int flag, int argc,
  46. char * const argv[])
  47. {
  48. unsigned val;
  49. int ret;
  50. int confirmed = argc >= 1 && !strcmp(argv[1], "-y");
  51. /* can be used in scripts for command availability check */
  52. if (argc >= 1 && !strcmp(argv[1], "-n"))
  53. return CMD_RET_SUCCESS;
  54. /* boot cfg */
  55. fuse_sense(0, 5, &val);
  56. printf("Fuse 0, 5: %8x\n", val);
  57. if (val & 0x10) {
  58. puts("Fast boot mode already fused, no need to fuse\n");
  59. return CMD_RET_SUCCESS;
  60. }
  61. if (!confirmed) {
  62. puts("Warning: Programming fuses is an irreversible operation!\n"
  63. " Updating to fast boot mode prevents easy\n"
  64. " downgrading to previous BSP versions.\n"
  65. "\nReally perform this fuse programming? <y/N>\n");
  66. if (!confirm_yesno())
  67. return CMD_RET_FAILURE;
  68. }
  69. puts("Fusing fast boot mode...\n");
  70. ret = fuse_prog(0, 5, 0x00005072);
  71. if (ret == CMD_RET_SUCCESS)
  72. puts("done.\n");
  73. else
  74. puts("failed.\n");
  75. return ret;
  76. }
  77. U_BOOT_CMD(
  78. mfgr_fuse, 1, 0, do_mfgr_fuse,
  79. "OTP fusing during module production",
  80. ""
  81. );
  82. U_BOOT_CMD(
  83. updt_fuse, 2, 0, do_updt_fuse,
  84. "OTP fusing during module update",
  85. "updt_fuse [-n] [-y] - boot cfg fast boot mode fusing"
  86. );
  87. #endif /* CONFIG_SPL_BUILD */