1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019-2020 NXP.
7 * Configuration of the Tamper pins in different mode:
8 * - default (no tamper pins): _default_
9 * - passive mode expecting VCC on the line: "_passive_vcc_"
10 * - passive mode expecting VCC on the line: "_passive_gnd_"
11 * - active mode: "_active_"
18 #include <asm/arch/sci/sci.h>
19 #include <asm/arch-imx8/imx8-pins.h>
20 #include <asm/arch-imx8/snvs_security_sc.h>
21 #include <asm/global_data.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 #define SC_WRITE_CONF 1
28 #define PGD_HEX_VALUE 0x41736166
32 struct snvs_security_sc_conf {
34 u32 lock; /* HPLR - HP Lock */
35 u32 __cmd; /* HPCOMR - HP Command */
36 u32 __ctl; /* HPCR - HP Control */
37 u32 secvio_intcfg; /* HPSICR - Security Violation Int
40 u32 secvio_ctl; /* HPSVCR - Security Violation Control*/
41 u32 status; /* HPSR - HP Status */
42 u32 secvio_status; /* HPSVSR - Security Violation Status */
43 u32 __ha_counteriv; /* High Assurance Counter IV */
44 u32 __ha_counter; /* High Assurance Counter */
45 u32 __rtc_msb; /* Real Time Clock/Counter MSB */
46 u32 __rtc_lsb; /* Real Time Counter LSB */
47 u32 __time_alarm_msb; /* Time Alarm MSB */
48 u32 __time_alarm_lsb; /* Time Alarm LSB */
53 u32 __mstr_key_ctl; /* Master Key Control */
54 u32 secvio_ctl; /* Security Violation Control */
55 u32 tamper_filt_cfg; /* Tamper Glitch Filters Configuration*/
56 u32 tamper_det_cfg; /* Tamper Detectors Configuration */
58 u32 __srtc_msb; /* Secure Real Time Clock/Counter MSB */
59 u32 __srtc_lsb; /* Secure Real Time Clock/Counter LSB */
60 u32 __time_alarm; /* Time Alarm */
61 u32 __smc_msb; /* Secure Monotonic Counter MSB */
62 u32 __smc_lsb; /* Secure Monotonic Counter LSB */
63 u32 __pwr_glitch_det; /* Power Glitch Detector */
65 u8 __zmk[32]; /* Zeroizable Master Key */
67 u32 __gen_purposes[4]; /* gp0_30 to gp0_33 */
68 u32 tamper_det_cfg2; /* Tamper Detectors Configuration2 */
69 u32 tamper_det_status; /* Tamper Detectors status */
70 u32 tamper_filt1_cfg; /* Tamper Glitch Filter1 Configuration*/
71 u32 tamper_filt2_cfg; /* Tamper Glitch Filter2 Configuration*/
73 u32 act_tamper1_cfg; /* Active Tamper1 Configuration */
74 u32 act_tamper2_cfg; /* Active Tamper2 Configuration */
75 u32 act_tamper3_cfg; /* Active Tamper3 Configuration */
76 u32 act_tamper4_cfg; /* Active Tamper4 Configuration */
77 u32 act_tamper5_cfg; /* Active Tamper5 Configuration */
79 u32 act_tamper_ctl; /* Active Tamper Control */
80 u32 act_tamper_clk_ctl; /* Active Tamper Clock Control */
81 u32 act_tamper_routing_ctl1;/* Active Tamper Routing Control1 */
82 u32 act_tamper_routing_ctl2;/* Active Tamper Routing Control2 */
86 static struct snvs_security_sc_conf snvs_default_config = {
89 .secvio_ctl = 0x3000007f,
95 .tamper_det_cfg = 0x76, /* analogic tampers
99 .tamper_filt1_cfg = 0,
100 .tamper_filt2_cfg = 0,
101 .act_tamper1_cfg = 0,
102 .act_tamper2_cfg = 0,
103 .act_tamper3_cfg = 0,
104 .act_tamper4_cfg = 0,
105 .act_tamper5_cfg = 0,
107 .act_tamper_clk_ctl = 0,
108 .act_tamper_routing_ctl1 = 0,
109 .act_tamper_routing_ctl2 = 0,
113 static struct snvs_security_sc_conf snvs_passive_vcc_config = {
116 .secvio_ctl = 0x3000007f,
121 .tamper_filt_cfg = 0,
122 .tamper_det_cfg = 0x276, /* ET1 will trig on line at GND
126 .tamper_det_cfg2 = 0,
127 .tamper_filt1_cfg = 0,
128 .tamper_filt2_cfg = 0,
129 .act_tamper1_cfg = 0,
130 .act_tamper2_cfg = 0,
131 .act_tamper3_cfg = 0,
132 .act_tamper4_cfg = 0,
133 .act_tamper5_cfg = 0,
135 .act_tamper_clk_ctl = 0,
136 .act_tamper_routing_ctl1 = 0,
137 .act_tamper_routing_ctl2 = 0,
141 static struct snvs_security_sc_conf snvs_passive_gnd_config = {
144 .secvio_ctl = 0x3000007f,
149 .tamper_filt_cfg = 0,
150 .tamper_det_cfg = 0xa76, /* ET1 will trig on line at VCC
154 .tamper_det_cfg2 = 0,
155 .tamper_filt1_cfg = 0,
156 .tamper_filt2_cfg = 0,
157 .act_tamper1_cfg = 0,
158 .act_tamper2_cfg = 0,
159 .act_tamper3_cfg = 0,
160 .act_tamper4_cfg = 0,
161 .act_tamper5_cfg = 0,
163 .act_tamper_clk_ctl = 0,
164 .act_tamper_routing_ctl1 = 0,
165 .act_tamper_routing_ctl2 = 0,
169 static struct snvs_security_sc_conf snvs_active_config = {
172 .secvio_ctl = 0x3000007f,
177 .tamper_filt_cfg = 0x00800000, /* Enable filtering */
178 .tamper_det_cfg = 0x276, /* ET1 enabled + analogic tampers
181 .tamper_det_cfg2 = 0,
182 .tamper_filt1_cfg = 0,
183 .tamper_filt2_cfg = 0,
184 .act_tamper1_cfg = 0x84001111,
185 .act_tamper2_cfg = 0,
186 .act_tamper3_cfg = 0,
187 .act_tamper4_cfg = 0,
188 .act_tamper5_cfg = 0,
189 .act_tamper_ctl = 0x00010001,
190 .act_tamper_clk_ctl = 0,
191 .act_tamper_routing_ctl1 = 0x1,
192 .act_tamper_routing_ctl2 = 0,
196 static struct snvs_security_sc_conf *get_snvs_config(void)
198 return &snvs_default_config;
201 struct snvs_dgo_conf {
202 u32 tamper_offset_ctl;
204 u32 tamper_ana_test_ctl;
205 u32 tamper_sensor_trim_ctl;
207 u32 tamper_core_volt_mon_ctl;
210 static struct snvs_dgo_conf snvs_dgo_default_config = {
211 .tamper_misc_ctl = 0x80000000, /* Lock the DGO */
214 static struct snvs_dgo_conf snvs_dgo_passive_vcc_config = {
215 .tamper_misc_ctl = 0x80000000, /* Lock the DGO */
216 .tamper_pull_ctl = 0x00000001, /* Pull down ET1 */
217 .tamper_ana_test_ctl = 0x20000000, /* Enable tamper */
220 static struct snvs_dgo_conf snvs_dgo_passive_gnd_config = {
221 .tamper_misc_ctl = 0x80000000, /* Lock the DGO */
222 .tamper_pull_ctl = 0x00000401, /* Pull up ET1 */
223 .tamper_ana_test_ctl = 0x20000000, /* Enable tamper */
226 static struct snvs_dgo_conf snvs_dgo_active_config = {
227 .tamper_misc_ctl = 0x80000000, /* Lock the DGO */
228 .tamper_ana_test_ctl = 0x20000000, /* Enable tamper */
231 static struct snvs_dgo_conf *get_snvs_dgo_config(void)
233 return &snvs_dgo_default_config;
236 struct tamper_pin_cfg {
241 static struct tamper_pin_cfg tamper_pin_list_default_config[] = {
242 {SC_P_CSI_D00, 0}, /* Tamp_Out0 */
243 {SC_P_CSI_D01, 0}, /* Tamp_Out1 */
244 {SC_P_CSI_D02, 0}, /* Tamp_Out2 */
245 {SC_P_CSI_D03, 0}, /* Tamp_Out3 */
246 {SC_P_CSI_D04, 0}, /* Tamp_Out4 */
247 {SC_P_CSI_D05, 0}, /* Tamp_In0 */
248 {SC_P_CSI_D06, 0}, /* Tamp_In1 */
249 {SC_P_CSI_D07, 0}, /* Tamp_In2 */
250 {SC_P_CSI_HSYNC, 0}, /* Tamp_In3 */
251 {SC_P_CSI_VSYNC, 0}, /* Tamp_In4 */
254 static struct tamper_pin_cfg tamper_pin_list_passive_vcc_config[] = {
255 {SC_P_CSI_D05, 0x1c000060}, /* Tamp_In0 */ /* Sel tamper + OD input */
258 static struct tamper_pin_cfg tamper_pin_list_passive_gnd_config[] = {
259 {SC_P_CSI_D05, 0x1c000060}, /* Tamp_In0 */ /* Sel tamper + OD input */
262 static struct tamper_pin_cfg tamper_pin_list_active_config[] = {
263 {SC_P_CSI_D00, 0x1a000060}, /* Tamp_Out0 */ /* Sel tamper + OD */
264 {SC_P_CSI_D05, 0x1c000060}, /* Tamp_In0 */ /* Sel tamper + OD input */
267 #define TAMPER_PIN_LIST_CHOSEN tamper_pin_list_default_config
269 static struct tamper_pin_cfg *get_tamper_pin_cfg_list(u32 *size)
271 *size = sizeof(TAMPER_PIN_LIST_CHOSEN) /
272 sizeof(TAMPER_PIN_LIST_CHOSEN[0]);
274 return TAMPER_PIN_LIST_CHOSEN;
277 #define SC_CONF_OFFSET_OF(_field) \
278 (offsetof(struct snvs_security_sc_conf, _field))
280 static u32 ptr_value(u32 *_p)
282 return (_p) ? *_p : 0xdeadbeef;
285 static int check_write_secvio_config(u32 id, u32 *_p1, u32 *_p2,
286 u32 *_p3, u32 *_p4, u32 *_p5,
290 u32 d1 = ptr_value(_p1);
291 u32 d2 = ptr_value(_p2);
292 u32 d3 = ptr_value(_p3);
293 u32 d4 = ptr_value(_p4);
294 u32 d5 = ptr_value(_p5);
296 scierr = sc_seco_secvio_config(-1, id, SC_WRITE_CONF, &d1, &d2, &d3,
298 if (scierr != SC_ERR_NONE) {
299 printf("Failed to set secvio configuration\n");
300 debug("Failed to set conf id 0x%x with values ", id);
301 debug("0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x (cnt: %d)\n",
302 d1, d2, d3, d4, d5, _cnt);
321 #define SC_CHECK_WRITE1(id, _p1) \
322 check_write_secvio_config(id, _p1, NULL, NULL, NULL, NULL, 1)
324 static int apply_snvs_config(struct snvs_security_sc_conf *cnf)
328 debug("%s\n", __func__);
330 debug("Applying config:\n"
331 "\thp.lock = 0x%.8x\n"
332 "\thp.secvio_ctl = 0x%.8x\n"
333 "\tlp.lock = 0x%.8x\n"
334 "\tlp.secvio_ctl = 0x%.8x\n"
335 "\tlp.tamper_filt_cfg = 0x%.8x\n"
336 "\tlp.tamper_det_cfg = 0x%.8x\n"
337 "\tlp.tamper_det_cfg2 = 0x%.8x\n"
338 "\tlp.tamper_filt1_cfg = 0x%.8x\n"
339 "\tlp.tamper_filt2_cfg = 0x%.8x\n"
340 "\tlp.act_tamper1_cfg = 0x%.8x\n"
341 "\tlp.act_tamper2_cfg = 0x%.8x\n"
342 "\tlp.act_tamper3_cfg = 0x%.8x\n"
343 "\tlp.act_tamper4_cfg = 0x%.8x\n"
344 "\tlp.act_tamper5_cfg = 0x%.8x\n"
345 "\tlp.act_tamper_ctl = 0x%.8x\n"
346 "\tlp.act_tamper_clk_ctl = 0x%.8x\n"
347 "\tlp.act_tamper_routing_ctl1 = 0x%.8x\n"
348 "\tlp.act_tamper_routing_ctl2 = 0x%.8x\n",
353 cnf->lp.tamper_filt_cfg,
354 cnf->lp.tamper_det_cfg,
355 cnf->lp.tamper_det_cfg2,
356 cnf->lp.tamper_filt1_cfg,
357 cnf->lp.tamper_filt2_cfg,
358 cnf->lp.act_tamper1_cfg,
359 cnf->lp.act_tamper2_cfg,
360 cnf->lp.act_tamper3_cfg,
361 cnf->lp.act_tamper4_cfg,
362 cnf->lp.act_tamper5_cfg,
363 cnf->lp.act_tamper_ctl,
364 cnf->lp.act_tamper_clk_ctl,
365 cnf->lp.act_tamper_routing_ctl1,
366 cnf->lp.act_tamper_routing_ctl2);
368 scierr = check_write_secvio_config(SC_CONF_OFFSET_OF(lp.tamper_filt_cfg),
369 &cnf->lp.tamper_filt_cfg,
370 &cnf->lp.tamper_filt1_cfg,
371 &cnf->lp.tamper_filt2_cfg, NULL,
373 if (scierr != SC_ERR_NONE)
377 scierr = check_write_secvio_config(SC_CONF_OFFSET_OF(lp.act_tamper1_cfg),
378 &cnf->lp.act_tamper1_cfg,
379 &cnf->lp.act_tamper2_cfg,
380 &cnf->lp.act_tamper2_cfg,
381 &cnf->lp.act_tamper2_cfg,
382 &cnf->lp.act_tamper2_cfg, 5);
383 if (scierr != SC_ERR_NONE)
386 /* Configure AT routing */
387 scierr = check_write_secvio_config(SC_CONF_OFFSET_OF(lp.act_tamper_routing_ctl1),
388 &cnf->lp.act_tamper_routing_ctl1,
389 &cnf->lp.act_tamper_routing_ctl2,
390 NULL, NULL, NULL, 2);
391 if (scierr != SC_ERR_NONE)
394 /* Configure AT frequency */
395 scierr = SC_CHECK_WRITE1(SC_CONF_OFFSET_OF(lp.act_tamper_clk_ctl),
396 &cnf->lp.act_tamper_clk_ctl);
397 if (scierr != SC_ERR_NONE)
400 /* Activate the ATs */
401 scierr = SC_CHECK_WRITE1(SC_CONF_OFFSET_OF(lp.act_tamper_ctl),
402 &cnf->lp.act_tamper_ctl);
403 if (scierr != SC_ERR_NONE)
406 /* Activate the detectors */
407 scierr = check_write_secvio_config(SC_CONF_OFFSET_OF(lp.tamper_det_cfg),
408 &cnf->lp.tamper_det_cfg,
409 &cnf->lp.tamper_det_cfg2, NULL, NULL,
411 if (scierr != SC_ERR_NONE)
414 /* Configure LP secvio */
415 scierr = SC_CHECK_WRITE1(SC_CONF_OFFSET_OF(lp.secvio_ctl),
416 &cnf->lp.secvio_ctl);
417 if (scierr != SC_ERR_NONE)
420 /* Configure HP secvio */
421 scierr = SC_CHECK_WRITE1(SC_CONF_OFFSET_OF(hp.secvio_ctl),
422 &cnf->hp.secvio_ctl);
423 if (scierr != SC_ERR_NONE)
427 scierr = SC_CHECK_WRITE1(SC_CONF_OFFSET_OF(hp.lock), &cnf->hp.lock);
428 if (scierr != SC_ERR_NONE)
431 scierr = SC_CHECK_WRITE1(SC_CONF_OFFSET_OF(lp.lock), &cnf->lp.lock);
432 if (scierr != SC_ERR_NONE)
436 return (scierr == SC_ERR_NONE) ? 0 : -EIO;
439 static int dgo_write(u32 _id, u8 _access, u32 *_pdata)
441 int scierr = sc_seco_secvio_dgo_config(-1, _id, _access, _pdata);
443 if (scierr != SC_ERR_NONE) {
444 printf("Failed to set dgo configuration\n");
445 debug("Failed to set conf id 0x%x : 0x%.8x", _id, *_pdata);
451 static int apply_snvs_dgo_config(struct snvs_dgo_conf *cnf)
455 debug("%s\n", __func__);
457 debug("Applying config:\n"
458 "\ttamper_offset_ctl = 0x%.8x\n"
459 "\ttamper_pull_ctl = 0x%.8x\n"
460 "\ttamper_ana_test_ctl = 0x%.8x\n"
461 "\ttamper_sensor_trim_ctl = 0x%.8x\n"
462 "\ttamper_misc_ctl = 0x%.8x\n"
463 "\ttamper_core_volt_mon_ctl = 0x%.8x\n",
464 cnf->tamper_offset_ctl,
465 cnf->tamper_pull_ctl,
466 cnf->tamper_ana_test_ctl,
467 cnf->tamper_sensor_trim_ctl,
468 cnf->tamper_misc_ctl,
469 cnf->tamper_core_volt_mon_ctl);
471 dgo_write(0x04, 1, &cnf->tamper_offset_ctl);
472 if (scierr != SC_ERR_NONE)
475 dgo_write(0x14, 1, &cnf->tamper_pull_ctl);
476 if (scierr != SC_ERR_NONE)
479 dgo_write(0x24, 1, &cnf->tamper_ana_test_ctl);
480 if (scierr != SC_ERR_NONE)
483 dgo_write(0x34, 1, &cnf->tamper_sensor_trim_ctl);
484 if (scierr != SC_ERR_NONE)
487 dgo_write(0x54, 1, &cnf->tamper_core_volt_mon_ctl);
488 if (scierr != SC_ERR_NONE)
491 /* Last as it could lock the writes */
492 dgo_write(0x44, 1, &cnf->tamper_misc_ctl);
493 if (scierr != SC_ERR_NONE)
497 return (scierr == SC_ERR_NONE) ? 0 : -EIO;
500 static int pad_write(u32 _pad, u32 _value)
502 int scierr = sc_pad_set(-1, _pad, _value);
504 if (scierr != SC_ERR_NONE) {
505 printf("Failed to set pad configuration\n");
506 debug("Failed to set conf pad 0x%x : 0x%.8x", _pad, _value);
512 static int apply_tamper_pin_list_config(struct tamper_pin_cfg *confs, u32 size)
517 debug("%s\n", __func__);
519 for (idx = 0; idx < size; idx++) {
520 debug("\t idx %d: pad %d: 0x%.8x\n", idx, confs[idx].pad,
521 confs[idx].mux_conf);
522 pad_write(confs[idx].pad, 3 << 30 | confs[idx].mux_conf);
523 if (scierr != SC_ERR_NONE)
528 return (scierr == SC_ERR_NONE) ? 0 : -EIO;
534 struct snvs_security_sc_conf *snvs_conf;
535 struct snvs_dgo_conf *snvs_dgo_conf;
536 struct tamper_pin_cfg *tamper_pin_conf;
539 snvs_conf = get_snvs_config();
540 snvs_dgo_conf = get_snvs_dgo_config();
541 tamper_pin_conf = get_tamper_pin_cfg_list(&size);
544 snvs_conf = &snvs_default_config;
545 snvs_dgo_conf = &snvs_dgo_default_config;
546 tamper_pin_conf = tamper_pin_list_default_config;
548 /* Passive tamper expecting VCC on the line */
549 snvs_conf = &snvs_passive_vcc_config;
550 snvs_dgo_conf = &snvs_dgo_passive_vcc_config;
551 tamper_pin_conf = tamper_pin_list_passive_vcc_config;
553 /* Passive tamper expecting GND on the line */
554 snvs_conf = &snvs_passive_gnd_config;
555 snvs_dgo_conf = &snvs_dgo_passive_gnd_config;
556 tamper_pin_conf = tamper_pin_list_passive_gnd_config;
559 snvs_conf = &snvs_active_config;
560 snvs_dgo_conf = &snvs_dgo_active_config;
561 tamper_pin_conf = tamper_pin_list_active_config;
563 return !snvs_conf + !snvs_dgo_conf + !tamper_pin_conf;
566 #ifdef CONFIG_IMX_SNVS_SEC_SC_AUTO
567 int snvs_security_sc_init(void)
571 struct snvs_security_sc_conf *snvs_conf;
572 struct snvs_dgo_conf *snvs_dgo_conf;
573 struct tamper_pin_cfg *tamper_pin_conf;
576 debug("%s\n", __func__);
578 snvs_conf = get_snvs_config();
579 snvs_dgo_conf = get_snvs_dgo_config();
581 tamper_pin_conf = get_tamper_pin_cfg_list(&size);
583 err = apply_tamper_pin_list_config(tamper_pin_conf, size);
585 debug("Failed to set pins\n");
589 err = apply_snvs_dgo_config(snvs_dgo_conf);
591 debug("Failed to set dgo\n");
595 err = apply_snvs_config(snvs_conf);
597 debug("Failed to set snvs\n");
604 #endif /* CONFIG_IMX_SNVS_SEC_SC_AUTO */
606 static char snvs_cfg_help_text[] =
612 "\tlp.tamper_filt_cfg\n"
613 "\tlp.tamper_det_cfg\n"
614 "\tlp.tamper_det_cfg2\n"
615 "\tlp.tamper_filt1_cfg\n"
616 "\tlp.tamper_filt2_cfg\n"
617 "\tlp.act_tamper1_cfg\n"
618 "\tlp.act_tamper2_cfg\n"
619 "\tlp.act_tamper3_cfg\n"
620 "\tlp.act_tamper4_cfg\n"
621 "\tlp.act_tamper5_cfg\n"
622 "\tlp.act_tamper_ctl\n"
623 "\tlp.act_tamper_clk_ctl\n"
624 "\tlp.act_tamper_routing_ctl1\n"
625 "\tlp.act_tamper_routing_ctl2\n"
627 "ALL values should be in hexadecimal format";
629 #define NB_REGISTERS 18
630 static int do_snvs_cfg(struct cmd_tbl *cmdtp, int flag, int argc,
636 struct snvs_security_sc_conf conf = {0};
638 if (argc != (NB_REGISTERS + 1))
639 return CMD_RET_USAGE;
641 conf.hp.lock = simple_strtoul(argv[++idx], NULL, 16);
642 conf.hp.secvio_ctl = simple_strtoul(argv[++idx], NULL, 16);
643 conf.lp.lock = simple_strtoul(argv[++idx], NULL, 16);
644 conf.lp.secvio_ctl = simple_strtoul(argv[++idx], NULL, 16);
645 conf.lp.tamper_filt_cfg = simple_strtoul(argv[++idx], NULL, 16);
646 conf.lp.tamper_det_cfg = simple_strtoul(argv[++idx], NULL, 16);
647 conf.lp.tamper_det_cfg2 = simple_strtoul(argv[++idx], NULL, 16);
648 conf.lp.tamper_filt1_cfg = simple_strtoul(argv[++idx], NULL, 16);
649 conf.lp.tamper_filt2_cfg = simple_strtoul(argv[++idx], NULL, 16);
650 conf.lp.act_tamper1_cfg = simple_strtoul(argv[++idx], NULL, 16);
651 conf.lp.act_tamper2_cfg = simple_strtoul(argv[++idx], NULL, 16);
652 conf.lp.act_tamper3_cfg = simple_strtoul(argv[++idx], NULL, 16);
653 conf.lp.act_tamper4_cfg = simple_strtoul(argv[++idx], NULL, 16);
654 conf.lp.act_tamper5_cfg = simple_strtoul(argv[++idx], NULL, 16);
655 conf.lp.act_tamper_ctl = simple_strtoul(argv[++idx], NULL, 16);
656 conf.lp.act_tamper_clk_ctl = simple_strtoul(argv[++idx], NULL, 16);
657 conf.lp.act_tamper_routing_ctl1 = simple_strtoul(argv[++idx], NULL, 16);
658 conf.lp.act_tamper_routing_ctl2 = simple_strtoul(argv[++idx], NULL, 16);
660 err = apply_snvs_config(&conf);
666 NB_REGISTERS + 1, 1, do_snvs_cfg,
667 "Security violation configuration",
671 static char snvs_dgo_cfg_help_text[] =
673 "\ttamper_offset_ctl\n"
674 "\ttamper_pull_ctl\n"
675 "\ttamper_ana_test_ctl\n"
676 "\ttamper_sensor_trim_ctl\n"
677 "\ttamper_misc_ctl\n"
678 "\ttamper_core_volt_mon_ctl\n"
680 "ALL values should be in hexadecimal format";
682 static int do_snvs_dgo_cfg(struct cmd_tbl *cmdtp, int flag, int argc,
688 struct snvs_dgo_conf conf = {0};
691 return CMD_RET_USAGE;
693 conf.tamper_offset_ctl = simple_strtoul(argv[++idx], NULL, 16);
694 conf.tamper_pull_ctl = simple_strtoul(argv[++idx], NULL, 16);
695 conf.tamper_ana_test_ctl = simple_strtoul(argv[++idx], NULL, 16);
696 conf.tamper_sensor_trim_ctl = simple_strtoul(argv[++idx], NULL, 16);
697 conf.tamper_misc_ctl = simple_strtoul(argv[++idx], NULL, 16);
698 conf.tamper_core_volt_mon_ctl = simple_strtoul(argv[++idx], NULL, 16);
700 err = apply_snvs_dgo_config(&conf);
705 U_BOOT_CMD(snvs_dgo_cfg,
706 7, 1, do_snvs_dgo_cfg,
707 "SNVS DGO configuration",
708 snvs_dgo_cfg_help_text
711 static char tamper_pin_cfg_help_text[] =
716 "ALL values should be in hexadecimal format";
718 static int do_tamper_pin_cfg(struct cmd_tbl *cmdtp, int flag, int argc,
724 struct tamper_pin_cfg conf = {0};
727 return CMD_RET_USAGE;
729 conf.pad = simple_strtoul(argv[++idx], NULL, 10);
730 conf.mux_conf = simple_strtoul(argv[++idx], NULL, 16);
732 err = apply_tamper_pin_list_config(&conf, 1);
737 U_BOOT_CMD(tamper_pin_cfg,
738 3, 1, do_tamper_pin_cfg,
739 "tamper pin configuration",
740 tamper_pin_cfg_help_text
743 static char snvs_clear_status_help_text[] =
744 "snvs_clear_status\n"
750 "Write the status registers with the value provided,"
751 " clearing the status";
753 static int do_snvs_clear_status(struct cmd_tbl *cmdtp, int flag, int argc,
759 struct snvs_security_sc_conf conf = {0};
762 return CMD_RET_USAGE;
764 conf.lp.status = simple_strtoul(argv[++idx], NULL, 16);
765 conf.lp.tamper_det_status = simple_strtoul(argv[++idx], NULL, 16);
767 scierr = check_write_secvio_config(SC_CONF_OFFSET_OF(lp.status),
768 &conf.lp.status, NULL, NULL, NULL,
770 if (scierr != SC_ERR_NONE)
773 scierr = check_write_secvio_config(SC_CONF_OFFSET_OF(lp.tamper_det_status),
774 &conf.lp.tamper_det_status, NULL,
775 NULL, NULL, NULL, 1);
776 if (scierr != SC_ERR_NONE)
780 return (scierr == SC_ERR_NONE) ? 0 : 1;
783 U_BOOT_CMD(snvs_clear_status,
784 3, 1, do_snvs_clear_status,
786 snvs_clear_status_help_text
789 static char snvs_sec_status_help_text[] =
791 "Display information about the security related to tamper and secvio";
793 static int do_snvs_sec_status(struct cmd_tbl *cmdtp, int flag, int argc,
832 /* Security violation */
837 /* Temper detectors */
864 for (idx = 0; idx < ARRAY_SIZE(pads); idx++) {
865 u8 pad_id = pads[idx];
867 scierr = sc_pad_get(-1, pad_id, &data[0]);
869 printf("\t- Pin %d: %.8x\n", pad_id, data[0]);
871 printf("Failed to read Pin %d\n", pad_id);
876 for (idx = 0; idx < ARRAY_SIZE(fuses); idx++) {
877 u32 fuse_id = fuses[idx];
879 scierr = sc_misc_otp_fuse_read(-1, fuse_id, &data[0]);
881 printf("\t- Fuse %d: %.8x\n", fuse_id, data[0]);
883 printf("Failed to read Fuse %d\n", fuse_id);
888 for (idx = 0; idx < ARRAY_SIZE(snvs); idx++) {
889 struct snvs_reg *reg = &snvs[idx];
891 scierr = sc_seco_secvio_config(-1, reg->id, 0, &data[0],
892 &data[1], &data[2], &data[3],
897 printf("\t- SNVS %.2x(%d):", reg->id, reg->nb);
898 for (subidx = 0; subidx < reg->nb; subidx++)
899 printf(" %.8x", data[subidx]);
902 printf("Failed to read SNVS %d\n", reg->id);
908 for (idx = 0; idx < ARRAY_SIZE(dgo); idx++) {
909 u8 dgo_id = dgo[idx];
911 scierr = sc_seco_secvio_dgo_config(-1, dgo_id, 0, &data[0]);
913 printf("\t- DGO %.2x: %.8x\n", dgo_id, data[0]);
915 printf("Failed to read DGO %d\n", dgo_id);
921 U_BOOT_CMD(snvs_sec_status,
922 1, 1, do_snvs_sec_status,
923 "tamper pin configuration",
924 snvs_sec_status_help_text