leo hendrickson / Mbed OS example-Ethernet-mbed-Cloud-connect
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_uc_pal_blockdevice.c Source File

arm_uc_pal_blockdevice.c

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2017-2018 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_config.h"
00020 #if defined(ARM_UC_FEATURE_PAL_BLOCKDEVICE) && (ARM_UC_FEATURE_PAL_BLOCKDEVICE == 1)
00021 
00022 #include "update-client-paal/arm_uc_paal_update_api.h"
00023 
00024 #include "update-client-pal-blockdevice/arm_uc_pal_blockdevice_implementation.h"
00025 #include "update-client-pal-flashiap/arm_uc_pal_flashiap_implementation.h"
00026 
00027 /**
00028  * @brief Initialize the underlying storage and set the callback handler.
00029  *
00030  * @param callback Function pointer to event handler.
00031  * @return Returns ERR_NONE on accept, and signals the event handler with
00032  *         either DONE or ERROR when complete.
00033  *         Returns ERR_INVALID_PARAMETER on reject, and no signal is sent.
00034  */
00035 arm_uc_error_t ARM_UCP_FashIAP_BlockDevice_Initialize(ARM_UC_PAAL_UPDATE_SignalEvent_t callback)
00036 {
00037     arm_uc_error_t result = { .code = ERR_INVALID_PARAMETER };
00038 
00039     if (callback) {
00040         arm_uc_error_t status1 = ARM_UC_PAL_FlashIAP_Initialize(callback);
00041         arm_uc_error_t status2 = ARM_UC_PAL_BlockDevice_Initialize(callback);
00042 
00043         if ((status1.error == ERR_NONE) && (status2.error == ERR_NONE)) {
00044             result.code = ERR_NONE;
00045         } else {
00046             result.code = ERR_NOT_READY;
00047         }
00048     }
00049 
00050     return result;
00051 }
00052 
00053 ARM_UC_PAAL_UPDATE_CAPABILITIES ARM_UCP_FashIAP_BlockDevice_GetCapabilities(void)
00054 {
00055     ARM_UC_PAAL_UPDATE_CAPABILITIES result = {
00056         .installer_arm_hash = 0,
00057         .installer_oem_hash = 0,
00058         .installer_layout   = 0,
00059         .firmware_hash      = 1,
00060         .firmware_hmac      = 0,
00061         .firmware_campaign  = 0,
00062         .firmware_version   = 1,
00063         .firmware_size      = 1
00064     };
00065 
00066     return result;
00067 }
00068 
00069 const ARM_UC_PAAL_UPDATE ARM_UCP_FLASHIAP_BLOCKDEVICE = {
00070     .Initialize                 = ARM_UCP_FashIAP_BlockDevice_Initialize,
00071     .GetCapabilities            = ARM_UCP_FashIAP_BlockDevice_GetCapabilities,
00072     .GetMaxID                   = ARM_UC_PAL_BlockDevice_GetMaxID,
00073     .Prepare                    = ARM_UC_PAL_BlockDevice_Prepare,
00074     .Write                      = ARM_UC_PAL_BlockDevice_Write,
00075     .Finalize                   = ARM_UC_PAL_BlockDevice_Finalize,
00076     .Read                       = ARM_UC_PAL_BlockDevice_Read,
00077     .Activate                   = ARM_UC_PAL_BlockDevice_Activate,
00078     .GetActiveFirmwareDetails   = ARM_UC_PAL_FlashIAP_GetActiveDetails,
00079     .GetFirmwareDetails         = ARM_UC_PAL_BlockDevice_GetFirmwareDetails,
00080     .GetInstallerDetails        = ARM_UC_PAL_FlashIAP_GetInstallerDetails
00081 };
00082 
00083 #endif // #if defined(ARM_UC_FEATURE_PAL_BLOCKDEVICE)