DM: Enable full 4MB access

A simulated rpmbfile requires to enable 4MB access by writing
the last byte.
Otherwise, the read operation should be failed if no write
was operated on the address greater than the read address.
Writing the last byte during file creating ensures the whole
4MB address is readable.

Signed-off-by: Huang Yang <yang.huang@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
This commit is contained in:
Huang, Yang 2018-05-27 15:46:37 -04:00 committed by lijinxia
parent dc566ab3ac
commit 113ece2854

View File

@ -108,25 +108,6 @@ err:
return hmac_ret ? 0 : -1;
}
static int rpmb_sim_open(const char *rpmb_devname)
{
rpmb_fd = fopen(rpmb_devname, "rb+");
if (rpmb_fd == NULL) {
/*if the rpmb device file does not exist, create a new file*/
rpmb_fd = fopen(rpmb_devname, "wb+");
DPRINTF(("rpmb device file(%s) does not exist, create a new file\n", rpmb_devname));
}
if (rpmb_fd == NULL) {
DPRINTF(("%s: unable (%d) to open rpmb device '%s': %s\n",
__func__, errno, rpmb_devname, strerror(errno)));
return -1;
}
return 0;
}
static void rpmb_sim_close(void)
{
fclose(rpmb_fd);
@ -171,6 +152,31 @@ static int file_read(FILE *fp, void *buf, size_t size, off_t offset)
}
}
static int rpmb_sim_open(const char *rpmb_devname)
{
uint8_t data = 0;
rpmb_fd = fopen(rpmb_devname, "rb+");
if (rpmb_fd == NULL) {
/*if the rpmb device file does not exist, create a new file*/
rpmb_fd = fopen(rpmb_devname, "wb+");
DPRINTF(("rpmb device file(%s) does not exist, create a new file\n", rpmb_devname));
/* Write 0 to the last byte to enable 4MB length access */
if (file_write(rpmb_fd, &data, 1, TEEDATA_SIZE - 1) < 0) {
DPRINTF(("Failed to initialize simulated rpmb to 0.\n"));
rpmb_fd = NULL;
}
}
if (rpmb_fd == NULL) {
DPRINTF(("%s: unable (%d) to open rpmb device '%s': %s\n",
__func__, errno, rpmb_devname, strerror(errno)));
return -1;
}
return 0;
}
static int get_counter(uint32_t *counter)
{
int rc = 0;