Commit 2270b6cd authored by Angus Ainslie's avatar Angus Ainslie

Merge branch 'fuse-cmp' into 'librem5'

Add functionality to manage board vid:pid and PCB rev

Closes librem5-devkit-tools#21

See merge request !27
parents 508b4a8c 7b96a27d
......@@ -20,6 +20,7 @@
#include <asm/arch/clock.h>
#include <asm/mach-imx/video.h>
#include <asm/arch/video_common.h>
#include <fuse.h>
#include <spl.h>
#include <power/pmic.h>
#include "../common/tcpc.h"
......@@ -566,11 +567,22 @@ int fastboot_key_pressed(void)
int board_late_init(void)
{
printf("%s: starting\n", __func__ );
#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
u32 vid, rev;
char rev_str[3];
env_set("board_name", "librem5");
env_set("board_rev", "1.0");
if (fuse_read(8, 2, &vid) || fuse_read(14, 0, &rev))
env_set("board_rev", BOARD_REV_ERROR);
else if (vid == 0) {
env_set("board_rev", BOARD_REV_UNKNOWN);
} else if (vid == (PURISM_PID<<16 | PURISM_VID)) {
sprintf(rev_str, "%u", rev);
env_set("board_rev", rev_str);
}
printf("Board name: %s\n", env_get("board_name"));
printf("Board rev: %s\n", env_get("board_rev"));
#endif
#ifdef CONFIG_ENV_IS_IN_MMC
......
......@@ -45,6 +45,16 @@
#define TPS_RESET IMX_GPIO_NR(3, 24)
#define PURISM_VID 0x316d
#define PURISM_PID 0x4c05
#define BOARD_REV_ERROR "unknown"
#define BOARD_REV_BIRCH "1"
#define BOARD_REV_CHESTNUT "2"
#define BOARD_REV_DOGWOOD "3"
/* Could be ASPEN, BIRCH or CHESTNUT. assume CHESTNUT */
#define BOARD_REV_UNKNOWN BOARD_REV_CHESTNUT
static iomux_v3_cfg_t const configure_pads[] = {
IMX8MQ_PAD_GPIO1_IO00__GPIO1_IO0 | MUX_PAD_CTRL(PAD_CTL_DSE6),
IMX8MQ_PAD_GPIO1_IO03__GPIO1_IO3 | MUX_PAD_CTRL(PAD_CTL_DSE6),
......
......@@ -12,6 +12,7 @@
#include <command.h>
#include <console.h>
#include <fuse.h>
#include <mapmem.h>
#include <linux/errno.h>
static int strtou32(const char *str, unsigned int base, u32 *result)
......@@ -44,7 +45,9 @@ static int do_fuse(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
const char *op = argc >= 2 ? argv[1] : NULL;
int confirmed = argc >= 3 && !strcmp(argv[2], "-y");
u32 bank, word, cnt, val;
u32 bank, word, cnt, val, cmp;
ulong addr;
void *buf, *start;
int ret, i;
argc -= 2 + confirmed;
......@@ -72,6 +75,46 @@ static int do_fuse(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
printf(" %.8x", val);
}
putc('\n');
} else if (!strcmp(op, "readm")) {
if (argc == 3)
cnt = 1;
else if (argc != 4 || strtou32(argv[3], 0, &cnt))
return CMD_RET_USAGE;
addr = simple_strtoul(argv[2], NULL, 16);
start = map_sysmem(addr, 4);
buf = start;
printf("Reading bank %u len %u to 0x%lx\n", bank, cnt, addr);
for (i = 0; i < cnt; i++, word++) {
ret = fuse_read(bank, word, &val);
if (ret)
goto err;
*((u32 *)buf) = val;
buf += 4;
}
unmap_sysmem(start);
} else if (!strcmp(op, "cmp")) {
if (argc != 3 || strtou32(argv[2], 0, &cmp))
return CMD_RET_USAGE;
printf("Comparing bank %u:\n", bank);
printf("\nWord 0x%.8x:", word);
printf("\nValue 0x%.8x:", cmp);
ret = fuse_read(bank, word, &val);
if (ret)
goto err;
printf( "0x%.8x\n", val);
if (val != cmp) {
printf("failed\n");
return CMD_RET_FAILURE;
}
printf("passed\n");
} else if (!strcmp(op, "sense")) {
if (argc == 2)
cnt = 1;
......@@ -136,6 +179,10 @@ U_BOOT_CMD(
"Fuse sub-system",
"read <bank> <word> [<cnt>] - read 1 or 'cnt' fuse words,\n"
" starting at 'word'\n"
"fuse cmp <bank> <word> <hexval> - compare 'hexval' to fuse\n"
" at 'word'\n"
"fuse readm <bank> <word> <addr> [<cnt>] - read 1 or 'cnt' fuse words,\n"
" starting at 'word' into memory at 'addr'\n"
"fuse sense <bank> <word> [<cnt>] - sense 1 or 'cnt' fuse words,\n"
" starting at 'word'\n"
"fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n"
......
......@@ -88,4 +88,5 @@ CONFIG_IMX8M_DRAM=y
CONFIG_IMX8M_LPDDR4=y
CONFIG_ENV_IS_IN_MMC=y
CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
......@@ -67,8 +67,6 @@
#define CONFIG_SYS_I2C_MXC_I2C3 /* enable I2C bus 3 */
#define CONFIG_SYS_I2C_MXC_I2C4 /* enable I2C bus 4 */
#define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
#define CONFIG_POWER
#define CONFIG_POWER_I2C
#define CONFIG_POWER_BD71837
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment