huangcm
2025-04-07 511b111543524704f6182b374e489f5d0e51db8c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * (C) Copyright 2018 allwinnertech  <wangwei@allwinnertech.com>
 *
 * SPDX-License-Identifier:    GPL-2.0+
 */
 
#include <common.h>
#include <console.h>
#include <command.h>
#include <securestorage.h>
#include <sunxi_board.h>
 
extern int sunxi_usb_dev_register(uint dev_name);
extern  void sunxi_usb_main_loop(int delaytime);
extern  int sunxi_usb_extern_loop(void);
extern  int sunxi_usb_init(int delaytime);
extern  int sunxi_usb_exit(void);
 
DECLARE_GLOBAL_DATA_PTR;
 
extern volatile int sunxi_usb_burn_from_boot_handshake, sunxi_usb_burn_from_boot_init, sunxi_usb_burn_from_boot_setup;
 
 
int do_burn_from_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
   int    ret;
   ulong begin_time= 0, over_time = 0;
 
   pr_force("usb burn from boot\n");
   if(sunxi_usb_dev_register(4) < 0)
   {
       pr_err("usb burn fail: not support burn private data\n");
       return -1;
   }
 
   if(sunxi_usb_init(0))
   {
       pr_err("%s usb init fail\n", __func__);
       sunxi_usb_exit();
       return 0;
   }
 
   tick_printf("usb prepare ok\n");
   begin_time = get_timer(0);
   over_time = 800; /* 800ms */
   while(1)
   {
       if(sunxi_usb_burn_from_boot_init)
       {
           pr_force("usb sof ok\n");
           break;
       }
       if(get_timer(begin_time) > over_time)
       {
           tick_printf("overtime\n");
           sunxi_usb_exit();
           tick_printf("%s usb : no usb exist\n", __func__);
 
           return 0;
       }
   }
   tick_printf("usb probe ok\n");
   tick_printf("usb setup ok\n");
 
   begin_time = get_timer(0);
   over_time = 3000; /* 3000ms */
   while(1)
   {
       ret = sunxi_usb_extern_loop();
       if(ret)
       {
           break;
       }
       if(!sunxi_usb_burn_from_boot_handshake)
       {
           if(get_timer(begin_time) > over_time)
           {
               sunxi_usb_exit();
               tick_printf("%s usb : have no handshake\n", __func__);
               return 0;
           }
       }
       if(ctrlc())
       {
           ret = SUNXI_UPDATE_NEXT_ACTION_NORMAL;
           break;
       }
   }
   tick_printf("exit usb burn from boot\n");
   sunxi_usb_exit();
   sunxi_update_subsequent_processing(ret);
 
   return 0;
}
 
 
U_BOOT_CMD(
   uburn, CONFIG_SYS_MAXARGS, 1, do_burn_from_boot,
   "do a burn from boot",
   "pburn [mode]"
   "NULL"
);
 
 
/*
************************************************************************************************************
*
*                                             function
*
*    name          :
*
*    parmeters     :
*
*    return        :
*
*    note          :
*
*
************************************************************************************************************
*/
int do_read_from_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
#ifdef CONFIG_SUNXI_SECURE_STORAGE
   if(argc == 1)
   {
       return sunxi_secure_storage_list();
   }
   if(argc == 2)
   {
       char buffer[4096];
       int ret, data_len;
 
       memset(buffer, 0, 4096);
       ret = sunxi_secure_storage_init();
       if(ret < 0)
       {
           pr_err("%s secure storage init err\n", __func__);
 
           return -1;
       }
       ret = sunxi_secure_object_read(argv[1], buffer, 4096, &data_len);
       if(ret < 0)
       {
           pr_err("private data %s is not exist\n", argv[1]);
 
           return -1;
       }
       pr_force("private data:\n");
       sunxi_dump(buffer, strlen((const char *)buffer));
 
       return 0;
   }
#endif
   return -1;
}
 
U_BOOT_CMD(
   pbread, CONFIG_SYS_MAXARGS, 1, do_read_from_boot,
   "read data from private data",
   "pread [name]"
   "NULL"
);