zephyr: move STM32 target config to soc_family_stm32.h
This cleanup commit requires a bit more target-specific knowledge
that's a bit harder to read than board-specific headers, but it's
still an improvement over what we have now.
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
diff --git a/boot/zephyr/include/target.h b/boot/zephyr/include/target.h
index d37a523..101c572 100644
--- a/boot/zephyr/include/target.h
+++ b/boot/zephyr/include/target.h
@@ -14,6 +14,8 @@
/* SoC family configuration. */
#if defined(CONFIG_SOC_FAMILY_NRF5)
#include "soc_family_nrf5.h"
+#elif defined(CONFIG_SOC_FAMILY_STM32)
+#include "soc_family_stm32.h"
#endif
/*
diff --git a/boot/zephyr/targets/96b_carbon.h b/boot/zephyr/targets/96b_carbon.h
deleted file mode 100644
index b61cebf..0000000
--- a/boot/zephyr/targets/96b_carbon.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2017 Linaro
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-/**
- * @file
- * @brief Bootloader device specific configuration.
- */
-
-/* TEMP: maintain compatibility with old STM flash driver */
-#ifndef CONFIG_SOC_FLASH_STM32_DEV_NAME
-#define FLASH_DRIVER_NAME "STM32F4_FLASH"
-#else
-#define FLASH_DRIVER_NAME CONFIG_SOC_FLASH_STM32_DEV_NAME
-#endif
-#define FLASH_ALIGN 1
-
-/*
- * Though sectors have variable size on this part, we require Zephyr
- * to choose image and flash sectors with uniform size, each one
- * sector in size.
- */
-#define FLASH_AREA_IMAGE_SECTOR_SIZE 0x20000
diff --git a/boot/zephyr/targets/disco_l475_iot1.h b/boot/zephyr/targets/disco_l475_iot1.h
deleted file mode 100644
index 3e9678b..0000000
--- a/boot/zephyr/targets/disco_l475_iot1.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2017 Linaro
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-/**
- * @file
- * @brief Bootloader device specific configuration.
- */
-
-#define FLASH_DRIVER_NAME CONFIG_SOC_FLASH_STM32_DEV_NAME
-#define FLASH_ALIGN 8
diff --git a/boot/zephyr/targets/nucleo_f401re.h b/boot/zephyr/targets/nucleo_f401re.h
deleted file mode 100644
index 4be77e0..0000000
--- a/boot/zephyr/targets/nucleo_f401re.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2017 Linaro
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-/**
- * @file
- * @brief Bootloader device specific configuration.
- */
-
-#define FLASH_DRIVER_NAME CONFIG_SOC_FLASH_STM32_DEV_NAME
-#define FLASH_ALIGN 1
-
-/* Though sectors have variable size on this part, we've chosen
- * three sectors with uniform size here. */
-#define FLASH_AREA_IMAGE_SECTOR_SIZE 0x20000
diff --git a/boot/zephyr/targets/soc_family_stm32.h b/boot/zephyr/targets/soc_family_stm32.h
new file mode 100644
index 0000000..cf21bb0
--- /dev/null
+++ b/boot/zephyr/targets/soc_family_stm32.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2017, Linaro Ltd
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr.h>
+#include <soc.h>
+
+#define FLASH_DRIVER_NAME CONFIG_SOC_FLASH_STM32_DEV_NAME
+
+#if defined(CONFIG_SOC_SERIES_STM32F4X)
+/*
+ * The Zephyr flash driver will let us remove the need for
+ * FLASH_AREA_IMAGE_SECTOR_SIZE at some point. It doesn't make sense
+ * on these targets, anyway, as they have variable sized sectors.
+ *
+ * For now, let's rely on the fact that on all STM32F4 chips with at
+ * most 16 flash sectors, all of the sectors after the first 128 KB
+ * are equal sized.
+ */
+#if (!defined(FLASH_AREA_IMAGE_SECTOR_SIZE) && FLASH_SECTOR_TOTAL <= 16 && \
+ FLASH_AREA_IMAGE_0_OFFSET >= KB(128))
+#define FLASH_AREA_IMAGE_SECTOR_SIZE 0x20000
+#endif
+#define FLASH_ALIGN 1
+#elif defined(CONFIG_SOC_SERIES_STM32L4X) /* !CONFIG_SOC_SERIES_STM32F4X */
+#define FLASH_ALIGN 8
+#define FLASH_AREA_IMAGE_SECTOR_SIZE FLASH_PAGE_SIZE /* from the HAL */
+#endif /* CONFIG_SOC_SERIES_STM32F4X */