2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-11-16 16:49:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Toradex, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2016-11-16 16:49:22 +00:00
|
|
|
#include <g_dnl.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2016-11-16 16:49:22 +00:00
|
|
|
|
2022-10-18 13:46:31 +00:00
|
|
|
#ifdef CONFIG_VIDEO
|
2020-07-15 10:31:01 +00:00
|
|
|
#include <bmp_logo.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <splash.h>
|
|
|
|
#include <video.h>
|
|
|
|
#endif
|
|
|
|
|
2016-11-16 16:49:22 +00:00
|
|
|
#include "tdx-cfg-block.h"
|
2017-05-17 14:23:00 +00:00
|
|
|
#include <asm/setup.h>
|
2016-11-16 16:49:22 +00:00
|
|
|
#include "tdx-common.h"
|
|
|
|
|
2022-06-13 17:35:22 +00:00
|
|
|
#define SERIAL_STR_LEN 8
|
|
|
|
#define MODULE_VER_STR_LEN 4 // V1.1
|
2022-06-13 17:35:23 +00:00
|
|
|
#define MODULE_REV_STR_LEN 3 // [A-Z] or #[26-99]
|
2022-06-13 17:35:22 +00:00
|
|
|
|
2016-11-16 16:49:22 +00:00
|
|
|
#ifdef CONFIG_TDX_CFG_BLOCK
|
2022-06-13 17:35:22 +00:00
|
|
|
static char tdx_serial_str[SERIAL_STR_LEN + 1];
|
|
|
|
static char tdx_board_rev_str[MODULE_VER_STR_LEN + MODULE_REV_STR_LEN + 1];
|
2016-11-16 16:49:22 +00:00
|
|
|
|
2020-07-15 10:30:57 +00:00
|
|
|
#ifdef CONFIG_TDX_CFG_BLOCK_EXTRA
|
2022-06-13 17:35:22 +00:00
|
|
|
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];
|
2020-07-15 10:30:57 +00:00
|
|
|
static char *tdx_carrier_board_name;
|
|
|
|
#endif
|
|
|
|
|
arm: Disable ATAGs support
With the exceptions of ds109, ds414, icnova-a20-swac, nokia_rx51 and
stemmy, disable ATAG support. A large number of platforms had enabled
support but never supported a kernel so old as to require it. Further,
some platforms are old enough to support both, but are well supported by
devicetree booting, and have been for a number of years. This is
because some of the ATAGs related functions have been re-used to provide
the same kind of information, but for devicetree or just generally to
inform the user. When needed still, rename these functions to
get_board_revision() instead, to avoid conflicts. In other cases, these
functions were simply unused, so drop them.
Cc: Andre Przywara <andre.przywara@arm.com>
Cc: Jagan Teki <jagan@amarulasolutions.com>
Cc: Phil Sutter <phil@nwl.cc>
Cc: Stefan Bosch <stefan_b@posteo.net>
Signed-off-by: Tom Rini <trini@konsulko.com>
2021-08-30 13:16:30 +00:00
|
|
|
#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
|
|
|
|
u32 get_board_revision(void)
|
2016-11-16 16:49:22 +00:00
|
|
|
{
|
|
|
|
/* 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 */
|
|
|
|
|
2022-06-13 17:35:23 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:49:22 +00:00
|
|
|
int show_board_info(void)
|
|
|
|
{
|
|
|
|
unsigned char ethaddr[6];
|
|
|
|
|
|
|
|
if (read_tdx_cfg_block()) {
|
2019-03-25 16:18:28 +00:00
|
|
|
printf("MISSING TORADEX CONFIG BLOCK\n");
|
2022-06-20 14:57:45 +00:00
|
|
|
get_mac_from_serial(tdx_serial, &tdx_eth_addr);
|
2016-11-16 16:49:22 +00:00
|
|
|
checkboard();
|
2019-03-25 16:18:28 +00:00
|
|
|
} else {
|
2022-06-13 17:35:21 +00:00
|
|
|
snprintf(tdx_serial_str, sizeof(tdx_serial_str),
|
|
|
|
"%08u", tdx_serial);
|
|
|
|
snprintf(tdx_board_rev_str, sizeof(tdx_board_rev_str),
|
2022-06-13 17:35:23 +00:00
|
|
|
"V%1d.%1d%s",
|
2022-06-13 17:35:21 +00:00
|
|
|
tdx_hw_tag.ver_major,
|
|
|
|
tdx_hw_tag.ver_minor,
|
2022-06-13 17:35:23 +00:00
|
|
|
get_board_assembly(tdx_hw_tag.ver_assembly));
|
2019-03-25 16:18:28 +00:00
|
|
|
|
|
|
|
env_set("serial#", tdx_serial_str);
|
|
|
|
|
2022-07-21 13:17:38 +00:00
|
|
|
printf("Model: Toradex %04d %s %s\n",
|
|
|
|
tdx_hw_tag.prodid,
|
2022-07-21 13:17:34 +00:00
|
|
|
toradex_modules[tdx_hw_tag.prodid].name,
|
2022-07-21 13:17:38 +00:00
|
|
|
tdx_board_rev_str);
|
|
|
|
printf("Serial#: %s\n", tdx_serial_str);
|
2020-07-15 10:30:57 +00:00
|
|
|
#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 = (char *)
|
|
|
|
toradex_carrier_boards[tdx_car_hw_tag.prodid];
|
|
|
|
|
2022-06-13 17:35:21 +00:00
|
|
|
snprintf(tdx_car_serial_str, sizeof(tdx_car_serial_str),
|
|
|
|
"%08u", tdx_car_serial);
|
|
|
|
snprintf(tdx_car_rev_str, sizeof(tdx_car_rev_str),
|
2022-06-13 17:35:23 +00:00
|
|
|
"V%1d.%1d%s",
|
2022-06-13 17:35:21 +00:00
|
|
|
tdx_car_hw_tag.ver_major,
|
|
|
|
tdx_car_hw_tag.ver_minor,
|
2022-06-13 17:35:23 +00:00
|
|
|
get_board_assembly(tdx_car_hw_tag.ver_assembly));
|
2020-07-15 10:30:57 +00:00
|
|
|
|
|
|
|
env_set("carrier_serial#", tdx_car_serial_str);
|
|
|
|
printf("Carrier: Toradex %s %s, Serial# %s\n",
|
|
|
|
tdx_carrier_board_name,
|
|
|
|
tdx_car_rev_str,
|
|
|
|
tdx_car_serial_str);
|
|
|
|
}
|
|
|
|
#endif
|
2016-11-16 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if environment contains a valid MAC address,
|
|
|
|
* set the one from config block if not
|
|
|
|
*/
|
2017-08-03 18:22:14 +00:00
|
|
|
if (!eth_env_get_enetaddr("ethaddr", ethaddr))
|
2017-08-03 18:22:11 +00:00
|
|
|
eth_env_set_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);
|
2016-11-16 16:49:22 +00:00
|
|
|
|
2022-07-21 13:17:36 +00:00
|
|
|
if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR) &&
|
|
|
|
!eth_env_get_enetaddr("eth1addr", ethaddr)) {
|
2016-11-16 16:49:22 +00:00
|
|
|
/*
|
|
|
|
* Secondary MAC address is allocated from block
|
|
|
|
* 0x100000 higher then the first MAC address
|
|
|
|
*/
|
|
|
|
memcpy(ethaddr, &tdx_eth_addr, 6);
|
|
|
|
ethaddr[3] += 0x10;
|
2017-08-03 18:22:11 +00:00
|
|
|
eth_env_set_enetaddr("eth1addr", ethaddr);
|
2016-11-16 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-23 06:39:46 +00:00
|
|
|
#ifdef CONFIG_TDX_CFG_BLOCK_USB_GADGET_PID
|
2016-11-16 16:49:22 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-11-30 21:41:52 +00:00
|
|
|
#endif
|
2016-11-16 16:49:22 +00:00
|
|
|
|
2016-11-30 21:41:53 +00:00
|
|
|
#if defined(CONFIG_OF_LIBFDT)
|
2020-06-26 06:13:33 +00:00
|
|
|
int ft_common_board_setup(void *blob, struct bd_info *bd)
|
2016-11-16 16:49:22 +00:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
|
2022-06-13 17:35:21 +00:00
|
|
|
snprintf(prod_id, sizeof(prod_id), "%04u", tdx_hw_tag.prodid);
|
2016-11-16 16:49:22 +00:00
|
|
|
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 */
|
|
|
|
|
arm: Disable ATAGs support
With the exceptions of ds109, ds414, icnova-a20-swac, nokia_rx51 and
stemmy, disable ATAG support. A large number of platforms had enabled
support but never supported a kernel so old as to require it. Further,
some platforms are old enough to support both, but are well supported by
devicetree booting, and have been for a number of years. This is
because some of the ATAGs related functions have been re-used to provide
the same kind of information, but for devicetree or just generally to
inform the user. When needed still, rename these functions to
get_board_revision() instead, to avoid conflicts. In other cases, these
functions were simply unused, so drop them.
Cc: Andre Przywara <andre.przywara@arm.com>
Cc: Jagan Teki <jagan@amarulasolutions.com>
Cc: Phil Sutter <phil@nwl.cc>
Cc: Stefan Bosch <stefan_b@posteo.net>
Signed-off-by: Tom Rini <trini@konsulko.com>
2021-08-30 13:16:30 +00:00
|
|
|
#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
|
|
|
|
u32 get_board_revision(void)
|
2016-11-16 16:49:22 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_REVISION_TAG */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_TAG
|
|
|
|
u32 get_board_serial(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SERIAL_TAG */
|
|
|
|
|
2020-06-26 06:13:33 +00:00
|
|
|
int ft_common_board_setup(void *blob, struct bd_info *bd)
|
2016-11-16 16:49:22 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_TDX_CFG_BLOCK */
|