Skip to content

Commit b8c1fd6

Browse files
binbinwu1lijinxia
authored andcommitted
dm: pass vrpmb key via cmos interface
CMOS offset from 0x20 to 0x9F is used to store rpmb key information. vsbl loader will init vrpmb key in CMOS when boot/reboot. vsbl loader will not init vrpmb key during S3 resume. vsbl will read vrpmb key via CMOS interface. After reading, the key value is cleared in CMOS. So the key can only be read once until next boot. Signed-off-by: Binbin Wu <binbin.wu@intel.com> Acked-by: Yin Fengwei <fengwei.yin@intel.com>
1 parent c8c0e10 commit b8c1fd6

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

devicemodel/core/sw_load_vsbl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ static int vsbl_size;
112112

113113
static int boot_blk_bdf;
114114

115+
extern int init_cmos_vrpmb(struct vmctx *ctx);
116+
115117
#define LOW_8BIT(x) ((x) & 0xFF)
116118
void
117119
vsbl_set_bdf(int bnum, int snum, int fnum)
@@ -250,6 +252,7 @@ acrn_sw_load_vsbl(struct vmctx *ctx)
250252
uint64_t *cfg_offset =
251253
(uint64_t *)(ctx->baseaddr + GUEST_CFG_OFFSET);
252254

255+
init_cmos_vrpmb(ctx);
253256
*cfg_offset = ctx->lowmem;
254257

255258
vsbl_para = (struct vsbl_para *)

devicemodel/hw/platform/cmos_io.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@
2121
* writing.
2222
*************************************************************************/
2323

24-
/* cmos io device is used for android device reboot to bootloader or
25-
* recovery or normal boot usage
24+
/* cmos io device
25+
* - nvram 0x10 ~ 0x1F is used for android device reboot to bootloader or
26+
* recovery or normal boot usage
27+
* - vrpmb 0x20 ~ 0x9F is used to store vrpmb for guest, read to clear
2628
*/
2729

2830
#include <stdio.h>
2931
#include <assert.h>
32+
#include <stdbool.h>
3033

3134
#include "inout.h"
35+
#include "vmmapi.h"
36+
#include "vrpmb.h"
3237

3338
#define CMOS_ADDR 0x74
3439
#define CMOS_DATA 0x75
35-
#define CMOS_BUF_SIZE 256
3640

3741
#define CMOS_NAME "cmos_io"
42+
#define CMOS_VRPMB_START 0x20
43+
#define CMOS_VRPMB_END 0x9F
3844

3945
/* #define CMOS_DEBUG */
4046
#ifdef CMOS_DEBUG
@@ -45,11 +51,6 @@ do { fprintf(dbg_file, format, args); fflush(dbg_file); } while (0)
4551
#define DPRINTF(format, arg...)
4652
#endif
4753

48-
/* cmos buffer used to store write/read contents,
49-
* and it should not be cleared when reboot
50-
*/
51-
static uint8_t cmos_buffer[CMOS_BUF_SIZE];
52-
5354
static int
5455
cmos_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
5556
uint32_t *eax, void *arg)
@@ -88,10 +89,15 @@ cmos_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
8889
return -1;
8990
}
9091

91-
if (in)
92-
*eax = cmos_buffer[buf_offset];
92+
if (in) {
93+
*eax = ctx->cmos_buffer[buf_offset];
94+
/* read to clear for Key range */
95+
if ((buf_offset >= CMOS_VRPMB_START) ||
96+
(buf_offset <= CMOS_VRPMB_END))
97+
ctx->cmos_buffer[buf_offset] = 0;
98+
}
9399
else
94-
cmos_buffer[buf_offset] = (uint8_t)*eax;
100+
ctx->cmos_buffer[buf_offset] = (uint8_t)*eax;
95101

96102
next_ops = 0;
97103
}
@@ -101,3 +107,15 @@ cmos_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
101107

102108
INOUT_PORT(cmos_io, CMOS_ADDR, IOPORT_F_INOUT, cmos_io_handler);
103109
INOUT_PORT(cmos_io, CMOS_DATA, IOPORT_F_INOUT, cmos_io_handler);
110+
111+
int init_cmos_vrpmb(struct vmctx *ctx)
112+
{
113+
uint8_t *vrpmb_buffer = &ctx->cmos_buffer[CMOS_VRPMB_START];
114+
115+
/* get vrpmb key, and store it to cmos buffer */
116+
if (!get_vrpmb_key(vrpmb_buffer, RPMB_KEY_LEN)) {
117+
printf("SW_LOAD: failed to get vrpmb key\n");
118+
return -1;
119+
}
120+
return 0;
121+
}

devicemodel/include/vmmapi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#define ALIGN_UP(x, align) (((x) + ((align)-1)) & ~((align)-1))
4646
#define ALIGN_DOWN(x, align) ((x) & ~((align)-1))
4747

48+
#define CMOS_BUF_SIZE 256
49+
4850
struct vmctx {
4951
int fd;
5052
int vmid;
@@ -61,6 +63,10 @@ struct vmctx {
6163
void *atkbdc_base;
6264
void *vrtc;
6365
void *ioc_dev;
66+
/* cmos buffer used to store write/read contents,
67+
* and it should not be cleared when reboot
68+
*/
69+
uint8_t cmos_buffer[CMOS_BUF_SIZE];
6470
};
6571

6672
/*

0 commit comments

Comments
 (0)