pull/8745/head
Oren Cohen 2018-12-05 16:52:22 +02:00
parent f1d3eb9340
commit b2d2cae3c4
3 changed files with 536 additions and 606 deletions

View File

@ -1,49 +1,25 @@
/***************************************************************************//** /* mbed Microcontroller Library
* \file cyprotection.c *
* \version 1.0
*
* \brief
* This is the source code for the protection unit config functions wrappers.
*
********************************************************************************
* \copyright * \copyright
*
* <EFBFBD> 2018, Cypress Semiconductor Corporation * (c) 2018, Cypress Semiconductor Corporation
* or a subsidiary of Cypress Semiconductor Corporation. All rights * or a subsidiary of Cypress Semiconductor Corporation. All rights
* reserved. * reserved.
* *
* This software, including source code, documentation and related * SPDX-License-Identifier: Apache-2.0
* materials (<EFBFBD>Software<EFBFBD>), is owned by Cypress Semiconductor
* Corporation or one of its subsidiaries (<EFBFBD>Cypress<EFBFBD>) and is protected by
* and subject to worldwide patent protection (United States and foreign),
* United States copyright laws and international treaty provisions.
* Therefore, you may use this Software only as provided in the license
* agreement accompanying the software package from which you
* obtained this Software (<EFBFBD>EULA<EFBFBD>).
* *
* If no EULA applies, Cypress hereby grants you a personal, non- * Licensed under the Apache License, Version 2.0 (the "License");
* exclusive, non-transferable license to copy, modify, and compile the * you may not use this file except in compliance with the License.
* Software source code solely for use in connection with Cypress<EFBFBD>s * You may obtain a copy of the License at
* integrated circuit products. Any reproduction, modification, translation,
* compilation, or representation of this Software except as specified
* above is prohibited without the express written permission of Cypress.
* *
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO * http://www.apache.org/licenses/LICENSE-2.0
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING,
* BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. Cypress reserves the right to make
* changes to the Software without notice. Cypress does not assume any
* liability arising out of the application or use of the Software or any
* product or circuit described in the Software. Cypress does not
* authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death (<EFBFBD>High Risk Product<EFBFBD>). By
* including Cypress<EFBFBD>s product in a High Risk Product, the manufacturer
* of such system or application assumes all risk of such use and in doing
* so agrees to indemnify Cypress against all liability.
* *
******************************************************************************/ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cyprotection.h" #include "cyprotection.h"
@ -311,7 +287,7 @@ cy_en_prot_status_t bus_masters_protect(cy_bus_master_config_t bus_masters_confi
* none * none
* *
* Called by: * Called by:
* isAccessAlowedSMPU, isAccessAlowedMPU * isAccessAllowedSMPU, isAccessAllowedMPU
* *
* Note: * Note:
* *
@ -359,7 +335,7 @@ static uint8_t isProtRangeMatched(uint32_t startAddrMem, uint32_t memSize, uint3
} }
/****************************************************************************** /******************************************************************************
* Function Name: isAccessAlowedFixedRgPPU * Function Name: isAccessAllowedFixedRgPPU
****************************************************************************** ******************************************************************************
* Summary: * Summary:
* The function checks whether a peripheral region is closed by Fixed Region PPU * The function checks whether a peripheral region is closed by Fixed Region PPU
@ -379,13 +355,13 @@ static uint8_t isProtRangeMatched(uint32_t startAddrMem, uint32_t memSize, uint3
* isProtRangeMatched * isProtRangeMatched
* *
* Called by: * Called by:
* isPeriferalAccessAllowed * isPeripheralAccessAllowed
* *
* Note: * Note:
* *
* *
*****************************************************************************/ *****************************************************************************/
static uint8_t isAccessAlowedFixedRgPPU(uint32_t perStartAddr, uint32_t perSize, static uint8_t isAccessAllowedFixedRgPPU(uint32_t perStartAddr, uint32_t perSize,
uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType) uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType)
{ {
uint8_t accessAllowed = 1; uint8_t accessAllowed = 1;
@ -449,7 +425,7 @@ static uint8_t isAccessAlowedFixedRgPPU(uint32_t perStartAddr, uint32_t perSize,
} }
/****************************************************************************** /******************************************************************************
* Function Name: isAccessAlowedFixedSlPPU * Function Name: isAccessAllowedFixedSlPPU
****************************************************************************** ******************************************************************************
* Summary: * Summary:
* The function checks whether a peripheral region is closed by Fixed Slave PPU * The function checks whether a peripheral region is closed by Fixed Slave PPU
@ -469,13 +445,13 @@ static uint8_t isAccessAlowedFixedRgPPU(uint32_t perStartAddr, uint32_t perSize,
* isProtRangeMatched * isProtRangeMatched
* *
* Called by: * Called by:
* isPeriferalAccessAllowed * isPeripheralAccessAllowed
* *
* Note: * Note:
* *
* *
*****************************************************************************/ *****************************************************************************/
static uint8_t isAccessAlowedFixedSlPPU(uint32_t perStartAddr, uint32_t perSize, static uint8_t isAccessAllowedFixedSlPPU(uint32_t perStartAddr, uint32_t perSize,
uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType) uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType)
{ {
uint8_t accessAllowed = 1; uint8_t accessAllowed = 1;
@ -573,7 +549,7 @@ static uint8_t isAccessAlowedFixedSlPPU(uint32_t perStartAddr, uint32_t perSize,
} }
/****************************************************************************** /******************************************************************************
* Function Name: isAccessAlowedProgPPU * Function Name: isAccessAllowedProgPPU
****************************************************************************** ******************************************************************************
* Summary: * Summary:
* The function checks whether a peripheral region is closed by Programmable PPU * The function checks whether a peripheral region is closed by Programmable PPU
@ -593,13 +569,13 @@ static uint8_t isAccessAlowedFixedSlPPU(uint32_t perStartAddr, uint32_t perSize,
* isProtRangeMatched * isProtRangeMatched
* *
* Called by: * Called by:
* isPeriferalAccessAllowed * isPeripheralAccessAllowed
* *
* Note: * Note:
* *
* *
*****************************************************************************/ *****************************************************************************/
static uint8_t isAccessAlowedProgPPU(uint32_t perStartAddr, uint32_t perSize, static uint8_t isAccessAllowedProgPPU(uint32_t perStartAddr, uint32_t perSize,
uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType) uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType)
{ {
uint8_t accessAllowed = 1; uint8_t accessAllowed = 1;
@ -660,7 +636,7 @@ static uint8_t isAccessAlowedProgPPU(uint32_t perStartAddr, uint32_t perSize,
} }
/****************************************************************************** /******************************************************************************
* Function Name: isAccessAlowedGrPPU * Function Name: isAccessAllowedGrPPU
****************************************************************************** ******************************************************************************
* Summary: * Summary:
* The function checks whether a peripheral region is closed by Group PPU * The function checks whether a peripheral region is closed by Group PPU
@ -680,13 +656,13 @@ static uint8_t isAccessAlowedProgPPU(uint32_t perStartAddr, uint32_t perSize,
* isProtRangeMatched * isProtRangeMatched
* *
* Called by: * Called by:
* isPeriferalAccessAllowed * isPeripheralAccessAllowed
* *
* Note: * Note:
* *
* *
*****************************************************************************/ *****************************************************************************/
static uint8_t isAccessAlowedGrPPU(uint32_t perStartAddr, uint32_t perSize, static uint8_t isAccessAllowedGrPPU(uint32_t perStartAddr, uint32_t perSize,
uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType) uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType)
{ {
uint8_t accessAllowed = 1; uint8_t accessAllowed = 1;
@ -750,7 +726,7 @@ static uint8_t isAccessAlowedGrPPU(uint32_t perStartAddr, uint32_t perSize,
} }
/****************************************************************************** /******************************************************************************
* Function Name: isPeriferalAccessAllowed * Function Name: isPeripheralAccessAllowed
****************************************************************************** ******************************************************************************
* Summary: * Summary:
* Checks if the given peripheral region is protected by PPU * Checks if the given peripheral region is protected by PPU
@ -767,7 +743,8 @@ static uint8_t isAccessAlowedGrPPU(uint32_t perStartAddr, uint32_t perSize,
* uint8_t accessAllowed (values: 0 (no) /1 (yes)) * uint8_t accessAllowed (values: 0 (no) /1 (yes))
* *
* Calls: * Calls:
* isAccessAlowedGrPPU, isAccessAlowedProgPPU, isAccessAlowedFixedPPU, isAccessAlowedRegionPPU * isAccessAllowedGrPPU, isAccessAllowedProgPPU, isAccessAllowedFixedPPU,
* isAccessAllowedRegionPPU
* *
* Called by: * Called by:
* none * none
@ -776,30 +753,30 @@ static uint8_t isAccessAlowedGrPPU(uint32_t perStartAddr, uint32_t perSize,
* *
* *
*****************************************************************************/ *****************************************************************************/
uint8_t isPeriferalAccessAllowed(uint32_t perStartAddr, uint32_t perSize, uint8_t isPeripheralAccessAllowed(uint32_t perStartAddr, uint32_t perSize,
uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType) uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType)
{ {
uint8_t accessAllowed; uint8_t accessAllowed;
accessAllowed = isAccessAlowedGrPPU(perStartAddr, perSize, privModeFlag, nsecureFlag, protectionCtx, accessType); accessAllowed = isAccessAllowedGrPPU(perStartAddr, perSize, privModeFlag, nsecureFlag, protectionCtx, accessType);
if (accessAllowed) if (accessAllowed)
{ {
accessAllowed = isAccessAlowedProgPPU(perStartAddr, perSize, privModeFlag, nsecureFlag, protectionCtx, accessType); accessAllowed = isAccessAllowedProgPPU(perStartAddr, perSize, privModeFlag, nsecureFlag, protectionCtx, accessType);
} }
if (accessAllowed) if (accessAllowed)
{ {
accessAllowed = isAccessAlowedFixedSlPPU(perStartAddr, perSize, privModeFlag, nsecureFlag, protectionCtx, accessType); accessAllowed = isAccessAllowedFixedSlPPU(perStartAddr, perSize, privModeFlag, nsecureFlag, protectionCtx, accessType);
} }
if (accessAllowed) if (accessAllowed)
{ {
accessAllowed = isAccessAlowedFixedRgPPU(perStartAddr, perSize, privModeFlag, nsecureFlag, protectionCtx, accessType); accessAllowed = isAccessAllowedFixedRgPPU(perStartAddr, perSize, privModeFlag, nsecureFlag, protectionCtx, accessType);
} }
return accessAllowed; return accessAllowed;
} }
/****************************************************************************** /******************************************************************************
* Function Name: isAccessAlowedSMPU * Function Name: isAccessAllowedSMPU
****************************************************************************** ******************************************************************************
* Summary: * Summary:
* The function checks whether a memory region is closed by SMPU for a master * The function checks whether a memory region is closed by SMPU for a master
@ -825,7 +802,7 @@ uint8_t isPeriferalAccessAllowed(uint32_t perStartAddr, uint32_t perSize,
* *
* *
*****************************************************************************/ *****************************************************************************/
static uint8_t isAccessAlowedSMPU(uint32_t memStartAddr, uint32_t memSize, static uint8_t isAccessAllowedSMPU(uint32_t memStartAddr, uint32_t memSize,
uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType) uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType)
{ {
uint8_t accessAllowed = 1; uint8_t accessAllowed = 1;
@ -887,7 +864,7 @@ static uint8_t isAccessAlowedSMPU(uint32_t memStartAddr, uint32_t memSize,
} }
/****************************************************************************** /******************************************************************************
* Function Name: isAccessAlowedMPU * Function Name: isAccessAllowedMPU
****************************************************************************** ******************************************************************************
* Summary: * Summary:
* The function checks whether a memory region is closed by MPU for a master * The function checks whether a memory region is closed by MPU for a master
@ -912,7 +889,7 @@ static uint8_t isAccessAlowedSMPU(uint32_t memStartAddr, uint32_t memSize,
* *
* *
*****************************************************************************/ *****************************************************************************/
static uint8_t isAccessAlowedMPU(uint32_t memStartAddr, uint32_t memSize, static uint8_t isAccessAllowedMPU(uint32_t memStartAddr, uint32_t memSize,
uint8_t privModeFlag, uint8_t nsecureFlag, cy_en_prot_perm_t accessType) uint8_t privModeFlag, uint8_t nsecureFlag, cy_en_prot_perm_t accessType)
{ {
uint8_t accessAllowed = 1; uint8_t accessAllowed = 1;
@ -982,7 +959,7 @@ static uint8_t isAccessAlowedMPU(uint32_t memStartAddr, uint32_t memSize,
* uint8_t accessAllowed (values: 0 (no) /1 (yes)) * uint8_t accessAllowed (values: 0 (no) /1 (yes))
* *
* Calls: * Calls:
* CheckEnabledMPUProtection, isAccessAlowedSMPU * CheckEnabledMPUProtection, isAccessAllowedSMPU
* *
* Called by: * Called by:
* none * none
@ -996,10 +973,10 @@ uint8_t isMemoryAccessAllowed(uint32_t memStartAddr, uint32_t memSize,
{ {
uint8_t accessAllowed; uint8_t accessAllowed;
accessAllowed = isAccessAlowedMPU(memStartAddr, memSize, privModeFlag, nsecureFlag, accessType); accessAllowed = isAccessAllowedMPU(memStartAddr, memSize, privModeFlag, nsecureFlag, accessType);
if (accessAllowed) if (accessAllowed)
{ {
accessAllowed = isAccessAlowedSMPU(memStartAddr, memSize, privModeFlag, nsecureFlag, protectionCtx, accessType); accessAllowed = isAccessAllowedSMPU(memStartAddr, memSize, privModeFlag, nsecureFlag, protectionCtx, accessType);
} }
return accessAllowed; return accessAllowed;

View File

@ -1,50 +1,25 @@
/***************************************************************************//** /* mbed Microcontroller Library
* \file cyprotection.h *
* \version 1.0
*
* \brief
* This is the header file for the protection configuration structures
* and functions.
*
********************************************************************************
* \copyright * \copyright
*
* <EFBFBD> 2018, Cypress Semiconductor Corporation * (c) 2018, Cypress Semiconductor Corporation
* or a subsidiary of Cypress Semiconductor Corporation. All rights * or a subsidiary of Cypress Semiconductor Corporation. All rights
* reserved. * reserved.
* *
* This software, including source code, documentation and related * SPDX-License-Identifier: Apache-2.0
* materials (<EFBFBD>Software<EFBFBD>), is owned by Cypress Semiconductor
* Corporation or one of its subsidiaries (<EFBFBD>Cypress<EFBFBD>) and is protected by
* and subject to worldwide patent protection (United States and foreign),
* United States copyright laws and international treaty provisions.
* Therefore, you may use this Software only as provided in the license
* agreement accompanying the software package from which you
* obtained this Software (<EFBFBD>EULA<EFBFBD>).
* *
* If no EULA applies, Cypress hereby grants you a personal, non- * Licensed under the Apache License, Version 2.0 (the "License");
* exclusive, non-transferable license to copy, modify, and compile the * you may not use this file except in compliance with the License.
* Software source code solely for use in connection with Cypress<EFBFBD>s * You may obtain a copy of the License at
* integrated circuit products. Any reproduction, modification, translation,
* compilation, or representation of this Software except as specified
* above is prohibited without the express written permission of Cypress.
* *
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO * http://www.apache.org/licenses/LICENSE-2.0
* WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING,
* BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. Cypress reserves the right to make
* changes to the Software without notice. Cypress does not assume any
* liability arising out of the application or use of the Software or any
* product or circuit described in the Software. Cypress does not
* authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death (<EFBFBD>High Risk Product<EFBFBD>). By
* including Cypress<EFBFBD>s product in a High Risk Product, the manufacturer
* of such system or application assumes all risk of such use and in doing
* so agrees to indemnify Cypress against all liability.
* *
******************************************************************************/ * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _CYPROTECTION_H_ #ifndef _CYPROTECTION_H_
#define _CYPROTECTION_H_ #define _CYPROTECTION_H_
@ -181,7 +156,7 @@ cy_en_prot_status_t ppu_prog_protect(cy_ppu_prog_cfg_t ppu_config_arr[], uint32_
cy_en_prot_status_t ppu_fixed_gr_protect(cy_ppu_fixed_gr_cfg_t ppu_config_arr[], uint32_t arr_length); cy_en_prot_status_t ppu_fixed_gr_protect(cy_ppu_fixed_gr_cfg_t ppu_config_arr[], uint32_t arr_length);
cy_en_prot_status_t bus_masters_protect(cy_bus_master_config_t bus_masters_config_arr[], uint32_t arr_length); cy_en_prot_status_t bus_masters_protect(cy_bus_master_config_t bus_masters_config_arr[], uint32_t arr_length);
uint8_t isPeriferalAccessAllowed(uint32_t perStartAddr, uint32_t perSize, uint8_t isPeripheralAccessAllowed(uint32_t perStartAddr, uint32_t perSize,
uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType); uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType);
uint8_t isMemoryAccessAllowed(uint32_t memStartAddr, uint32_t memSize, uint8_t isMemoryAccessAllowed(uint32_t memStartAddr, uint32_t memSize,
uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType); uint8_t privModeFlag, uint8_t nsecureFlag, enum cy_en_prot_pc_t protectionCtx, cy_en_prot_perm_t accessType);