Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
manifest-manager-api.c
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2017 ARM Ltd. 00003 // 00004 // SPDX-License-Identifier: Apache-2.0 00005 // 00006 // Licensed under the Apache License, Version 2.0 (the "License"); 00007 // you may not use this file except in compliance with the License. 00008 // You may obtain a copy of the License at 00009 // 00010 // http://www.apache.org/licenses/LICENSE-2.0 00011 // 00012 // Unless required by applicable law or agreed to in writing, software 00013 // distributed under the License is distributed on an "AS IS" BASIS, 00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 // See the License for the specific language governing permissions and 00016 // limitations under the License. 00017 // ---------------------------------------------------------------------------- 00018 00019 #include "arm_uc_mmCommon.h" 00020 #include "arm_uc_mmConfig.h" 00021 #include "arm_uc_mmStateSelector.h" 00022 #include "arm_uc_mmInit.h" 00023 00024 #include "update-client-manifest-manager/update-client-manifest-manager.h" 00025 #include "update-client-manifest-manager/update-client-manifest-manager-context.h" 00026 #include "update-client-manifest-manager/update-client-manifest-types.h" 00027 #include "update-client-manifest-manager/arm-pal-kv.h" 00028 00029 #include "update-client-common/arm_uc_scheduler.h" 00030 #include "update-client-common/arm_uc_utilities.h" 00031 #include "update-client-common/arm_uc_error.h" 00032 00033 #include <stdint.h> 00034 #include <stdio.h> 00035 #include <stddef.h> 00036 #include <string.h> 00037 00038 /** 00039 * @file manifest_manager.c 00040 * @brief Manifest Manager API 00041 * @details This file specifies the API used to interact with the manifest manager 00042 */ 00043 00044 arm_uc_error_t ARM_UC_mmInit(arm_uc_mmContext_t **mmCtx, void (*event_handler)(uintptr_t), 00045 const arm_pal_key_value_api *api) 00046 { 00047 arm_uc_error_t err = {ERR_NONE}; 00048 if (mmCtx == NULL || *mmCtx == NULL) { 00049 return (arm_uc_error_t) {MFST_ERR_NULL_PTR}; 00050 } 00051 00052 arm_uc_mmPersistentContext.ctx = mmCtx; 00053 arm_uc_mmPersistentContext.applicationEventHandler = event_handler; 00054 arm_uc_mmPersistentContext.testFSM = NULL; 00055 00056 // initialize callback node 00057 arm_uc_mmPersistentContext.applicationCallbackStorage.lock = 0; 00058 00059 ARM_UC_PostCallback(&arm_uc_mmPersistentContext.applicationCallbackStorage, event_handler, ARM_UC_MM_RC_DONE); 00060 // This code will be re-enabled when storage is available 00061 #if 0 00062 ARM_UC_mmCfStoreInit(api); 00063 00064 // Initialize the Init FSM 00065 arm_uc_mmContext_t *ctx = *mmCtx; 00066 ctx->init.state = ARM_UC_MM_INIT_BEGIN; 00067 00068 err = ARM_UC_mmSetState(ARM_UC_MM_STATE_INIT); 00069 if (err.code != ERR_NONE) { 00070 return err; 00071 } 00072 // Start the Init FSM 00073 ARM_UC_PostCallback(&ctx->init.callbackStorage, ARM_UC_mmCallbackFSMEntry, ARM_UC_MM_EVENT_BEGIN); 00074 #endif 00075 return err; 00076 } 00077 00078 arm_uc_error_t ARM_UC_mmInsert(arm_uc_mmContext_t **ctx, arm_uc_buffer_t *buffer, arm_uc_buffer_t *certificateStorage, 00079 arm_uc_manifest_handle_t *ID) 00080 { 00081 if (ctx == NULL || *ctx == NULL || buffer == NULL) { 00082 return (arm_uc_error_t) {MFST_ERR_NULL_PTR}; 00083 } 00084 arm_uc_mmPersistentContext.ctx = ctx; 00085 // Setup the state machine 00086 arm_uc_error_t err = ARM_UC_mmSetState(ARM_UC_MM_STATE_INSERTING); 00087 if (err.code != ERR_NONE) { 00088 return err; 00089 } 00090 struct arm_uc_mmInsertContext_t *insertCtx = &(*arm_uc_mmPersistentContext.ctx)->insert; 00091 // Store the buffer pointer 00092 ARM_UC_buffer_shallow_copy(&insertCtx->manifest, buffer); 00093 insertCtx->state = ARM_UC_MM_INS_STATE_BEGIN; 00094 // Store the ID pointer 00095 insertCtx->ID = ID; 00096 // Store the certificate buffer 00097 ARM_UC_buffer_shallow_copy(&insertCtx->certificateStorage, certificateStorage); 00098 00099 // initialize callback node 00100 insertCtx->callbackStorage.lock = 0; 00101 00102 // Start the FSM 00103 ARM_UC_PostCallback(&insertCtx->callbackStorage, ARM_UC_mmCallbackFSMEntry, ARM_UC_MM_EVENT_BEGIN); 00104 return (arm_uc_error_t) {ERR_NONE}; 00105 } 00106 arm_uc_error_t ARM_UC_mmFetchFirmwareInfo(arm_uc_mmContext_t **ctx, struct manifest_firmware_info_t *info, 00107 const arm_uc_manifest_handle_t *ID) 00108 { 00109 if (ctx == NULL || *ctx == NULL || info == NULL) { 00110 return (arm_uc_error_t) {MFST_ERR_NULL_PTR}; 00111 } 00112 arm_uc_mmPersistentContext.ctx = ctx; 00113 // Initialize the state machine 00114 arm_uc_error_t err = ARM_UC_mmSetState(ARM_UC_MM_STATE_FWINFO); 00115 if (err.code != ERR_NONE) { 00116 return err; 00117 } 00118 struct arm_uc_mm_fw_context_t *fwCtx = &(*arm_uc_mmPersistentContext.ctx)->getFw; 00119 fwCtx->state = ARM_UC_MM_FW_STATE_BEGIN; 00120 fwCtx->info = info; 00121 00122 // initialize callback node 00123 fwCtx->callbackStorage.lock = 0; 00124 00125 // Start the state machine 00126 ARM_UC_PostCallback(&fwCtx->callbackStorage, ARM_UC_mmCallbackFSMEntry, ARM_UC_MM_EVENT_BEGIN); 00127 00128 return (arm_uc_error_t) {ERR_NONE}; 00129 } 00130 arm_uc_error_t ARM_UC_mmFetchNextFirmwareInfo(struct manifest_firmware_info_t *info) 00131 { 00132 struct arm_uc_mm_fw_context_t *fwCtx = &(*arm_uc_mmPersistentContext.ctx)->getFw; 00133 fwCtx->info = info; 00134 00135 // initialize callback node 00136 fwCtx->callbackStorage.lock = 0; 00137 00138 // Continue the state machine 00139 ARM_UC_PostCallback(&fwCtx->callbackStorage, ARM_UC_mmCallbackFSMEntry, ARM_UC_MM_EVENT_BEGIN); 00140 return (arm_uc_error_t) {ERR_NONE}; 00141 } 00142 arm_uc_error_t ARM_UC_mmGetError() 00143 { 00144 return arm_uc_mmPersistentContext.reportedError; 00145 } 00146 00147 int ARM_UC_mmCheckFormatUint32(manifest_guid_t* format, uint32_t expected) 00148 { 00149 manifest_guid_t local; 00150 // Fix alignment problems 00151 memcpy(&local, format, sizeof(local)); 00152 00153 int fail = 0; 00154 fail = fail || local.words[0] != 0; 00155 fail = fail || local.words[1] != 0; 00156 fail = fail || local.words[2] != 0; 00157 fail = fail || local.words[3] != htobe(expected); 00158 return !fail; 00159 } 00160 00161 #if ARM_UC_MM_ENABLE_TEST_VECTORS 00162 arm_uc_error_t ARM_UC_mmRegisterTestHook(ARM_UC_mmTestHook_t hook) 00163 { 00164 arm_uc_error_t err = {ERR_NONE}; 00165 arm_uc_mmPersistentContext.testHook = hook; 00166 return err; 00167 } 00168 #endif
Generated on Tue Jul 12 2022 20:21:01 by
