lib: optee_client: recover original partition after error

1.switch to RPMB partition when call init rpmb
2.switch to original partition when call finish rpmb
3.it will not switch to original partition when error
  occurred, we should recover original partition after error

Change-Id: I41927e82fb2db690058a809f008ca1f59d334011
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
This commit is contained in:
Hisping Lin 2019-01-22 19:25:40 +08:00 committed by Jianhong Chen
parent df99e5808c
commit 68ba937304
1 changed files with 11 additions and 18 deletions

View File

@ -312,8 +312,7 @@ TEEC_Result OpteeRpcCmdRpmb(t_teesmc32_arg *TeeSmc32Arg)
switch (RequestMsgType) { switch (RequestMsgType) {
case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_KEY_PROGRAM: { case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_KEY_PROGRAM: {
EfiStatus = init_rpmb(); if (init_rpmb() != 0) {
if (EfiStatus != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
} }
@ -321,12 +320,11 @@ TEEC_Result OpteeRpcCmdRpmb(t_teesmc32_arg *TeeSmc32Arg)
EfiStatus = do_programkey((struct s_rpmb *) EfiStatus = do_programkey((struct s_rpmb *)
RequestPackets_back); RequestPackets_back);
if (EfiStatus != 0) { if (finish_rpmb() != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
} }
EfiStatus = finish_rpmb();
if (EfiStatus != 0) { if (EfiStatus != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
@ -336,20 +334,19 @@ TEEC_Result OpteeRpcCmdRpmb(t_teesmc32_arg *TeeSmc32Arg)
} }
case TEE_RPC_RPMB_MSG_TYPE_REQ_WRITE_COUNTER_VAL_READ: { case TEE_RPC_RPMB_MSG_TYPE_REQ_WRITE_COUNTER_VAL_READ: {
EfiStatus = init_rpmb(); if (init_rpmb() != 0) {
if (EfiStatus != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
} }
EfiStatus = do_readcounter((struct s_rpmb *) EfiStatus = do_readcounter((struct s_rpmb *)
RequestPackets_back); RequestPackets_back);
if (EfiStatus != 0) {
if (finish_rpmb() != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
} }
EfiStatus = finish_rpmb();
if (EfiStatus != 0) { if (EfiStatus != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
@ -359,21 +356,19 @@ TEEC_Result OpteeRpcCmdRpmb(t_teesmc32_arg *TeeSmc32Arg)
} }
case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_DATA_WRITE: { case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_DATA_WRITE: {
EfiStatus = init_rpmb(); if (init_rpmb() != 0) {
if (EfiStatus != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
} }
EfiStatus = do_authenticatedwrite((struct s_rpmb *) EfiStatus = do_authenticatedwrite((struct s_rpmb *)
RequestPackets_back); RequestPackets_back);
if (EfiStatus != 0) {
if (finish_rpmb() != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
} }
EfiStatus = finish_rpmb();
if (EfiStatus != 0) { if (EfiStatus != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
@ -383,21 +378,19 @@ TEEC_Result OpteeRpcCmdRpmb(t_teesmc32_arg *TeeSmc32Arg)
} }
case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_DATA_READ: { case TEE_RPC_RPMB_MSG_TYPE_REQ_AUTH_DATA_READ: {
EfiStatus = init_rpmb(); if (init_rpmb() != 0) {
if (EfiStatus != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
} }
EfiStatus = do_authenticatedread((struct s_rpmb *) EfiStatus = do_authenticatedread((struct s_rpmb *)
RequestPackets_back, global_block_count); RequestPackets_back, global_block_count);
if (EfiStatus != 0) {
if (finish_rpmb() != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;
} }
EfiStatus = finish_rpmb();
if (EfiStatus != 0) { if (EfiStatus != 0) {
TeecResult = TEEC_ERROR_GENERIC; TeecResult = TEEC_ERROR_GENERIC;
break; break;