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