Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * Read FactorySet information from EEPROM into global structure. |
| 5 | * (C) Copyright 2013 Siemens Schweiz AG |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #if !defined(CONFIG_SPL_BUILD) |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Anatolij Gustschin | d0d75f5 | 2019-07-10 19:44:15 +0200 | [diff] [blame] | 12 | #include <dm.h> |
Tom Rini | fb76807 | 2019-08-12 18:47:53 -0400 | [diff] [blame] | 13 | #include <env_internal.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 14 | #include <i2c.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/cpu.h> |
| 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <asm/unaligned.h> |
| 19 | #include <net.h> |
Samuel Egli | 8069bfe | 2013-11-04 14:05:03 +0100 | [diff] [blame] | 20 | #include <errno.h> |
| 21 | #include <g_dnl.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 22 | #include "factoryset.h" |
| 23 | |
| 24 | #define EEPR_PG_SZ 0x80 |
| 25 | #define EEPROM_FATORYSET_OFFSET 0x400 |
| 26 | #define OFF_PG EEPROM_FATORYSET_OFFSET/EEPR_PG_SZ |
| 27 | |
| 28 | /* Global variable that contains necessary information from FactorySet */ |
| 29 | struct factorysetcontainer factory_dat; |
| 30 | |
| 31 | #define fact_get_char(i) *((char *)&eeprom_buf[i]) |
| 32 | |
| 33 | static int fact_match(unsigned char *eeprom_buf, uchar *s1, int i2) |
| 34 | { |
| 35 | if (s1 == NULL) |
| 36 | return -1; |
| 37 | |
| 38 | while (*s1 == fact_get_char(i2++)) |
| 39 | if (*s1++ == '=') |
| 40 | return i2; |
| 41 | |
| 42 | if (*s1 == '\0' && fact_get_char(i2-1) == '=') |
| 43 | return i2; |
| 44 | |
| 45 | return -1; |
| 46 | } |
| 47 | |
| 48 | static int get_factory_val(unsigned char *eeprom_buf, int size, uchar *name, |
| 49 | uchar *buf, int len) |
| 50 | { |
| 51 | int i, nxt = 0; |
| 52 | |
| 53 | for (i = 0; fact_get_char(i) != '\0'; i = nxt + 1) { |
| 54 | int val, n; |
| 55 | |
| 56 | for (nxt = i; fact_get_char(nxt) != '\0'; ++nxt) { |
| 57 | if (nxt >= size) |
| 58 | return -1; |
| 59 | } |
| 60 | |
| 61 | val = fact_match(eeprom_buf, (uchar *)name, i); |
| 62 | if (val < 0) |
| 63 | continue; |
| 64 | |
| 65 | /* found; copy out */ |
| 66 | for (n = 0; n < len; ++n, ++buf) { |
| 67 | *buf = fact_get_char(val++); |
| 68 | if (*buf == '\0') |
| 69 | return n; |
| 70 | } |
| 71 | |
| 72 | if (n) |
| 73 | *--buf = '\0'; |
| 74 | |
| 75 | printf("env_buf [%d bytes] too small for value of \"%s\"\n", |
| 76 | len, name); |
| 77 | |
| 78 | return n; |
| 79 | } |
| 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | static |
| 84 | int get_factory_record_val(unsigned char *eeprom_buf, int size, uchar *record, |
| 85 | uchar *name, uchar *buf, int len) |
| 86 | { |
| 87 | int ret = -1; |
| 88 | int i, nxt = 0; |
| 89 | int c; |
| 90 | unsigned char end = 0xff; |
Heiko Schocher | 6596b85 | 2014-11-18 11:51:04 +0100 | [diff] [blame] | 91 | unsigned char tmp; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 92 | |
| 93 | for (i = 0; fact_get_char(i) != end; i = nxt) { |
| 94 | nxt = i + 1; |
| 95 | if (fact_get_char(i) == '>') { |
| 96 | int pos; |
| 97 | int endpos; |
| 98 | int z; |
Heiko Schocher | 6596b85 | 2014-11-18 11:51:04 +0100 | [diff] [blame] | 99 | int level = 0; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 100 | |
| 101 | c = strncmp((char *)&eeprom_buf[i + 1], (char *)record, |
| 102 | strlen((char *)record)); |
| 103 | if (c == 0) { |
| 104 | /* record found */ |
| 105 | pos = i + strlen((char *)record) + 2; |
| 106 | nxt = pos; |
| 107 | /* search for "<" */ |
| 108 | c = -1; |
| 109 | for (z = pos; fact_get_char(z) != end; z++) { |
Heiko Schocher | 6596b85 | 2014-11-18 11:51:04 +0100 | [diff] [blame] | 110 | if (fact_get_char(z) == '<') { |
| 111 | if (level == 0) { |
| 112 | endpos = z; |
| 113 | nxt = endpos; |
| 114 | c = 0; |
| 115 | break; |
| 116 | } else { |
| 117 | level--; |
| 118 | } |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 119 | } |
Heiko Schocher | 6596b85 | 2014-11-18 11:51:04 +0100 | [diff] [blame] | 120 | if (fact_get_char(z) == '>') |
| 121 | level++; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 122 | } |
Heiko Schocher | 6596b85 | 2014-11-18 11:51:04 +0100 | [diff] [blame] | 123 | } else { |
| 124 | continue; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 125 | } |
| 126 | if (c == 0) { |
| 127 | /* end found -> call get_factory_val */ |
Heiko Schocher | 6596b85 | 2014-11-18 11:51:04 +0100 | [diff] [blame] | 128 | tmp = eeprom_buf[endpos]; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 129 | eeprom_buf[endpos] = end; |
| 130 | ret = get_factory_val(&eeprom_buf[pos], |
Heiko Schocher | 6596b85 | 2014-11-18 11:51:04 +0100 | [diff] [blame] | 131 | endpos - pos, name, buf, len); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 132 | /* fix buffer */ |
Heiko Schocher | 6596b85 | 2014-11-18 11:51:04 +0100 | [diff] [blame] | 133 | eeprom_buf[endpos] = tmp; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 134 | debug("%s: %s.%s = %s\n", |
| 135 | __func__, record, name, buf); |
| 136 | return ret; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | return ret; |
| 141 | } |
| 142 | |
| 143 | int factoryset_read_eeprom(int i2c_addr) |
| 144 | { |
| 145 | int i, pages = 0, size = 0; |
| 146 | unsigned char eeprom_buf[0x3c00], hdr[4], buf[MAX_STRING_LENGTH]; |
| 147 | unsigned char *cp, *cp1; |
Anatolij Gustschin | d0d75f5 | 2019-07-10 19:44:15 +0200 | [diff] [blame] | 148 | #if CONFIG_IS_ENABLED(DM_I2C) |
| 149 | struct udevice *bus, *dev; |
| 150 | int ret; |
| 151 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 152 | |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 153 | #if defined(CONFIG_DFU_OVER_USB) |
Maxime Ripard | 7f78b9d | 2017-09-07 08:58:08 +0200 | [diff] [blame] | 154 | factory_dat.usb_vendor_id = CONFIG_USB_GADGET_VENDOR_NUM; |
| 155 | factory_dat.usb_product_id = CONFIG_USB_GADGET_PRODUCT_NUM; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 156 | #endif |
Anatolij Gustschin | d0d75f5 | 2019-07-10 19:44:15 +0200 | [diff] [blame] | 157 | |
| 158 | #if CONFIG_IS_ENABLED(DM_I2C) |
| 159 | ret = uclass_get_device_by_seq(UCLASS_I2C, EEPROM_I2C_BUS, &bus); |
| 160 | if (ret) |
| 161 | goto err; |
| 162 | |
| 163 | ret = dm_i2c_probe(bus, i2c_addr, 0, &dev); |
| 164 | if (ret) |
| 165 | goto err; |
| 166 | |
| 167 | ret = i2c_set_chip_offset_len(dev, 2); |
| 168 | if (ret) |
| 169 | goto err; |
| 170 | |
| 171 | ret = dm_i2c_read(dev, EEPROM_FATORYSET_OFFSET, hdr, sizeof(hdr)); |
| 172 | if (ret) |
| 173 | goto err; |
| 174 | #else |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 175 | if (i2c_probe(i2c_addr)) |
| 176 | goto err; |
| 177 | |
| 178 | if (i2c_read(i2c_addr, EEPROM_FATORYSET_OFFSET, 2, hdr, sizeof(hdr))) |
| 179 | goto err; |
Anatolij Gustschin | d0d75f5 | 2019-07-10 19:44:15 +0200 | [diff] [blame] | 180 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 181 | |
| 182 | if ((hdr[0] != 0x99) || (hdr[1] != 0x80)) { |
| 183 | printf("FactorySet is not right in eeprom.\n"); |
| 184 | return 1; |
| 185 | } |
| 186 | |
| 187 | /* get FactorySet size */ |
| 188 | size = (hdr[2] << 8) + hdr[3] + sizeof(hdr); |
| 189 | if (size > 0x3bfa) |
| 190 | size = 0x3bfa; |
| 191 | |
| 192 | pages = size / EEPR_PG_SZ; |
| 193 | |
| 194 | /* |
| 195 | * read the eeprom using i2c |
| 196 | * I can not read entire eeprom in once, so separate into several |
| 197 | * times. Furthermore, fetch eeprom take longer time, so we fetch |
| 198 | * data after every time we got a record from eeprom |
| 199 | */ |
| 200 | debug("Read eeprom page :\n"); |
Anatolij Gustschin | d0d75f5 | 2019-07-10 19:44:15 +0200 | [diff] [blame] | 201 | for (i = 0; i < pages; i++) { |
| 202 | #if CONFIG_IS_ENABLED(DM_I2C) |
| 203 | ret = dm_i2c_read(dev, (OFF_PG + i) * EEPR_PG_SZ, |
| 204 | eeprom_buf + (i * EEPR_PG_SZ), EEPR_PG_SZ); |
| 205 | if (ret) |
| 206 | goto err; |
| 207 | #else |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 208 | if (i2c_read(i2c_addr, (OFF_PG + i) * EEPR_PG_SZ, 2, |
| 209 | eeprom_buf + (i * EEPR_PG_SZ), EEPR_PG_SZ)) |
| 210 | goto err; |
Anatolij Gustschin | d0d75f5 | 2019-07-10 19:44:15 +0200 | [diff] [blame] | 211 | #endif |
| 212 | } |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 213 | |
Anatolij Gustschin | d0d75f5 | 2019-07-10 19:44:15 +0200 | [diff] [blame] | 214 | if (size % EEPR_PG_SZ) { |
| 215 | #if CONFIG_IS_ENABLED(DM_I2C) |
| 216 | ret = dm_i2c_read(dev, (OFF_PG + pages) * EEPR_PG_SZ, |
| 217 | eeprom_buf + (pages * EEPR_PG_SZ), |
| 218 | size % EEPR_PG_SZ); |
| 219 | if (ret) |
| 220 | goto err; |
| 221 | #else |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 222 | if (i2c_read(i2c_addr, (OFF_PG + pages) * EEPR_PG_SZ, 2, |
| 223 | eeprom_buf + (pages * EEPR_PG_SZ), |
| 224 | (size % EEPR_PG_SZ))) |
| 225 | goto err; |
Anatolij Gustschin | d0d75f5 | 2019-07-10 19:44:15 +0200 | [diff] [blame] | 226 | #endif |
| 227 | } |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 228 | |
| 229 | /* we do below just for eeprom align */ |
| 230 | for (i = 0; i < size; i++) |
| 231 | if (eeprom_buf[i] == '\n') |
| 232 | eeprom_buf[i] = 0; |
| 233 | |
| 234 | /* skip header */ |
| 235 | size -= sizeof(hdr); |
| 236 | cp = (uchar *)eeprom_buf + sizeof(hdr); |
| 237 | |
| 238 | /* get mac address */ |
| 239 | get_factory_record_val(cp, size, (uchar *)"ETH1", (uchar *)"mac", |
| 240 | buf, MAX_STRING_LENGTH); |
| 241 | cp1 = buf; |
| 242 | for (i = 0; i < 6; i++) { |
| 243 | factory_dat.mac[i] = simple_strtoul((char *)cp1, NULL, 16); |
| 244 | cp1 += 3; |
| 245 | } |
| 246 | |
Anatolij Gustschin | 8e9821e | 2019-07-10 19:44:16 +0200 | [diff] [blame] | 247 | #if CONFIG_IS_ENABLED(TARGET_GIEDI) || CONFIG_IS_ENABLED(TARGET_DENEB) |
| 248 | /* get mac address for WLAN */ |
| 249 | ret = get_factory_record_val(cp, size, (uchar *)"WLAN1", (uchar *)"mac", |
| 250 | buf, MAX_STRING_LENGTH); |
| 251 | if (ret > 0) { |
| 252 | cp1 = buf; |
| 253 | for (i = 0; i < 6; i++) { |
| 254 | factory_dat.mac_wlan[i] = simple_strtoul((char *)cp1, |
| 255 | NULL, 16); |
| 256 | cp1 += 3; |
| 257 | } |
| 258 | } |
| 259 | #endif |
| 260 | |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 261 | #if defined(CONFIG_DFU_OVER_USB) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 262 | /* read vid and pid for dfu mode */ |
| 263 | if (0 <= get_factory_record_val(cp, size, (uchar *)"USBD1", |
| 264 | (uchar *)"vid", buf, |
| 265 | MAX_STRING_LENGTH)) { |
| 266 | factory_dat.usb_vendor_id = simple_strtoul((char *)buf, |
| 267 | NULL, 16); |
| 268 | } |
| 269 | |
| 270 | if (0 <= get_factory_record_val(cp, size, (uchar *)"USBD1", |
| 271 | (uchar *)"pid", buf, |
| 272 | MAX_STRING_LENGTH)) { |
| 273 | factory_dat.usb_product_id = simple_strtoul((char *)buf, |
| 274 | NULL, 16); |
| 275 | } |
| 276 | printf("DFU USB: VID = 0x%4x, PID = 0x%4x\n", factory_dat.usb_vendor_id, |
| 277 | factory_dat.usb_product_id); |
| 278 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 279 | #if defined(CONFIG_VIDEO) |
| 280 | if (0 <= get_factory_record_val(cp, size, (uchar *)"DISP1", |
| 281 | (uchar *)"name", factory_dat.disp_name, |
| 282 | MAX_STRING_LENGTH)) { |
| 283 | debug("display name: %s\n", factory_dat.disp_name); |
| 284 | } |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 285 | #endif |
Samuel Egli | 8069bfe | 2013-11-04 14:05:03 +0100 | [diff] [blame] | 286 | if (0 <= get_factory_record_val(cp, size, (uchar *)"DEV", |
| 287 | (uchar *)"num", factory_dat.serial, |
| 288 | MAX_STRING_LENGTH)) { |
| 289 | debug("serial number: %s\n", factory_dat.serial); |
| 290 | } |
| 291 | if (0 <= get_factory_record_val(cp, size, (uchar *)"DEV", |
| 292 | (uchar *)"ver", buf, |
| 293 | MAX_STRING_LENGTH)) { |
| 294 | factory_dat.version = simple_strtoul((char *)buf, |
| 295 | NULL, 16); |
| 296 | debug("version number: %d\n", factory_dat.version); |
| 297 | } |
Heiko Schocher | faf2dc6 | 2014-11-18 11:51:06 +0100 | [diff] [blame] | 298 | /* Get ASN from factory set if available */ |
| 299 | if (0 <= get_factory_record_val(cp, size, (uchar *)"DEV", |
| 300 | (uchar *)"id", factory_dat.asn, |
| 301 | MAX_STRING_LENGTH)) { |
| 302 | debug("factoryset asn: %s\n", factory_dat.asn); |
| 303 | } else { |
| 304 | factory_dat.asn[0] = 0; |
| 305 | } |
Heiko Schocher | 7b90565 | 2014-11-18 11:51:05 +0100 | [diff] [blame] | 306 | /* Get COMP/ver from factory set if available */ |
| 307 | if (0 <= get_factory_record_val(cp, size, (uchar *)"COMP", |
| 308 | (uchar *)"ver", |
| 309 | factory_dat.comp_version, |
| 310 | MAX_STRING_LENGTH)) { |
| 311 | debug("factoryset COMP/ver: %s\n", factory_dat.comp_version); |
| 312 | } else { |
| 313 | strcpy((char *)factory_dat.comp_version, "1.0"); |
| 314 | } |
| 315 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 316 | return 0; |
| 317 | |
| 318 | err: |
| 319 | printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\n"); |
| 320 | return 1; |
| 321 | } |
| 322 | |
Anatolij Gustschin | 8e9821e | 2019-07-10 19:44:16 +0200 | [diff] [blame] | 323 | static int get_mac_from_efuse(uint8_t mac[6]) |
| 324 | { |
| 325 | #ifdef CONFIG_AM33XX |
| 326 | struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 327 | uint32_t mac_hi, mac_lo; |
| 328 | |
| 329 | mac_lo = readl(&cdev->macid0l); |
| 330 | mac_hi = readl(&cdev->macid0h); |
| 331 | |
| 332 | mac[0] = mac_hi & 0xFF; |
| 333 | mac[1] = (mac_hi & 0xFF00) >> 8; |
| 334 | mac[2] = (mac_hi & 0xFF0000) >> 16; |
| 335 | mac[3] = (mac_hi & 0xFF000000) >> 24; |
| 336 | mac[4] = mac_lo & 0xFF; |
| 337 | mac[5] = (mac_lo & 0xFF00) >> 8; |
| 338 | #else |
| 339 | /* unhandled */ |
| 340 | memset(mac, 0, 6); |
| 341 | #endif |
| 342 | if (!is_valid_ethaddr(mac)) { |
| 343 | puts("Warning: ethaddr not set by FactorySet or E-fuse. "); |
| 344 | puts("Set <ethaddr> variable to overcome this.\n"); |
| 345 | return -1; |
| 346 | } |
| 347 | return 0; |
| 348 | } |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 349 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 350 | static int factoryset_mac_env_set(void) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 351 | { |
| 352 | uint8_t mac_addr[6]; |
| 353 | |
Anatolij Gustschin | 8e9821e | 2019-07-10 19:44:16 +0200 | [diff] [blame] | 354 | /* Set mac from factoryset or try reading E-fuse */ |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 355 | debug("FactorySet: Set mac address\n"); |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 356 | if (is_valid_ethaddr(factory_dat.mac)) { |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 357 | memcpy(mac_addr, factory_dat.mac, 6); |
| 358 | } else { |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 359 | debug("Warning: FactorySet: <ethaddr> not set. Fallback to E-fuse\n"); |
Anatolij Gustschin | 8e9821e | 2019-07-10 19:44:16 +0200 | [diff] [blame] | 360 | if (get_mac_from_efuse(mac_addr) < 0) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 361 | return -1; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 362 | } |
| 363 | |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 364 | eth_env_set_enetaddr("ethaddr", mac_addr); |
Anatolij Gustschin | 8e9821e | 2019-07-10 19:44:16 +0200 | [diff] [blame] | 365 | |
| 366 | #if CONFIG_IS_ENABLED(TARGET_GIEDI) || CONFIG_IS_ENABLED(TARGET_DENEB) |
| 367 | eth_env_set_enetaddr("eth1addr", mac_addr); |
| 368 | |
| 369 | /* wlan mac */ |
| 370 | if (is_valid_ethaddr(factory_dat.mac_wlan)) |
| 371 | eth_env_set_enetaddr("eth2addr", factory_dat.mac_wlan); |
| 372 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
Anatolij Gustschin | 8e9821e | 2019-07-10 19:44:16 +0200 | [diff] [blame] | 376 | static void factoryset_dtb_env_set(void) |
| 377 | { |
| 378 | /* Set ASN in environment*/ |
| 379 | if (factory_dat.asn[0] != 0) { |
| 380 | env_set("dtb_name", (char *)factory_dat.asn); |
| 381 | } else { |
| 382 | /* dtb suffix gets added in load script */ |
| 383 | env_set("dtb_name", "default"); |
| 384 | } |
| 385 | } |
| 386 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 387 | int factoryset_env_set(void) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 388 | { |
| 389 | int ret = 0; |
| 390 | |
Anatolij Gustschin | 8e9821e | 2019-07-10 19:44:16 +0200 | [diff] [blame] | 391 | factoryset_dtb_env_set(); |
| 392 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 393 | if (factoryset_mac_env_set() < 0) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 394 | ret = -1; |
| 395 | |
| 396 | return ret; |
| 397 | } |
| 398 | |
Lukasz Majewski | 44b5b38 | 2013-10-08 14:30:41 +0200 | [diff] [blame] | 399 | int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 400 | { |
| 401 | put_unaligned(factory_dat.usb_vendor_id, &dev->idVendor); |
| 402 | put_unaligned(factory_dat.usb_product_id, &dev->idProduct); |
Samuel Egli | 8069bfe | 2013-11-04 14:05:03 +0100 | [diff] [blame] | 403 | g_dnl_set_serialnumber((char *)factory_dat.serial); |
| 404 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 405 | return 0; |
| 406 | } |
Samuel Egli | 8069bfe | 2013-11-04 14:05:03 +0100 | [diff] [blame] | 407 | |
| 408 | int g_dnl_get_board_bcd_device_number(int gcnum) |
| 409 | { |
| 410 | return factory_dat.version; |
| 411 | } |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 412 | #endif /* defined(CONFIG_SPL_BUILD) */ |