diff options
Diffstat (limited to 'board/ti/common/board_detect.c')
-rw-r--r-- | board/ti/common/board_detect.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index 564d2f7046..59ec57062d 100644 --- a/board/ti/common/board_detect.c +++ b/board/ti/common/board_detect.c @@ -14,6 +14,9 @@ #include <dm/uclass.h> #include <env.h> #include <i2c.h> +#include <mmc.h> +#include <errno.h> +#include <malloc.h> #include "board_detect.h" @@ -171,6 +174,79 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr, return 0; } +int __maybe_unused ti_emmc_boardid_get(void) +{ + int rc; + struct udevice *dev; + struct mmc *mmc; + struct ti_common_eeprom *ep; + struct ti_am_eeprom brdid; + struct blk_desc *bdesc; + uchar *buffer; + + ep = TI_EEPROM_DATA; + if (ep->header == TI_EEPROM_HEADER_MAGIC) + return 0; /* EEPROM has already been read */ + + /* Initialize with a known bad marker for emmc fails.. */ + ep->header = TI_DEAD_EEPROM_MAGIC; + ep->name[0] = 0x0; + ep->version[0] = 0x0; + ep->serial[0] = 0x0; + ep->config[0] = 0x0; + + /* uclass object initialization */ + rc = mmc_initialize(NULL); + if (rc) + return rc; + + /* Set device to /dev/mmcblk1 */ + rc = uclass_get_device(UCLASS_MMC, 1, &dev); + if (rc) + return rc; + + /* Grab the mmc device */ + mmc = mmc_get_mmc_dev(dev); + if (!mmc) + return -ENODEV; + + /* mmc hardware initialization routine */ + mmc_init(mmc); + + /* Set partition to /dev/mmcblk1boot1 */ + rc = mmc_switch_part(mmc, 2); + if (rc) + return rc; + + buffer = malloc(mmc->read_bl_len); + if (!buffer) + return -ENOMEM; + + bdesc = mmc_get_blk_desc(mmc); + + /* blk_dread returns the number of blocks read*/ + if (blk_dread(bdesc, 0L, 1, buffer) != 1) { + rc = -EIO; + goto cleanup; + } + + memcpy(&brdid, buffer, sizeof(brdid)); + + /* Write out the ep struct values */ + ep->header = brdid.header; + strlcpy(ep->name, brdid.name, TI_EEPROM_HDR_NAME_LEN + 1); + ti_eeprom_string_cleanup(ep->name); + strlcpy(ep->version, brdid.version, TI_EEPROM_HDR_REV_LEN + 1); + ti_eeprom_string_cleanup(ep->version); + strlcpy(ep->serial, brdid.serial, TI_EEPROM_HDR_SERIAL_LEN + 1); + ti_eeprom_string_cleanup(ep->serial); + +cleanup: + free(buffer); + + return rc; +} + int __maybe_unused ti_i2c_eeprom_am_set(const char *name, const char *rev) { struct ti_common_eeprom *ep; |