xref: /rk3399_rockchip-uboot/cmd/rk_secure_storage.c (revision 2b4182c1edaf1bfb2e4b0fb60381ba7dbb2e6a60)
1*2b4182c1SJason Zhu // SPDX-License-Identifier: GPL-2.0
2*2b4182c1SJason Zhu /*
3*2b4182c1SJason Zhu  * Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd
4*2b4182c1SJason Zhu  */
5*2b4182c1SJason Zhu 
6*2b4182c1SJason Zhu #include <common.h>
7*2b4182c1SJason Zhu #include <command.h>
8*2b4182c1SJason Zhu #include <dm.h>
9*2b4182c1SJason Zhu #include <misc.h>
10*2b4182c1SJason Zhu 
11*2b4182c1SJason Zhu #ifdef CONFIG_ROCKCHIP_OTP
dump_otps(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])12*2b4182c1SJason Zhu static int dump_otps(cmd_tbl_t *cmdtp, int flag,
13*2b4182c1SJason Zhu 		     int argc, char * const argv[])
14*2b4182c1SJason Zhu {
15*2b4182c1SJason Zhu 	struct udevice *dev;
16*2b4182c1SJason Zhu 	u8 otps[64] = {0};
17*2b4182c1SJason Zhu 	int ret;
18*2b4182c1SJason Zhu 
19*2b4182c1SJason Zhu 	/* retrieve the device */
20*2b4182c1SJason Zhu 	ret = uclass_get_device_by_driver(UCLASS_MISC,
21*2b4182c1SJason Zhu 					  DM_GET_DRIVER(rockchip_otp), &dev);
22*2b4182c1SJason Zhu 	if (ret) {
23*2b4182c1SJason Zhu 		printf("%s: no misc-device found\n", __func__);
24*2b4182c1SJason Zhu 		return 0;
25*2b4182c1SJason Zhu 	}
26*2b4182c1SJason Zhu 
27*2b4182c1SJason Zhu 	ret = misc_read(dev, 0, &otps, sizeof(otps));
28*2b4182c1SJason Zhu 	if (ret) {
29*2b4182c1SJason Zhu 		printf("%s: misc_read failed\n", __func__);
30*2b4182c1SJason Zhu 		return 0;
31*2b4182c1SJason Zhu 	}
32*2b4182c1SJason Zhu 
33*2b4182c1SJason Zhu 	printf("otp-contents:\n");
34*2b4182c1SJason Zhu 	print_buffer(0, otps, 1, 64, 16);
35*2b4182c1SJason Zhu 
36*2b4182c1SJason Zhu 	return 0;
37*2b4182c1SJason Zhu }
38*2b4182c1SJason Zhu 
39*2b4182c1SJason Zhu U_BOOT_CMD(
40*2b4182c1SJason Zhu 	rockchip_dump_otps, 1, 1, dump_otps,
41*2b4182c1SJason Zhu 	"Dump the content of the otps",
42*2b4182c1SJason Zhu 	""
43*2b4182c1SJason Zhu );
44*2b4182c1SJason Zhu #endif
45*2b4182c1SJason Zhu 
46*2b4182c1SJason Zhu #ifdef CONFIG_ROCKCHIP_EFUSE
dump_efuses(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])47*2b4182c1SJason Zhu static int dump_efuses(cmd_tbl_t *cmdtp, int flag,
48*2b4182c1SJason Zhu 		       int argc, char * const argv[])
49*2b4182c1SJason Zhu {
50*2b4182c1SJason Zhu 	/*
51*2b4182c1SJason Zhu 	 * N.B.: This function is tailored towards the RK3399 and assumes that
52*2b4182c1SJason Zhu 	 *       there's always 32 fuses x 32 bits (i.e. 128 bytes of data) to
53*2b4182c1SJason Zhu 	 *       be read.
54*2b4182c1SJason Zhu 	 */
55*2b4182c1SJason Zhu 
56*2b4182c1SJason Zhu 	struct udevice *dev;
57*2b4182c1SJason Zhu 	u8 fuses[128] = {0};
58*2b4182c1SJason Zhu 	int ret;
59*2b4182c1SJason Zhu 
60*2b4182c1SJason Zhu 	/* retrieve the device */
61*2b4182c1SJason Zhu 	ret = uclass_get_device_by_driver(UCLASS_MISC,
62*2b4182c1SJason Zhu 					  DM_GET_DRIVER(rockchip_efuse), &dev);
63*2b4182c1SJason Zhu 	if (ret) {
64*2b4182c1SJason Zhu 		printf("%s: no misc-device found\n", __func__);
65*2b4182c1SJason Zhu 		return 0;
66*2b4182c1SJason Zhu 	}
67*2b4182c1SJason Zhu 
68*2b4182c1SJason Zhu 	ret = misc_read(dev, 0, &fuses, sizeof(fuses));
69*2b4182c1SJason Zhu 	if (ret) {
70*2b4182c1SJason Zhu 		printf("%s: misc_read failed\n", __func__);
71*2b4182c1SJason Zhu 		return 0;
72*2b4182c1SJason Zhu 	}
73*2b4182c1SJason Zhu 
74*2b4182c1SJason Zhu 	printf("efuse-contents:\n");
75*2b4182c1SJason Zhu 	print_buffer(0, fuses, 1, 128, 16);
76*2b4182c1SJason Zhu 
77*2b4182c1SJason Zhu 	return 0;
78*2b4182c1SJason Zhu }
79*2b4182c1SJason Zhu 
80*2b4182c1SJason Zhu U_BOOT_CMD(
81*2b4182c1SJason Zhu 	rockchip_dump_efuses, 1, 1, dump_efuses,
82*2b4182c1SJason Zhu 	"Dump the content of the efuses",
83*2b4182c1SJason Zhu 	""
84*2b4182c1SJason Zhu );
85*2b4182c1SJason Zhu #endif
86