Toyomasa Watarai / simple-mbed-cloud-client

Dependents:  

Committer:
MACRUM
Date:
Mon Jul 02 06:30:39 2018 +0000
Revision:
0:276e7a263c35
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:276e7a263c35 1 // ----------------------------------------------------------------------------
MACRUM 0:276e7a263c35 2 // Copyright 2016-2017 ARM Ltd.
MACRUM 0:276e7a263c35 3 //
MACRUM 0:276e7a263c35 4 // SPDX-License-Identifier: Apache-2.0
MACRUM 0:276e7a263c35 5 //
MACRUM 0:276e7a263c35 6 // Licensed under the Apache License, Version 2.0 (the "License");
MACRUM 0:276e7a263c35 7 // you may not use this file except in compliance with the License.
MACRUM 0:276e7a263c35 8 // You may obtain a copy of the License at
MACRUM 0:276e7a263c35 9 //
MACRUM 0:276e7a263c35 10 // http://www.apache.org/licenses/LICENSE-2.0
MACRUM 0:276e7a263c35 11 //
MACRUM 0:276e7a263c35 12 // Unless required by applicable law or agreed to in writing, software
MACRUM 0:276e7a263c35 13 // distributed under the License is distributed on an "AS IS" BASIS,
MACRUM 0:276e7a263c35 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 0:276e7a263c35 15 // See the License for the specific language governing permissions and
MACRUM 0:276e7a263c35 16 // limitations under the License.
MACRUM 0:276e7a263c35 17 // ----------------------------------------------------------------------------
MACRUM 0:276e7a263c35 18
MACRUM 0:276e7a263c35 19 #include "arm_uc_mmCommon.h"
MACRUM 0:276e7a263c35 20 #include "arm_uc_mmConfig.h"
MACRUM 0:276e7a263c35 21 #include "arm_uc_mmStateSelector.h"
MACRUM 0:276e7a263c35 22 #include "arm_uc_mmInit.h"
MACRUM 0:276e7a263c35 23
MACRUM 0:276e7a263c35 24 #include "update-client-manifest-manager/update-client-manifest-manager.h"
MACRUM 0:276e7a263c35 25 #include "update-client-manifest-manager/update-client-manifest-manager-context.h"
MACRUM 0:276e7a263c35 26 #include "update-client-manifest-manager/update-client-manifest-types.h"
MACRUM 0:276e7a263c35 27 #include "update-client-manifest-manager/arm-pal-kv.h"
MACRUM 0:276e7a263c35 28
MACRUM 0:276e7a263c35 29 #include "update-client-common/arm_uc_scheduler.h"
MACRUM 0:276e7a263c35 30 #include "update-client-common/arm_uc_utilities.h"
MACRUM 0:276e7a263c35 31 #include "update-client-common/arm_uc_error.h"
MACRUM 0:276e7a263c35 32
MACRUM 0:276e7a263c35 33 #include <stdint.h>
MACRUM 0:276e7a263c35 34 #include <stdio.h>
MACRUM 0:276e7a263c35 35 #include <stddef.h>
MACRUM 0:276e7a263c35 36 #include <string.h>
MACRUM 0:276e7a263c35 37
MACRUM 0:276e7a263c35 38 /**
MACRUM 0:276e7a263c35 39 * @file manifest_manager.c
MACRUM 0:276e7a263c35 40 * @brief Manifest Manager API
MACRUM 0:276e7a263c35 41 * @details This file specifies the API used to interact with the manifest manager
MACRUM 0:276e7a263c35 42 */
MACRUM 0:276e7a263c35 43
MACRUM 0:276e7a263c35 44 arm_uc_error_t ARM_UC_mmInit(arm_uc_mmContext_t** mmCtx, void (*event_handler)(uint32_t), const arm_pal_key_value_api* api)
MACRUM 0:276e7a263c35 45 {
MACRUM 0:276e7a263c35 46 arm_uc_error_t err = {MFST_ERR_NONE};
MACRUM 0:276e7a263c35 47 if (mmCtx == NULL || *mmCtx == NULL)
MACRUM 0:276e7a263c35 48 {
MACRUM 0:276e7a263c35 49 return (arm_uc_error_t){MFST_ERR_NULL_PTR};
MACRUM 0:276e7a263c35 50 }
MACRUM 0:276e7a263c35 51
MACRUM 0:276e7a263c35 52 arm_uc_mmPersistentContext.ctx = mmCtx;
MACRUM 0:276e7a263c35 53 arm_uc_mmPersistentContext.applicationEventHandler = event_handler;
MACRUM 0:276e7a263c35 54 arm_uc_mmPersistentContext.testFSM = NULL;
MACRUM 0:276e7a263c35 55
MACRUM 0:276e7a263c35 56 // initialize callback node
MACRUM 0:276e7a263c35 57 arm_uc_mmPersistentContext.applicationCallbackStorage.lock = 0;
MACRUM 0:276e7a263c35 58
MACRUM 0:276e7a263c35 59 ARM_UC_PostCallback(&arm_uc_mmPersistentContext.applicationCallbackStorage, event_handler, ARM_UC_MM_RC_DONE);
MACRUM 0:276e7a263c35 60 // This code will be re-enabled when storage is available
MACRUM 0:276e7a263c35 61 #if 0
MACRUM 0:276e7a263c35 62 ARM_UC_mmCfStoreInit(api);
MACRUM 0:276e7a263c35 63
MACRUM 0:276e7a263c35 64 // Initialize the Init FSM
MACRUM 0:276e7a263c35 65 arm_uc_mmContext_t* ctx = *mmCtx;
MACRUM 0:276e7a263c35 66 ctx->init.state = ARM_UC_MM_INIT_BEGIN;
MACRUM 0:276e7a263c35 67
MACRUM 0:276e7a263c35 68 err = ARM_UC_mmSetState(ARM_UC_MM_STATE_INIT);
MACRUM 0:276e7a263c35 69 if (err.code != MFST_ERR_NONE)
MACRUM 0:276e7a263c35 70 {
MACRUM 0:276e7a263c35 71 return err;
MACRUM 0:276e7a263c35 72 }
MACRUM 0:276e7a263c35 73 // Start the Init FSM
MACRUM 0:276e7a263c35 74 ARM_UC_PostCallback(&ctx->init.callbackStorage, ARM_UC_mmCallbackFSMEntry, ARM_UC_MM_EVENT_BEGIN);
MACRUM 0:276e7a263c35 75 #endif
MACRUM 0:276e7a263c35 76 return err;
MACRUM 0:276e7a263c35 77 }
MACRUM 0:276e7a263c35 78
MACRUM 0:276e7a263c35 79 arm_uc_error_t ARM_UC_mmInsert(arm_uc_mmContext_t** ctx, arm_uc_buffer_t* buffer, arm_uc_buffer_t* certificateStorage, arm_uc_manifest_handle_t* ID)
MACRUM 0:276e7a263c35 80 {
MACRUM 0:276e7a263c35 81 if (ctx == NULL || *ctx == NULL || buffer == NULL )
MACRUM 0:276e7a263c35 82 {
MACRUM 0:276e7a263c35 83 return (arm_uc_error_t){MFST_ERR_NULL_PTR};
MACRUM 0:276e7a263c35 84 }
MACRUM 0:276e7a263c35 85 arm_uc_mmPersistentContext.ctx = ctx;
MACRUM 0:276e7a263c35 86 // Setup the state machine
MACRUM 0:276e7a263c35 87 arm_uc_error_t err = ARM_UC_mmSetState(ARM_UC_MM_STATE_INSERTING);
MACRUM 0:276e7a263c35 88 if (err.code != MFST_ERR_NONE)
MACRUM 0:276e7a263c35 89 {
MACRUM 0:276e7a263c35 90 return err;
MACRUM 0:276e7a263c35 91 }
MACRUM 0:276e7a263c35 92 struct arm_uc_mmInsertContext_t* insertCtx = &(*arm_uc_mmPersistentContext.ctx)->insert;
MACRUM 0:276e7a263c35 93 // Store the buffer pointer
MACRUM 0:276e7a263c35 94 ARM_UC_buffer_shallow_copy(&insertCtx->manifest, buffer);
MACRUM 0:276e7a263c35 95 insertCtx->state = ARM_UC_MM_INS_STATE_BEGIN;
MACRUM 0:276e7a263c35 96 // Store the ID pointer
MACRUM 0:276e7a263c35 97 insertCtx->ID = ID;
MACRUM 0:276e7a263c35 98 // Store the certificate buffer
MACRUM 0:276e7a263c35 99 ARM_UC_buffer_shallow_copy(&insertCtx->certificateStorage, certificateStorage);
MACRUM 0:276e7a263c35 100
MACRUM 0:276e7a263c35 101 // initialize callback node
MACRUM 0:276e7a263c35 102 insertCtx->callbackStorage.lock = 0;
MACRUM 0:276e7a263c35 103
MACRUM 0:276e7a263c35 104 // Start the FSM
MACRUM 0:276e7a263c35 105 ARM_UC_PostCallback(&insertCtx->callbackStorage, ARM_UC_mmCallbackFSMEntry, ARM_UC_MM_EVENT_BEGIN);
MACRUM 0:276e7a263c35 106 return (arm_uc_error_t){MFST_ERR_NONE};
MACRUM 0:276e7a263c35 107 }
MACRUM 0:276e7a263c35 108 arm_uc_error_t ARM_UC_mmFetchFirmwareInfo(arm_uc_mmContext_t** ctx, struct manifest_firmware_info_t* info, const arm_uc_manifest_handle_t* ID)
MACRUM 0:276e7a263c35 109 {
MACRUM 0:276e7a263c35 110 if (ctx == NULL || *ctx == NULL || info == NULL )
MACRUM 0:276e7a263c35 111 {
MACRUM 0:276e7a263c35 112 return (arm_uc_error_t){MFST_ERR_NULL_PTR};
MACRUM 0:276e7a263c35 113 }
MACRUM 0:276e7a263c35 114 arm_uc_mmPersistentContext.ctx = ctx;
MACRUM 0:276e7a263c35 115 // Initialize the state machine
MACRUM 0:276e7a263c35 116 arm_uc_error_t err = ARM_UC_mmSetState(ARM_UC_MM_STATE_FWINFO);
MACRUM 0:276e7a263c35 117 if (err.code != MFST_ERR_NONE)
MACRUM 0:276e7a263c35 118 {
MACRUM 0:276e7a263c35 119 return err;
MACRUM 0:276e7a263c35 120 }
MACRUM 0:276e7a263c35 121 struct arm_uc_mm_fw_context_t* fwCtx = &(*arm_uc_mmPersistentContext.ctx)->getFw;
MACRUM 0:276e7a263c35 122 fwCtx->state = ARM_UC_MM_FW_STATE_BEGIN;
MACRUM 0:276e7a263c35 123 fwCtx->info = info;
MACRUM 0:276e7a263c35 124
MACRUM 0:276e7a263c35 125 // initialize callback node
MACRUM 0:276e7a263c35 126 fwCtx->callbackStorage.lock = 0;
MACRUM 0:276e7a263c35 127
MACRUM 0:276e7a263c35 128 // Start the state machine
MACRUM 0:276e7a263c35 129 ARM_UC_PostCallback(&fwCtx->callbackStorage, ARM_UC_mmCallbackFSMEntry, ARM_UC_MM_EVENT_BEGIN);
MACRUM 0:276e7a263c35 130
MACRUM 0:276e7a263c35 131 return (arm_uc_error_t){MFST_ERR_NONE};
MACRUM 0:276e7a263c35 132 }
MACRUM 0:276e7a263c35 133 arm_uc_error_t ARM_UC_mmFetchNextFirmwareInfo(struct manifest_firmware_info_t* info)
MACRUM 0:276e7a263c35 134 {
MACRUM 0:276e7a263c35 135 struct arm_uc_mm_fw_context_t* fwCtx = &(*arm_uc_mmPersistentContext.ctx)->getFw;
MACRUM 0:276e7a263c35 136 fwCtx->info = info;
MACRUM 0:276e7a263c35 137
MACRUM 0:276e7a263c35 138 // initialize callback node
MACRUM 0:276e7a263c35 139 fwCtx->callbackStorage.lock = 0;
MACRUM 0:276e7a263c35 140
MACRUM 0:276e7a263c35 141 // Continue the state machine
MACRUM 0:276e7a263c35 142 ARM_UC_PostCallback(&fwCtx->callbackStorage, ARM_UC_mmCallbackFSMEntry, ARM_UC_MM_EVENT_BEGIN);
MACRUM 0:276e7a263c35 143 return (arm_uc_error_t){MFST_ERR_NONE};
MACRUM 0:276e7a263c35 144 }
MACRUM 0:276e7a263c35 145 arm_uc_error_t ARM_UC_mmGetError()
MACRUM 0:276e7a263c35 146 {
MACRUM 0:276e7a263c35 147 return arm_uc_mmPersistentContext.reportedError;
MACRUM 0:276e7a263c35 148 }
MACRUM 0:276e7a263c35 149
MACRUM 0:276e7a263c35 150 #if ARM_UC_MM_ENABLE_TEST_VECTORS
MACRUM 0:276e7a263c35 151 arm_uc_error_t ARM_UC_mmRegisterTestHook(ARM_UC_mmTestHook_t hook)
MACRUM 0:276e7a263c35 152 {
MACRUM 0:276e7a263c35 153 arm_uc_error_t err = {MFST_ERR_NONE};
MACRUM 0:276e7a263c35 154 arm_uc_mmPersistentContext.testHook = hook;
MACRUM 0:276e7a263c35 155 return err;
MACRUM 0:276e7a263c35 156 }
MACRUM 0:276e7a263c35 157 #endif