static void process_start(TPM_ALG_ID alg, int handle, void *response_body, size_t *response_size) { uint8_t *response = response_body; struct test_context *new_context; if (find_context(handle)) { *response = EXC_HASH_DUPLICATED_HANDLE; *response_size = 1; return; } if (!hash_test_db.max_contexts) { /* Check how many contexts could possible fit. */ hash_test_db.max_contexts = shared_mem_size() / sizeof(struct test_context); } if (!hash_test_db.contexts) shared_mem_acquire(shared_mem_size(), (char **)&hash_test_db.contexts); if (!hash_test_db.contexts || (hash_test_db.current_context_count == hash_test_db.max_contexts)) { *response = EXC_HASH_TOO_MANY_HANDLES; *response_size = 1; return; } new_context = hash_test_db.contexts + hash_test_db.current_context_count++; new_context->context_handle = handle; _cpri__StartHash(alg, 0, &new_context->hstate); }
static int command_flash_write(int argc, char **argv) { int offset = -1; int size = CONFIG_FLASH_ERASE_SIZE; int rv; char *data; int i; if (flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) return EC_ERROR_ACCESS_DENIED; rv = parse_offset_size(argc, argv, 1, &offset, &size); if (rv) return rv; if (size > shared_mem_size()) size = shared_mem_size(); /* Acquire the shared memory buffer */ rv = shared_mem_acquire(size, &data); if (rv) { ccputs("Can't get shared mem\n"); return rv; } /* Fill the data buffer with a pattern */ for (i = 0; i < size; i++) data[i] = i; ccprintf("Writing %d bytes to 0x%x...\n", size, offset, offset); rv = flash_write(offset, size, data); /* Free the buffer */ shared_mem_release(data); return rv; }