From 054c564a2d265a1f6915999779a96c014de41471 Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Wed, 22 May 2024 15:13:33 +0800 Subject: [PATCH] arm_mpu:Fix mpu_initialize not taking effect Modified the input parameters of mpu_initialize to require the caller to provide the number of entries in the table Signed-off-by: chenrun1 --- arch/arm/src/armv7-m/arm_mpu.c | 9 +++++---- arch/arm/src/armv7-m/mpu.h | 5 +++-- arch/arm/src/armv7-r/arm_mpu.c | 7 ++++--- arch/arm/src/armv7-r/mpu.h | 3 ++- arch/arm/src/armv8-m/arm_mpu.c | 9 +++++---- arch/arm/src/armv8-m/mpu.h | 5 +++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/arch/arm/src/armv7-m/arm_mpu.c b/arch/arm/src/armv7-m/arm_mpu.c index 422c6112b8..1e93eb97ec 100644 --- a/arch/arm/src/armv7-m/arm_mpu.c +++ b/arch/arm/src/armv7-m/arm_mpu.c @@ -558,6 +558,7 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * * Input Parameters: * table - MPU initialization table. + * count - Initialize the number of entries in the region table. * hfnmiena - A boolean indicating whether the MPU should enable the * HFNMIENA bit. * privdefena - A boolean indicating whether the MPU should enable the @@ -568,14 +569,14 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * ****************************************************************************/ -void mpu_initialize(const struct mpu_region_s *table, bool hfnmiena, - bool privdefena) +void mpu_initialize(const struct mpu_region_s *table, size_t count, + bool hfnmiena, bool privdefena) { const struct mpu_region_s *conf; - int index; + size_t index; mpu_control(false, false, false); - for (index = 0; index < nitems(table); index++) + for (index = 0; index < count; index++) { conf = &table[index]; mpu_configure_region(conf->base, conf->size, conf->flags); diff --git a/arch/arm/src/armv7-m/mpu.h b/arch/arm/src/armv7-m/mpu.h index e4c7286eca..7cbf820470 100644 --- a/arch/arm/src/armv7-m/mpu.h +++ b/arch/arm/src/armv7-m/mpu.h @@ -380,6 +380,7 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * * Input Parameters: * table - MPU initialization table. + * count - Initialize the number of entries in the region table. * hfnmiena - A boolean indicating whether the MPU should enable the * HFNMIENA bit. * privdefena - A boolean indicating whether the MPU should enable the @@ -390,8 +391,8 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * ****************************************************************************/ -void mpu_initialize(const struct mpu_region_s *table, bool hfnmiena, - bool privdefena); +void mpu_initialize(const struct mpu_region_s *table, size_t count, + bool hfnmiena, bool privdefena); /**************************************************************************** * Inline Functions diff --git a/arch/arm/src/armv7-r/arm_mpu.c b/arch/arm/src/armv7-r/arm_mpu.c index 0715a5b4e1..33128d32c9 100644 --- a/arch/arm/src/armv7-r/arm_mpu.c +++ b/arch/arm/src/armv7-r/arm_mpu.c @@ -486,19 +486,20 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * * Input Parameters: * table - MPU Initiaze table. + * count - Initialize the number of entries in the region table. * * Returned Value: * NULL. * ****************************************************************************/ -void mpu_initialize(const struct mpu_region_s *table) +void mpu_initialize(const struct mpu_region_s *table, size_t count) { const struct mpu_region_s *conf; - int index; + size_t index; mpu_control(false); - for (index = 0; index < nitems(table); index++) + for (index = 0; index < count; index++) { conf = &table[index]; mpu_configure_region(conf->base, conf->size, conf->flags); diff --git a/arch/arm/src/armv7-r/mpu.h b/arch/arm/src/armv7-r/mpu.h index f6736505a1..acbbbdf749 100644 --- a/arch/arm/src/armv7-r/mpu.h +++ b/arch/arm/src/armv7-r/mpu.h @@ -318,13 +318,14 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * * Input Parameters: * table - MPU Initiaze table. + * count - Initialize the number of entries in the region table. * * Returned Value: * NULL. * ****************************************************************************/ -void mpu_initialize(const struct mpu_region_s *table); +void mpu_initialize(const struct mpu_region_s *table, size_t count); /**************************************************************************** * Inline Functions diff --git a/arch/arm/src/armv8-m/arm_mpu.c b/arch/arm/src/armv8-m/arm_mpu.c index 2c68d7e31a..c00e4802a7 100644 --- a/arch/arm/src/armv8-m/arm_mpu.c +++ b/arch/arm/src/armv8-m/arm_mpu.c @@ -289,6 +289,7 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * * Input Parameters: * table - MPU initialization table. + * count - Initialize the number of entries in the region table. * hfnmiena - A boolean indicating whether the MPU should enable the * HFNMIENA bit. * privdefena - A boolean indicating whether the MPU should enable the @@ -299,14 +300,14 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * ****************************************************************************/ -void mpu_initialize(const struct mpu_region_s *table, bool hfnmiena, - bool privdefena) +void mpu_initialize(const struct mpu_region_s *table, size_t count, + bool hfnmiena, bool privdefena) { const struct mpu_region_s *conf; - int index; + size_t index; mpu_control(false, false, false); - for (index = 0; index < nitems(table); index++) + for (index = 0; index < count; index++) { conf = &table[index]; mpu_configure_region(conf->base, conf->size, conf->flags1, diff --git a/arch/arm/src/armv8-m/mpu.h b/arch/arm/src/armv8-m/mpu.h index 033357edc4..d7c6f929f8 100644 --- a/arch/arm/src/armv8-m/mpu.h +++ b/arch/arm/src/armv8-m/mpu.h @@ -347,6 +347,7 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * * Input Parameters: * table - MPU initialization table. + * count - Initialize the number of entries in the region table. * hfnmiena - A boolean indicating whether the MPU should enable the * HFNMIENA bit. * privdefena - A boolean indicating whether the MPU should enable the @@ -357,8 +358,8 @@ unsigned int mpu_configure_region(uintptr_t base, size_t size, * ****************************************************************************/ -void mpu_initialize(const struct mpu_region_s *table, bool hfnmiena, - bool privdefena); +void mpu_initialize(const struct mpu_region_s *table, size_t count, + bool hfnmiena, bool privdefena); /**************************************************************************** * Inline Functions