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