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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2016 Toradex, Inc.
*/
#include <common.h>
#include <env.h>
#include <g_dnl.h>
#include <init.h>
#include <linux/libfdt.h>
#ifdef CONFIG_VIDEO
#include <bmp_logo.h>
#include <dm.h>
#include <splash.h>
#include <video.h>
#endif
#include "tdx-cfg-block.h"
#include <asm/setup.h>
#include "tdx-common.h"
#define SERIAL_STR_LEN 8
#define MODULE_VER_STR_LEN 4 // V1.1
#define MODULE_REV_STR_LEN 3 // [A-Z] or #[26-99]
#ifdef CONFIG_TDX_CFG_BLOCK
static char tdx_serial_str[SERIAL_STR_LEN + 1];
static char tdx_board_rev_str[MODULE_VER_STR_LEN + MODULE_REV_STR_LEN + 1];
#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
static char tdx_car_serial_str[SERIAL_STR_LEN + 1];
static char tdx_car_rev_str[MODULE_VER_STR_LEN + MODULE_REV_STR_LEN + 1];
static const char *tdx_carrier_board_name;
#endif
#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
u32 get_board_revision(void)
{
/* Check validity */
if (!tdx_hw_tag.ver_major)
return 0;
return ((tdx_hw_tag.ver_major & 0xff) << 8) |
((tdx_hw_tag.ver_minor & 0xf) << 4) |
((tdx_hw_tag.ver_assembly & 0xf) + 0xa);
}
#endif /* CONFIG_TDX_CFG_BLOCK */
#ifdef CONFIG_SERIAL_TAG
void get_board_serial(struct tag_serialnr *serialnr)
{
int array[8];
unsigned int serial = tdx_serial;
int i;
serialnr->low = 0;
serialnr->high = 0;
/* Check validity */
if (serial) {
/*
* Convert to Linux serial number format (hexadecimal coded
* decimal)
*/
i = 7;
while (serial) {
array[i--] = serial % 10;
serial /= 10;
}
while (i >= 0)
array[i--] = 0;
serial = array[0];
for (i = 1; i < 8; i++) {
serial *= 16;
serial += array[i];
}
serialnr->low = serial;
}
}
#endif /* CONFIG_SERIAL_TAG */
static const char *get_board_assembly(u16 ver_assembly)
{
static char ver_name[MODULE_REV_STR_LEN + 1];
if (ver_assembly < 26) {
ver_name[0] = (char)ver_assembly + 'A';
ver_name[1] = '\0';
} else {
snprintf(ver_name, sizeof(ver_name),
"#%u", ver_assembly);
}
return ver_name;
}
__weak int print_bootinfo(void)
{
return 0;
}
int checkboard(void)
{
if (valid_cfgblock) {
printf("Model: Toradex %04d %s %s\n",
tdx_hw_tag.prodid,
toradex_modules[tdx_hw_tag.prodid].name,
tdx_board_rev_str);
printf("Serial#: %s\n", tdx_serial_str);
}
#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
if (tdx_carrier_board_name)
printf("Carrier: Toradex %s %s, Serial# %s\n",
tdx_carrier_board_name,
tdx_car_rev_str,
tdx_car_serial_str);
#endif
print_bootinfo();
return 0;
}
static int settings_r(void)
{
unsigned char ethaddr[6];
if (read_tdx_cfg_block()) {
printf("MISSING TORADEX CONFIG BLOCK\n");
get_mac_from_serial(tdx_serial, &tdx_eth_addr);
/* Board can run even if config block is not present */
return 0;
}
snprintf(tdx_serial_str, sizeof(tdx_serial_str),
"%08u", tdx_serial);
snprintf(tdx_board_rev_str, sizeof(tdx_board_rev_str),
"V%1d.%1d%s",
tdx_hw_tag.ver_major,
tdx_hw_tag.ver_minor,
get_board_assembly(tdx_hw_tag.ver_assembly));
env_set("serial#", tdx_serial_str);
#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
if (read_tdx_cfg_block_carrier()) {
printf("MISSING TORADEX CARRIER CONFIG BLOCKS\n");
try_migrate_tdx_cfg_block_carrier();
} else {
tdx_carrier_board_name =
get_toradex_carrier_boards(tdx_car_hw_tag.prodid);
snprintf(tdx_car_serial_str, sizeof(tdx_car_serial_str),
"%08u", tdx_car_serial);
snprintf(tdx_car_rev_str, sizeof(tdx_car_rev_str),
"V%1d.%1d%s",
tdx_car_hw_tag.ver_major,
tdx_car_hw_tag.ver_minor,
get_board_assembly(tdx_car_hw_tag.ver_assembly));
env_set("carrier_serial#", tdx_car_serial_str);
}
#endif
/*
* Check if environment contains a valid MAC address,
* set the one from config block if not
*/
if (!eth_env_get_enetaddr("ethaddr", ethaddr))
eth_env_set_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);
if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR) &&
!eth_env_get_enetaddr("eth1addr", ethaddr)) {
/*
* Secondary MAC address is allocated from block
* 0x100000 higher then the first MAC address
*/
memcpy(ethaddr, &tdx_eth_addr, 6);
ethaddr[3] += 0x10;
eth_env_set_enetaddr("eth1addr", ethaddr);
}
return 0;
}
EVENT_SPY_SIMPLE(EVT_SETTINGS_R, settings_r);
#ifdef CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID
int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
{
unsigned short usb_pid;
usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid;
put_unaligned(usb_pid, &dev->idProduct);
return 0;
}
#endif
#if defined(CONFIG_OF_LIBFDT)
int ft_common_board_setup(void *blob, struct bd_info *bd)
{
if (tdx_serial) {
fdt_setprop(blob, 0, "serial-number", tdx_serial_str,
strlen(tdx_serial_str) + 1);
}
if (tdx_hw_tag.ver_major) {
char prod_id[5];
snprintf(prod_id, sizeof(prod_id), "%04u", tdx_hw_tag.prodid);
fdt_setprop(blob, 0, "toradex,product-id", prod_id, 5);
fdt_setprop(blob, 0, "toradex,board-rev", tdx_board_rev_str,
strlen(tdx_board_rev_str) + 1);
}
return 0;
}
#endif
#else /* CONFIG_TDX_CFG_BLOCK */
#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
u32 get_board_revision(void)
{
return 0;
}
#endif /* CONFIG_REVISION_TAG */
#ifdef CONFIG_SERIAL_TAG
u32 get_board_serial(void)
{
return 0;
}
#endif /* CONFIG_SERIAL_TAG */
int ft_common_board_setup(void *blob, struct bd_info *bd)
{
return 0;
}
#endif /* CONFIG_TDX_CFG_BLOCK */
|