do_fuse.c 2.1 KB

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