zephyr: restructure the build process to use board config files
Move the board specific configurations into its own header file, which
can now be created per board, once it gets tested and validated by the
bootloader.
Signed-off-by: Ricardo Salveti <ricardo.salveti@linaro.org>
diff --git a/boot/zephyr/Makefile b/boot/zephyr/Makefile
index 6b8618a..b3f79f3 100644
--- a/boot/zephyr/Makefile
+++ b/boot/zephyr/Makefile
@@ -1,5 +1,7 @@
+subdir-ccflags-y += -DMCUBOOT_TARGET_CONFIG='"$(BOARD).h"'
subdir-ccflags-y += -I$(PROJECT)/boot/bootutil/include
subdir-ccflags-y += -I$(PROJECT)/boot/zephyr/include
+subdir-ccflags-y += -I$(PROJECT)/boot/zephyr/targets
obj-y += main.o
obj-y += flash_map.o hal_flash.o os.o
diff --git a/boot/zephyr/flash_map.c b/boot/zephyr/flash_map.c
index aadf13a..ad5cd05 100644
--- a/boot/zephyr/flash_map.c
+++ b/boot/zephyr/flash_map.c
@@ -21,6 +21,8 @@
#include <misc/printk.h>
#include <flash.h>
+#include MCUBOOT_TARGET_CONFIG
+
#include <flash_map/flash_map.h>
#include <hal/hal_flash.h>
#include <sysflash/sysflash.h>
@@ -34,28 +36,22 @@
static const struct flash_area part_map[] = {
{
.fa_id = FLASH_AREA_IMAGE_0,
- .fa_off = 0x20000,
- .fa_size = 0x20000,
+ .fa_off = FLASH_AREA_IMAGE_0_OFFSET,
+ .fa_size = FLASH_AREA_IMAGE_0_SIZE,
},
{
.fa_id = FLASH_AREA_IMAGE_1,
- .fa_off = 0x40000,
- .fa_size = 0x20000,
+ .fa_off = FLASH_AREA_IMAGE_1_OFFSET,
+ .fa_size = FLASH_AREA_IMAGE_1_SIZE,
},
{
.fa_id = FLASH_AREA_IMAGE_SCRATCH,
- .fa_off = 0x60000,
- .fa_size = 0x20000,
+ .fa_off = FLASH_AREA_IMAGE_SCRATCH_OFFSET,
+ .fa_size = FLASH_AREA_IMAGE_SCRATCH_SIZE,
},
};
/*
- * The K64F has a simple 1MB of uniform 4KB sectors. Initially, we'll
- * use the same partition layout as the Carbon board to make
- * development easier.
- */
-
-/*
* `open` a flash area. The `area` in this case is not the individual
* sectors, but describes the particular flash area in question.
*/
@@ -137,13 +133,13 @@
if (*cnt < 1)
return -1;
- off = (idx - FLASH_AREA_IMAGE_0 + 1) * 0x20000;
+ off = (idx - FLASH_AREA_IMAGE_0 + 1) * FLASH_AREA_IMAGE_0_OFFSET;
ret->fa_id = idx;
ret->fa_device_id = 0;
ret->pad16 = 0;
ret->fa_off = off;
- ret->fa_size = 0x20000;
+ ret->fa_size = FLASH_AREA_IMAGE_0_SIZE;
return 0;
}
diff --git a/boot/zephyr/hal_flash.c b/boot/zephyr/hal_flash.c
index a3700bc..986ae77 100644
--- a/boot/zephyr/hal_flash.c
+++ b/boot/zephyr/hal_flash.c
@@ -20,15 +20,9 @@
#include <zephyr.h>
#include <misc/printk.h>
-#include "hal/hal_flash.h"
+#include MCUBOOT_TARGET_CONFIG
-#if defined(CONFIG_BOARD_FRDM_K64F)
-#define FLASH_ALIGN 8
-#elif defined(CONFIG_BOARD_96B_CARBON)
-#define FLASH_ALIGN 1
-#else
-#error "Board is currently not supported by bootloader"
-#endif
+#include "hal/hal_flash.h"
/* All of the currently supported devices allow single byte writes. */
uint8_t hal_flash_align(uint8_t flash_id)
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index 800fe51..026fc92 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -19,17 +19,15 @@
#include <flash.h>
#include <asm_inline.h>
-#include "bootutil/image.h"
-#include "bootutil/bootutil.h"
-
-#if defined(CONFIG_BOARD_FRDM_K64F)
-#define BOOT_FLASH "KSDK_FLASH"
-#elif defined(CONFIG_BOARD_96B_CARBON)
-#define BOOT_FLASH "STM32F4_FLASH"
+#if defined(MCUBOOT_TARGET_CONFIG)
+#include MCUBOOT_TARGET_CONFIG
#else
#error "Board is currently not supported by bootloader"
#endif
+#include "bootutil/image.h"
+#include "bootutil/bootutil.h"
+
struct device *boot_flash_device;
struct vector_table {
@@ -47,7 +45,7 @@
os_heap_init();
- boot_flash_device = device_get_binding(BOOT_FLASH);
+ boot_flash_device = device_get_binding(FLASH_DRIVER_NAME);
if (!boot_flash_device) {
printk("Flash device not found\n");
while (1)
diff --git a/boot/zephyr/target.sh.example b/boot/zephyr/target.sh.example
deleted file mode 100644
index 1652853..0000000
--- a/boot/zephyr/target.sh.example
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copy this file to target.sh and modify to suit your needs
-
-if true; then
- BOARD=96b_carbon
- SOC=STM32F401RE
- BASE_BOOT=0x08000000
- BASE_SLOT0=0x08020000
- BASE_SLOT1=0x08040000
-else
- BOARD=frdm_k64f
- SOC=MK64FN1M0VLL12
- BASE_BOOT=0x00000000
- BASE_SLOT0=0x00020000
- BASE_SLOT1=0x00040000
-fi
-
-gdbexe=/mnt/linaro/toolchains/aarch32/bin/arm-linux-gnueabihf-gdb
diff --git a/boot/zephyr/targets/96b_carbon.h b/boot/zephyr/targets/96b_carbon.h
new file mode 100644
index 0000000..6d8b248
--- /dev/null
+++ b/boot/zephyr/targets/96b_carbon.h
@@ -0,0 +1,29 @@
+/*
+ * 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 "STM32F4_FLASH"
+#define FLASH_ALIGN 1
+#define FLASH_AREA_IMAGE_0_OFFSET 0x20000
+#define FLASH_AREA_IMAGE_0_SIZE 0x20000
+#define FLASH_AREA_IMAGE_1_OFFSET 0x40000
+#define FLASH_AREA_IMAGE_1_SIZE 0x20000
+#define FLASH_AREA_IMAGE_SCRATCH_OFFSET 0x60000
+#define FLASH_AREA_IMAGE_SCRATCH_SIZE 0x20000
diff --git a/boot/zephyr/targets/frdm_k64f.h b/boot/zephyr/targets/frdm_k64f.h
new file mode 100644
index 0000000..01926d5
--- /dev/null
+++ b/boot/zephyr/targets/frdm_k64f.h
@@ -0,0 +1,29 @@
+/*
+ * 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 "KSDK_FLASH"
+#define FLASH_ALIGN 8
+#define FLASH_AREA_IMAGE_0_OFFSET 0x20000
+#define FLASH_AREA_IMAGE_0_SIZE 0x20000
+#define FLASH_AREA_IMAGE_1_OFFSET 0x40000
+#define FLASH_AREA_IMAGE_1_SIZE 0x20000
+#define FLASH_AREA_IMAGE_SCRATCH_OFFSET 0x60000
+#define FLASH_AREA_IMAGE_SCRATCH_SIZE 0x20000