Dependencies:   MMA7660 LM75B

Committer:
MACRUM
Date:
Sat Jun 30 01:40:30 2018 +0000
Revision:
0:119624335925
Initial commit

Who changed what in which revision?

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