From 6322a7b63fb74d0f9ba5d027ef8299df7f796498 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:22 -0600 Subject: cros: Update cros_ec code to use struct udevice At present we pass around a private pointer to specify the cros_ec device. With driver model it makes more sense to pass the device. Update the code to do this. Signed-off-by: Simon Glass --- cmd/cros_ec.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'cmd') diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c index 60c87838fdf..fb369a4e329 100644 --- a/cmd/cros_ec.c +++ b/cmd/cros_ec.c @@ -49,7 +49,7 @@ static int cros_ec_decode_region(int argc, char * const argv[]) * @return 0 for ok, 1 for a usage error or -ve for ec command error * (negative EC_RES_...) */ -static int do_read_write(struct cros_ec_dev *dev, int is_write, int argc, +static int do_read_write(struct udevice *dev, int is_write, int argc, char * const argv[]) { uint32_t offset, size = -1U, region_size; @@ -94,8 +94,7 @@ static int do_read_write(struct cros_ec_dev *dev, int is_write, int argc, static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - struct cros_ec_dev *dev; - struct udevice *udev; + struct udevice *dev; const char *cmd; int ret = 0; @@ -105,10 +104,10 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) cmd = argv[1]; if (0 == strcmp("init", cmd)) { /* Remove any existing device */ - ret = uclass_find_device(UCLASS_CROS_EC, 0, &udev); + ret = uclass_find_device(UCLASS_CROS_EC, 0, &dev); if (!ret) - device_remove(udev, DM_REMOVE_NORMAL); - ret = uclass_get_device(UCLASS_CROS_EC, 0, &udev); + device_remove(dev, DM_REMOVE_NORMAL); + ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev); if (ret) { printf("Could not init cros_ec device (err %d)\n", ret); return 1; @@ -116,12 +115,11 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 0; } - ret = uclass_get_device(UCLASS_CROS_EC, 0, &udev); + ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev); if (ret) { printf("Cannot get cros-ec device (err=%d)\n", ret); return 1; } - dev = dev_get_uclass_priv(udev); if (0 == strcmp("id", cmd)) { char id[MSG_BYTES]; @@ -262,7 +260,8 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) unsigned long result; if (argc <= 2) { - ret = cros_ec_read_vbnvcontext(dev, block); + ret = cros_ec_read_nvdata(dev, block, + EC_VBNV_BLOCK_SIZE); if (!ret) { printf("vbnv_block: "); for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++) @@ -288,7 +287,8 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) strict_strtoul(buf, 16, &result); block[i] = result; } - ret = cros_ec_write_vbnvcontext(dev, block); + ret = cros_ec_write_nvdata(dev, block, + EC_VBNV_BLOCK_SIZE); } if (ret) { debug("%s: Could not %s VbNvContext\n", __func__, @@ -336,9 +336,9 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) state = simple_strtoul(argv[3], &endp, 10); if (*argv[3] == 0 || *endp != 0) return CMD_RET_USAGE; - ret = cros_ec_set_ldo(udev, index, state); + ret = cros_ec_set_ldo(dev, index, state); } else { - ret = cros_ec_get_ldo(udev, index, &state); + ret = cros_ec_get_ldo(dev, index, &state); if (!ret) { printf("LDO%d: %s\n", index, state == EC_LDO_STATE_ON ? -- cgit v1.2.3 From 6e64ec1256875f6fafa853a74108fb57fd769e98 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:29 -0600 Subject: tpm: Add a few new commands for v1 These are needed for the 2018 version of Chromium OS vboot. Add an implementation for TPM v1, with v2 to come later. Signed-off-by: Simon Glass --- cmd/tpm_test.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'cmd') diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c index 35f3c96e3de..f21ad5d3cf9 100644 --- a/cmd/tpm_test.c +++ b/cmd/tpm_test.c @@ -62,14 +62,6 @@ static uint32_t tpm_get_flags(uint8_t *disable, uint8_t *deactivated, return 0; } -static uint32_t tpm_set_global_lock(void) -{ - uint32_t x; - - debug("TPM: Set global lock\n"); - return tpm_nv_write_value(INDEX0, (uint8_t *)&x, 0); -} - static uint32_t tpm_nv_write_value_lock(uint32_t index) { debug("TPM: Write lock 0x%x\n", index); @@ -77,13 +69,6 @@ static uint32_t tpm_nv_write_value_lock(uint32_t index) return tpm_nv_write_value(index, NULL, 0); } -static uint32_t tpm_nv_set_locked(void) -{ - debug("TPM: Set NV locked\n"); - - return tpm_nv_define_space(TPM_NV_INDEX_LOCK, 0, 0); -} - static int tpm_is_owned(void) { uint8_t response[TPM_PUBEK_SIZE]; -- cgit v1.2.3 From 6f1c0430e88396abc8e6a91ab3cc78882c76cb7c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:36 -0600 Subject: cros: Update ec_commands to latest version This file has changed quite a bit in the last 5 years as the capabilities of the ECs have grown. Sync it up with the copy in coreboot commit b9141f2215. The only change is the addition of EC_VBNV_BLOCK_SIZE_V2. This is needed because U-Boot uses the new v2 vboot API and this is not currently fully supported by Chromium OS firmware. Signed-off-by: Simon Glass --- cmd/cros_ec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c index fb369a4e329..3ac4f3b235d 100644 --- a/cmd/cros_ec.c +++ b/cmd/cros_ec.c @@ -27,7 +27,7 @@ static int cros_ec_decode_region(int argc, char * const argv[]) { if (argc > 0) { if (0 == strcmp(*argv, "rw")) - return EC_FLASH_REGION_RW; + return EC_FLASH_REGION_ACTIVE; else if (0 == strcmp(*argv, "ro")) return EC_FLASH_REGION_RO; @@ -137,7 +137,6 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } printf("rows = %u\n", info.rows); printf("cols = %u\n", info.cols); - printf("switches = %#x\n", info.switches); } else if (0 == strcmp("curimage", cmd)) { enum ec_current_image image; @@ -177,7 +176,7 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) region = cros_ec_decode_region(argc - 2, argv + 2); if (region == EC_FLASH_REGION_RO) cmd = EC_REBOOT_JUMP_RO; - else if (region == EC_FLASH_REGION_RW) + else if (region == EC_FLASH_REGION_ACTIVE) cmd = EC_REBOOT_JUMP_RW; else return CMD_RET_USAGE; -- cgit v1.2.3 From 590cee8315e94e729493d2ecd8a604bcfbfa7d0e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:37 -0600 Subject: x86: Update mtrr functions to allow leaving cache alone At present the mtrr functions disable the cache before making changes and enable it again afterwards. This is fine in U-Boot, but does not work if running in CAR (such as we are in SPL). Update the functions so that the caller can request that caches be left alone. Signed-off-by: Simon Glass Reviewed-by: Bin Meng --- cmd/x86/mtrr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cmd') diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c index 70f373a72a5..d3fd959235f 100644 --- a/cmd/x86/mtrr.c +++ b/cmd/x86/mtrr.c @@ -73,10 +73,10 @@ static int do_mtrr_set(uint reg, int argc, char * const argv[]) mask |= MTRR_PHYS_MASK_VALID; printf("base=%llx, mask=%llx\n", base, mask); - mtrr_open(&state); + mtrr_open(&state, true); wrmsrl(MTRR_PHYS_BASE_MSR(reg), base); wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask); - mtrr_close(&state); + mtrr_close(&state, true); return 0; } @@ -86,14 +86,14 @@ static int mtrr_set_valid(int reg, bool valid) struct mtrr_state state; uint64_t mask; - mtrr_open(&state); + mtrr_open(&state, true); mask = native_read_msr(MTRR_PHYS_MASK_MSR(reg)); if (valid) mask |= MTRR_PHYS_MASK_VALID; else mask &= ~MTRR_PHYS_MASK_VALID; wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask); - mtrr_close(&state); + mtrr_close(&state, true); return 0; } -- cgit v1.2.3 From a12ef7e26a69213869badc02c0f3267816200024 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 1 Oct 2018 12:22:38 -0600 Subject: cros_ec: Update cros_ec_read_hash() to specify the image Allow selection of which EC image to hash. Signed-off-by: Simon Glass --- cmd/cros_ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/cros_ec.c b/cmd/cros_ec.c index 3ac4f3b235d..9e2f1b06f3c 100644 --- a/cmd/cros_ec.c +++ b/cmd/cros_ec.c @@ -149,7 +149,7 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) struct ec_response_vboot_hash hash; int i; - if (cros_ec_read_hash(dev, &hash)) { + if (cros_ec_read_hash(dev, EC_VBOOT_HASH_OFFSET_ACTIVE, &hash)) { debug("%s: Could not read KBC hash\n", __func__); return 1; } -- cgit v1.2.3