]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
095aea29 A |
2 | /* |
3 | * Copyright 2011 Linaro Limited | |
4 | * Aneesh V <aneesh@ti.com> | |
095aea29 A |
5 | */ |
6 | #include <common.h> | |
9925f1db | 7 | #include <environment.h> |
5d982856 | 8 | #include <asm/setup.h> |
8a0c6d6f | 9 | #include <asm/arch/sys_proto.h> |
7a390c0e SP |
10 | #include <asm/omap_common.h> |
11 | ||
095aea29 A |
12 | static void do_cancel_out(u32 *num, u32 *den, u32 factor) |
13 | { | |
14 | while (1) { | |
15 | if (((*num)/factor*factor == (*num)) && | |
16 | ((*den)/factor*factor == (*den))) { | |
17 | (*num) /= factor; | |
18 | (*den) /= factor; | |
19 | } else | |
20 | break; | |
21 | } | |
22 | } | |
23 | ||
fa24eca1 SP |
24 | #ifdef CONFIG_FASTBOOT_FLASH |
25 | static void omap_set_fastboot_cpu(void) | |
26 | { | |
27 | char *cpu; | |
28 | u32 cpu_rev = omap_revision(); | |
29 | ||
30 | switch (cpu_rev) { | |
9b46ce8c | 31 | case DRA762_ES1_0: |
cd30f3fc PB |
32 | case DRA762_ABZ_ES1_0: |
33 | case DRA762_ACD_ES1_0: | |
9b46ce8c PB |
34 | cpu = "DRA762"; |
35 | break; | |
fa24eca1 SP |
36 | case DRA752_ES1_0: |
37 | case DRA752_ES1_1: | |
38 | case DRA752_ES2_0: | |
39 | cpu = "DRA752"; | |
40 | break; | |
41 | case DRA722_ES1_0: | |
42 | case DRA722_ES2_0: | |
b6df9359 | 43 | case DRA722_ES2_1: |
fa24eca1 SP |
44 | cpu = "DRA722"; |
45 | break; | |
46 | default: | |
47 | cpu = NULL; | |
48 | printf("Warning: fastboot.cpu: unknown CPU rev: %u\n", cpu_rev); | |
49 | } | |
50 | ||
382bee57 | 51 | env_set("fastboot.cpu", cpu); |
fa24eca1 SP |
52 | } |
53 | ||
54 | static void omap_set_fastboot_secure(void) | |
55 | { | |
56 | const char *secure; | |
57 | u32 dev = get_device_type(); | |
58 | ||
59 | switch (dev) { | |
60 | case EMU_DEVICE: | |
61 | secure = "EMU"; | |
62 | break; | |
63 | case HS_DEVICE: | |
64 | secure = "HS"; | |
65 | break; | |
66 | case GP_DEVICE: | |
67 | secure = "GP"; | |
68 | break; | |
69 | default: | |
70 | secure = NULL; | |
71 | printf("Warning: fastboot.secure: unknown CPU sec: %u\n", dev); | |
72 | } | |
73 | ||
382bee57 | 74 | env_set("fastboot.secure", secure); |
fa24eca1 SP |
75 | } |
76 | ||
77 | static void omap_set_fastboot_board_rev(void) | |
78 | { | |
79 | const char *board_rev; | |
80 | ||
00caae6d | 81 | board_rev = env_get("board_rev"); |
fa24eca1 SP |
82 | if (board_rev == NULL) |
83 | printf("Warning: fastboot.board_rev: unknown board revision\n"); | |
84 | ||
382bee57 | 85 | env_set("fastboot.board_rev", board_rev); |
fa24eca1 SP |
86 | } |
87 | ||
42d8dd44 | 88 | #ifdef CONFIG_FASTBOOT_FLASH_MMC |
fa24eca1 SP |
89 | static u32 omap_mmc_get_part_size(const char *part) |
90 | { | |
91 | int res; | |
92 | struct blk_desc *dev_desc; | |
93 | disk_partition_t info; | |
94 | u64 sz = 0; | |
95 | ||
96 | dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); | |
97 | if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { | |
9b643e31 | 98 | pr_err("invalid mmc device\n"); |
fa24eca1 SP |
99 | return 0; |
100 | } | |
101 | ||
26857766 SP |
102 | /* Check only for EFI (GPT) partition table */ |
103 | res = part_get_info_by_name_type(dev_desc, part, &info, PART_TYPE_EFI); | |
19d141a0 | 104 | if (res < 0) |
fa24eca1 | 105 | return 0; |
fa24eca1 SP |
106 | |
107 | /* Calculate size in bytes */ | |
108 | sz = (info.size * (u64)info.blksz); | |
109 | /* to KiB */ | |
110 | sz >>= 10; | |
111 | ||
112 | return (u32)sz; | |
113 | } | |
114 | ||
115 | static void omap_set_fastboot_userdata_size(void) | |
116 | { | |
117 | char buf[16]; | |
118 | u32 sz_kb; | |
119 | ||
120 | sz_kb = omap_mmc_get_part_size("userdata"); | |
19d141a0 SP |
121 | if (sz_kb == 0) |
122 | return; /* probably it's not Android partition table */ | |
fa24eca1 | 123 | |
19d141a0 | 124 | sprintf(buf, "%u", sz_kb); |
382bee57 | 125 | env_set("fastboot.userdata_size", buf); |
fa24eca1 SP |
126 | } |
127 | #else | |
128 | static inline void omap_set_fastboot_userdata_size(void) | |
129 | { | |
130 | } | |
42d8dd44 | 131 | #endif /* CONFIG_FASTBOOT_FLASH_MMC */ |
4347b0b0 SP |
132 | |
133 | static void omap_set_fastboot_product(void) | |
134 | { | |
135 | const char *board_name; | |
136 | ||
137 | board_name = env_get("board_name"); | |
138 | if (board_name == NULL) | |
139 | printf("Warning: fastboot.product: unknown board\n"); | |
140 | ||
141 | env_set("fastboot.product", board_name); | |
142 | } | |
143 | ||
fa24eca1 SP |
144 | void omap_set_fastboot_vars(void) |
145 | { | |
146 | omap_set_fastboot_cpu(); | |
147 | omap_set_fastboot_secure(); | |
148 | omap_set_fastboot_board_rev(); | |
149 | omap_set_fastboot_userdata_size(); | |
4347b0b0 | 150 | omap_set_fastboot_product(); |
fa24eca1 SP |
151 | } |
152 | #endif /* CONFIG_FASTBOOT_FLASH */ | |
153 | ||
095aea29 A |
154 | /* |
155 | * Cancel out the denominator and numerator of a fraction | |
156 | * to get smaller numerator and denominator. | |
157 | */ | |
158 | void cancel_out(u32 *num, u32 *den, u32 den_limit) | |
159 | { | |
160 | do_cancel_out(num, den, 2); | |
161 | do_cancel_out(num, den, 3); | |
162 | do_cancel_out(num, den, 5); | |
163 | do_cancel_out(num, den, 7); | |
164 | do_cancel_out(num, den, 11); | |
165 | do_cancel_out(num, den, 13); | |
166 | do_cancel_out(num, den, 17); | |
167 | while ((*den) > den_limit) { | |
168 | *num /= 2; | |
169 | /* | |
170 | * Round up the denominator so that the final fraction | |
171 | * (num/den) is always <= the desired value | |
172 | */ | |
173 | *den = (*den + 1) / 2; | |
174 | } | |
175 | } | |
8a0c6d6f | 176 | |
72931b15 PK |
177 | __weak void omap_die_id(unsigned int *die_id) |
178 | { | |
179 | die_id[0] = die_id[1] = die_id[2] = die_id[3] = 0; | |
180 | } | |
181 | ||
07815eb9 | 182 | void omap_die_id_serial(void) |
8a0c6d6f | 183 | { |
07815eb9 PK |
184 | unsigned int die_id[4] = { 0 }; |
185 | char serial_string[17] = { 0 }; | |
8a0c6d6f | 186 | |
07815eb9 | 187 | omap_die_id((unsigned int *)&die_id); |
8a0c6d6f | 188 | |
00caae6d | 189 | if (!env_get("serial#")) { |
07815eb9 PK |
190 | snprintf(serial_string, sizeof(serial_string), |
191 | "%08x%08x", die_id[0], die_id[3]); | |
192 | ||
382bee57 | 193 | env_set("serial#", serial_string); |
8a0c6d6f NM |
194 | } |
195 | } | |
f12467d1 | 196 | |
2da87ab3 PK |
197 | void omap_die_id_get_board_serial(struct tag_serialnr *serialnr) |
198 | { | |
199 | char *serial_string; | |
200 | unsigned long long serial; | |
201 | ||
00caae6d | 202 | serial_string = env_get("serial#"); |
2da87ab3 PK |
203 | |
204 | if (serial_string) { | |
205 | serial = simple_strtoull(serial_string, NULL, 16); | |
206 | ||
207 | serialnr->high = (unsigned int) (serial >> 32); | |
208 | serialnr->low = (unsigned int) (serial & 0xffffffff); | |
209 | } else { | |
210 | serialnr->high = 0; | |
211 | serialnr->low = 0; | |
212 | } | |
213 | } | |
214 | ||
07815eb9 | 215 | void omap_die_id_usbethaddr(void) |
f12467d1 | 216 | { |
07815eb9 PK |
217 | unsigned int die_id[4] = { 0 }; |
218 | unsigned char mac[6] = { 0 }; | |
f12467d1 | 219 | |
07815eb9 PK |
220 | omap_die_id((unsigned int *)&die_id); |
221 | ||
00caae6d | 222 | if (!env_get("usbethaddr")) { |
07815eb9 PK |
223 | /* |
224 | * Create a fake MAC address from the processor ID code. | |
225 | * First byte is 0x02 to signify locally administered. | |
226 | */ | |
227 | mac[0] = 0x02; | |
228 | mac[1] = die_id[3] & 0xff; | |
229 | mac[2] = die_id[2] & 0xff; | |
230 | mac[3] = die_id[1] & 0xff; | |
231 | mac[4] = die_id[0] & 0xff; | |
232 | mac[5] = (die_id[0] >> 8) & 0xff; | |
233 | ||
fd1e959e | 234 | eth_env_set_enetaddr("usbethaddr", mac); |
b59670f2 PR |
235 | |
236 | if (!env_get("ethaddr")) | |
237 | eth_env_set_enetaddr("ethaddr", mac); | |
f12467d1 DK |
238 | } |
239 | } | |
679f82c3 PK |
240 | |
241 | void omap_die_id_display(void) | |
242 | { | |
243 | unsigned int die_id[4] = { 0 }; | |
244 | ||
245 | omap_die_id(die_id); | |
246 | ||
e22455f0 LM |
247 | printf("OMAP die ID: %08x%08x%08x%08x\n", die_id[3], die_id[2], |
248 | die_id[1], die_id[0]); | |
679f82c3 | 249 | } |