Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Toradex, Inc. |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 7 | #include <env.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 8 | #include <g_dnl.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 10 | #include <linux/libfdt.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 11 | |
Igor Opaniuk | 897822d | 2020-07-15 13:31:01 +0300 | [diff] [blame] | 12 | #ifdef CONFIG_DM_VIDEO |
| 13 | #include <bmp_logo.h> |
| 14 | #include <dm.h> |
| 15 | #include <splash.h> |
| 16 | #include <video.h> |
| 17 | #endif |
| 18 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 19 | #include "tdx-cfg-block.h" |
Simon Glass | d9a766f | 2017-05-17 08:23:00 -0600 | [diff] [blame] | 20 | #include <asm/setup.h> |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 21 | #include "tdx-common.h" |
| 22 | |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 23 | #define TORADEX_OUI 0x00142dUL |
| 24 | |
Philippe Schenker | 1832bd3 | 2022-06-13 19:35:22 +0200 | [diff] [blame] | 25 | #define SERIAL_STR_LEN 8 |
| 26 | #define MODULE_VER_STR_LEN 4 // V1.1 |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame] | 27 | #define MODULE_REV_STR_LEN 3 // [A-Z] or #[26-99] |
Philippe Schenker | 1832bd3 | 2022-06-13 19:35:22 +0200 | [diff] [blame] | 28 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 29 | #ifdef CONFIG_TDX_CFG_BLOCK |
Philippe Schenker | 1832bd3 | 2022-06-13 19:35:22 +0200 | [diff] [blame] | 30 | static char tdx_serial_str[SERIAL_STR_LEN + 1]; |
| 31 | static char tdx_board_rev_str[MODULE_VER_STR_LEN + MODULE_REV_STR_LEN + 1]; |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 32 | |
Igor Opaniuk | ecfe0f5 | 2020-07-15 13:30:57 +0300 | [diff] [blame] | 33 | #ifdef CONFIG_TDX_CFG_BLOCK_EXTRA |
Philippe Schenker | 1832bd3 | 2022-06-13 19:35:22 +0200 | [diff] [blame] | 34 | static char tdx_car_serial_str[SERIAL_STR_LEN + 1]; |
| 35 | static char tdx_car_rev_str[MODULE_VER_STR_LEN + MODULE_REV_STR_LEN + 1]; |
Igor Opaniuk | ecfe0f5 | 2020-07-15 13:30:57 +0300 | [diff] [blame] | 36 | static char *tdx_carrier_board_name; |
| 37 | #endif |
| 38 | |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 39 | #if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) |
| 40 | u32 get_board_revision(void) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 41 | { |
| 42 | /* Check validity */ |
| 43 | if (!tdx_hw_tag.ver_major) |
| 44 | return 0; |
| 45 | |
| 46 | return ((tdx_hw_tag.ver_major & 0xff) << 8) | |
| 47 | ((tdx_hw_tag.ver_minor & 0xf) << 4) | |
| 48 | ((tdx_hw_tag.ver_assembly & 0xf) + 0xa); |
| 49 | } |
| 50 | #endif /* CONFIG_TDX_CFG_BLOCK */ |
| 51 | |
| 52 | #ifdef CONFIG_SERIAL_TAG |
| 53 | void get_board_serial(struct tag_serialnr *serialnr) |
| 54 | { |
| 55 | int array[8]; |
| 56 | unsigned int serial = tdx_serial; |
| 57 | int i; |
| 58 | |
| 59 | serialnr->low = 0; |
| 60 | serialnr->high = 0; |
| 61 | |
| 62 | /* Check validity */ |
| 63 | if (serial) { |
| 64 | /* |
| 65 | * Convert to Linux serial number format (hexadecimal coded |
| 66 | * decimal) |
| 67 | */ |
| 68 | i = 7; |
| 69 | while (serial) { |
| 70 | array[i--] = serial % 10; |
| 71 | serial /= 10; |
| 72 | } |
| 73 | while (i >= 0) |
| 74 | array[i--] = 0; |
| 75 | serial = array[0]; |
| 76 | for (i = 1; i < 8; i++) { |
| 77 | serial *= 16; |
| 78 | serial += array[i]; |
| 79 | } |
| 80 | |
| 81 | serialnr->low = serial; |
| 82 | } |
| 83 | } |
| 84 | #endif /* CONFIG_SERIAL_TAG */ |
| 85 | |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame] | 86 | static const char *get_board_assembly(u16 ver_assembly) |
| 87 | { |
| 88 | static char ver_name[MODULE_REV_STR_LEN + 1]; |
| 89 | |
| 90 | if (ver_assembly < 26) { |
| 91 | ver_name[0] = (char)ver_assembly + 'A'; |
| 92 | ver_name[1] = '\0'; |
| 93 | } else { |
| 94 | snprintf(ver_name, sizeof(ver_name), |
| 95 | "#%u", ver_assembly); |
| 96 | } |
| 97 | |
| 98 | return ver_name; |
| 99 | } |
| 100 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 101 | int show_board_info(void) |
| 102 | { |
| 103 | unsigned char ethaddr[6]; |
| 104 | |
| 105 | if (read_tdx_cfg_block()) { |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 106 | printf("MISSING TORADEX CONFIG BLOCK\n"); |
| 107 | tdx_eth_addr.oui = htonl(TORADEX_OUI << 8); |
| 108 | tdx_eth_addr.nic = htonl(tdx_serial << 8); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 109 | checkboard(); |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 110 | } else { |
Philippe Schenker | 38cf79e | 2022-06-13 19:35:21 +0200 | [diff] [blame] | 111 | snprintf(tdx_serial_str, sizeof(tdx_serial_str), |
| 112 | "%08u", tdx_serial); |
| 113 | snprintf(tdx_board_rev_str, sizeof(tdx_board_rev_str), |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame] | 114 | "V%1d.%1d%s", |
Philippe Schenker | 38cf79e | 2022-06-13 19:35:21 +0200 | [diff] [blame] | 115 | tdx_hw_tag.ver_major, |
| 116 | tdx_hw_tag.ver_minor, |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame] | 117 | get_board_assembly(tdx_hw_tag.ver_assembly)); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 118 | |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 119 | env_set("serial#", tdx_serial_str); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 120 | |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 121 | printf("Model: Toradex %s %s, Serial# %s\n", |
| 122 | toradex_modules[tdx_hw_tag.prodid], |
| 123 | tdx_board_rev_str, |
| 124 | tdx_serial_str); |
Igor Opaniuk | ecfe0f5 | 2020-07-15 13:30:57 +0300 | [diff] [blame] | 125 | #ifdef CONFIG_TDX_CFG_BLOCK_EXTRA |
| 126 | if (read_tdx_cfg_block_carrier()) { |
| 127 | printf("MISSING TORADEX CARRIER CONFIG BLOCKS\n"); |
| 128 | try_migrate_tdx_cfg_block_carrier(); |
| 129 | } else { |
| 130 | tdx_carrier_board_name = (char *) |
| 131 | toradex_carrier_boards[tdx_car_hw_tag.prodid]; |
| 132 | |
Philippe Schenker | 38cf79e | 2022-06-13 19:35:21 +0200 | [diff] [blame] | 133 | snprintf(tdx_car_serial_str, sizeof(tdx_car_serial_str), |
| 134 | "%08u", tdx_car_serial); |
| 135 | snprintf(tdx_car_rev_str, sizeof(tdx_car_rev_str), |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame] | 136 | "V%1d.%1d%s", |
Philippe Schenker | 38cf79e | 2022-06-13 19:35:21 +0200 | [diff] [blame] | 137 | tdx_car_hw_tag.ver_major, |
| 138 | tdx_car_hw_tag.ver_minor, |
Philippe Schenker | 498f95a | 2022-06-13 19:35:23 +0200 | [diff] [blame] | 139 | get_board_assembly(tdx_car_hw_tag.ver_assembly)); |
Igor Opaniuk | ecfe0f5 | 2020-07-15 13:30:57 +0300 | [diff] [blame] | 140 | |
| 141 | env_set("carrier_serial#", tdx_car_serial_str); |
| 142 | printf("Carrier: Toradex %s %s, Serial# %s\n", |
| 143 | tdx_carrier_board_name, |
| 144 | tdx_car_rev_str, |
| 145 | tdx_car_serial_str); |
| 146 | } |
| 147 | #endif |
Bhuvanchandra DV | 2190ade | 2019-03-25 17:18:28 +0100 | [diff] [blame] | 148 | } |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * Check if environment contains a valid MAC address, |
| 152 | * set the one from config block if not |
| 153 | */ |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 154 | if (!eth_env_get_enetaddr("ethaddr", ethaddr)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 155 | eth_env_set_enetaddr("ethaddr", (u8 *)&tdx_eth_addr); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 156 | |
| 157 | #ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 158 | if (!eth_env_get_enetaddr("eth1addr", ethaddr)) { |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 159 | /* |
| 160 | * Secondary MAC address is allocated from block |
| 161 | * 0x100000 higher then the first MAC address |
| 162 | */ |
| 163 | memcpy(ethaddr, &tdx_eth_addr, 6); |
| 164 | ethaddr[3] += 0x10; |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 165 | eth_env_set_enetaddr("eth1addr", ethaddr); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 166 | } |
| 167 | #endif |
| 168 | |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
Stefan Agner | 57985bd | 2021-07-23 09:39:46 +0300 | [diff] [blame] | 172 | #ifdef CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 173 | int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) |
| 174 | { |
| 175 | unsigned short usb_pid; |
| 176 | |
| 177 | usb_pid = TORADEX_USB_PRODUCT_NUM_OFFSET + tdx_hw_tag.prodid; |
| 178 | put_unaligned(usb_pid, &dev->idProduct); |
| 179 | |
| 180 | return 0; |
| 181 | } |
Stefan Agner | a188652 | 2016-11-30 13:41:52 -0800 | [diff] [blame] | 182 | #endif |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 183 | |
Stefan Agner | 98ffd0f | 2016-11-30 13:41:53 -0800 | [diff] [blame] | 184 | #if defined(CONFIG_OF_LIBFDT) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 185 | int ft_common_board_setup(void *blob, struct bd_info *bd) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 186 | { |
| 187 | if (tdx_serial) { |
| 188 | fdt_setprop(blob, 0, "serial-number", tdx_serial_str, |
| 189 | strlen(tdx_serial_str) + 1); |
| 190 | } |
| 191 | |
| 192 | if (tdx_hw_tag.ver_major) { |
| 193 | char prod_id[5]; |
| 194 | |
Philippe Schenker | 38cf79e | 2022-06-13 19:35:21 +0200 | [diff] [blame] | 195 | snprintf(prod_id, sizeof(prod_id), "%04u", tdx_hw_tag.prodid); |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 196 | fdt_setprop(blob, 0, "toradex,product-id", prod_id, 5); |
| 197 | |
| 198 | fdt_setprop(blob, 0, "toradex,board-rev", tdx_board_rev_str, |
| 199 | strlen(tdx_board_rev_str) + 1); |
| 200 | } |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | #endif |
| 205 | |
| 206 | #else /* CONFIG_TDX_CFG_BLOCK */ |
| 207 | |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 208 | #if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG) |
| 209 | u32 get_board_revision(void) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 210 | { |
| 211 | return 0; |
| 212 | } |
| 213 | #endif /* CONFIG_REVISION_TAG */ |
| 214 | |
| 215 | #ifdef CONFIG_SERIAL_TAG |
| 216 | u32 get_board_serial(void) |
| 217 | { |
| 218 | return 0; |
| 219 | } |
| 220 | #endif /* CONFIG_SERIAL_TAG */ |
| 221 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 222 | int ft_common_board_setup(void *blob, struct bd_info *bd) |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 223 | { |
| 224 | return 0; |
| 225 | } |
Marcel Ziswiler | 7a28dfc | 2016-11-16 17:49:22 +0100 | [diff] [blame] | 226 | |
| 227 | #endif /* CONFIG_TDX_CFG_BLOCK */ |