static int command_hash(int argc, char **argv) { uint32_t offset = CONFIG_FW_RW_OFF; uint32_t size = CONFIG_FW_RW_SIZE; char *e; if (argc == 1) { ccprintf("Offset: 0x%08x\n", data_offset); ccprintf("Size: 0x%08x (%d)\n", data_size, data_size); ccprintf("Digest: "); if (want_abort) ccprintf("(aborting)\n"); else if (in_progress) ccprintf("(in progress)\n"); else if (hash) ccprintf("%.*h\n", SHA256_DIGEST_SIZE, hash); else ccprintf("(invalid)\n"); return EC_SUCCESS; } if (argc == 2) { if (!strcasecmp(argv[1], "abort")) { vboot_hash_abort(); return EC_SUCCESS; } else if (!strcasecmp(argv[1], "rw")) { return vboot_hash_start( CONFIG_FW_RW_OFF, system_get_image_used(SYSTEM_IMAGE_RW), NULL, 0); } else if (!strcasecmp(argv[1], "ro")) { return vboot_hash_start( CONFIG_FW_RO_OFF, system_get_image_used(SYSTEM_IMAGE_RO), NULL, 0); } } if (argc >= 3) { offset = strtoi(argv[1], &e, 0); if (*e) return EC_ERROR_PARAM1; size = strtoi(argv[2], &e, 0); if (*e) return EC_ERROR_PARAM2; } if (argc == 4) { int nonce = strtoi(argv[3], &e, 0); if (*e) return EC_ERROR_PARAM3; return vboot_hash_start(offset, size, (const uint8_t *)&nonce, sizeof(nonce)); } else return vboot_hash_start(offset, size, NULL, 0); }
/** * Start computing a hash, with sanity checking on params. * * @return EC_RES_SUCCESS if success, or other result code on error. */ static int host_start_hash(const struct ec_params_vboot_hash *p) { int offset = p->offset; int size = p->size; int rv; /* Sanity-check input params */ if (p->hash_type != EC_VBOOT_HASH_TYPE_SHA256) return EC_RES_INVALID_PARAM; if (p->nonce_size > sizeof(p->nonce_data)) return EC_RES_INVALID_PARAM; /* Handle special offset values */ if (offset == EC_VBOOT_HASH_OFFSET_RO) { offset = CONFIG_FW_RO_OFF; size = system_get_image_used(SYSTEM_IMAGE_RO); } else if (p->offset == EC_VBOOT_HASH_OFFSET_RW) { offset = CONFIG_FW_RW_OFF; size = system_get_image_used(SYSTEM_IMAGE_RW); } rv = vboot_hash_start(offset, size, p->nonce_data, p->nonce_size); if (rv == EC_SUCCESS) return EC_RES_SUCCESS; else if (rv == EC_ERROR_INVAL) return EC_RES_INVALID_PARAM; else return EC_RES_ERROR; }
static void vboot_hash_init(void) { #ifdef CONFIG_SAVE_VBOOT_HASH const struct vboot_hash_tag *tag; int version, size; tag = (const struct vboot_hash_tag *)system_get_jump_tag( VBOOT_HASH_SYSJUMP_TAG, &version, &size); if (tag && version == VBOOT_HASH_SYSJUMP_VERSION && size == sizeof(*tag)) { /* Already computed a hash, so don't recompute */ CPRINTS("hash precomputed"); hash = tag->hash; data_offset = tag->offset; data_size = tag->size; } else #endif { /* Start computing the hash of RW firmware */ vboot_hash_start(CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF, system_get_image_used(SYSTEM_IMAGE_RW), NULL, 0); } }