-
Notifications
You must be signed in to change notification settings - Fork 842
Zephyr specific updates #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3a2c124
88303ff
43fc2cd
3dbf222
a2d5b1a
7cf3d9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,21 +15,22 @@ | |
| */ | ||
|
|
||
| #include <zephyr.h> | ||
| #include <misc/printk.h> | ||
| #include <flash.h> | ||
| #include <asm_inline.h> | ||
|
|
||
| #include "bootutil/image.h" | ||
| #include "bootutil/bootutil.h" | ||
| #define SYS_LOG_DOMAIN "BOOTLOADER" | ||
| #define SYS_LOG_LEVEL SYS_LOG_LEVEL_INFO | ||
| #include <logging/sys_log.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 { | ||
|
|
@@ -45,34 +46,39 @@ void main(void) | |
| struct vector_table *vt; | ||
| int rc; | ||
|
|
||
| SYS_LOG_INF("Starting bootloader"); | ||
|
|
||
| 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"); | ||
| SYS_LOG_ERR("Flash device not found"); | ||
| while (1) | ||
| ; | ||
| } | ||
|
|
||
| rc = boot_go(&rsp); | ||
| if (rc != 0) { | ||
| printk("Unable to find bootable image\n"); | ||
| SYS_LOG_ERR("Unable to find bootable image"); | ||
| while (1) | ||
| ; | ||
| } | ||
|
|
||
| printk("Bootloader chain: 0x%x\n", rsp.br_image_addr); | ||
| SYS_LOG_INF("Bootloader chainload address: 0x%x", rsp.br_image_addr); | ||
| vt = (struct vector_table *)(rsp.br_image_addr + | ||
| rsp.br_hdr->ih_hdr_size); | ||
| irq_lock(); | ||
| _MspSet(vt->msp); | ||
|
|
||
| SYS_LOG_INF("Setting vector table to %p", vt); | ||
|
|
||
| /* Not all targets set the VTOR, so just set it. */ | ||
| _scs_relocate_vector_table((void *) vt); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this can be removed, now that we're going to be setting this properly in Zephyr. |
||
|
|
||
| SYS_LOG_INF("Jumping to the first image slot"); | ||
| ((void (*)(void))vt->reset)(); | ||
|
|
||
| printk("Never should get here\n"); | ||
| SYS_LOG_ERR("Never should get here"); | ||
| while (1) | ||
| ; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
| */ | ||
|
|
||
| #include <zephyr.h> | ||
| #include <misc/printk.h> | ||
| #include <string.h> | ||
|
|
||
| #include "os/os_heap.h" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| CONFIG_CONSOLE_HANDLER=y | ||
| CONFIG_PRINTK=y | ||
| CONFIG_SYS_LOG=y | ||
| CONFIG_DEBUG=y | ||
|
|
||
| CONFIG_MAIN_STACK_SIZE=10240 | ||
|
|
@@ -11,4 +11,6 @@ CONFIG_MBEDTLS_CFG_FILE="config-boot.h" | |
| CONFIG_HEAP_MEM_POOL_SIZE=16384 | ||
|
|
||
| CONFIG_FLASH=y | ||
| CONFIG_SOC_FLASH_STM32F4=y | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you do something to Zephyr to make this work? When I did it, there were two flash devices defined for the target so Kconfig picked neither.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's probably because of Linaro/zephyr@942edd4. I'm hoping the upstream version to be merged soon, then we will have the right fix at the right place. |
||
| ### Disable Bluetooth by default | ||
| # CONFIG_BLUETOOTH is not set | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 "NRF5_FLASH" | ||
| #define FLASH_ALIGN 1 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure this is really right. Having it too small can excessively wear the flash device.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, same value as used by mynewt, so fine to have that now. |
||
| #define FLASH_AREA_IMAGE_0_OFFSET 0x08000 | ||
| #define FLASH_AREA_IMAGE_0_SIZE 0x3A000 | ||
| #define FLASH_AREA_IMAGE_1_OFFSET 0x42000 | ||
| #define FLASH_AREA_IMAGE_1_SIZE 0x3A000 | ||
| #define FLASH_AREA_IMAGE_SCRATCH_OFFSET 0x7c000 | ||
| #define FLASH_AREA_IMAGE_SCRATCH_SIZE 0x01000 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,22 @@ | ||
| #! /bin/bash | ||
| #!/bin/sh | ||
|
|
||
| source $(dirname 0)/target.sh | ||
| source ../zephyr/zephyr-env.sh | ||
| # Assume first argument is the board name (as defined in Zephyr) | ||
| BOARD=$1 | ||
|
|
||
| make BOARD=$BOARD "$@" | ||
| if [ -z "$BOARD" ]; then | ||
| echo "Please specify the board name (as in Zephyr) as first argument." | ||
| exit 1; | ||
| fi | ||
|
|
||
| if [ ! -f "$(dirname $0)/boot/zephyr/targets/${BOARD}.h" ]; then | ||
| echo "Board $BOARD not yet supported, please use a supported target." | ||
| exit 1; | ||
| fi | ||
|
|
||
| # Check if there is a valid Zephyr environment available | ||
| if [ -z "$ZEPHYR_BASE" ]; then | ||
| echo "ZEPHYR_BASE not provided by the environment." | ||
| exit 1; | ||
| fi | ||
|
|
||
| make BOARD=$BOARD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good for now. It is likely that we will bring in the partition table code from mynewt into mcuboot, which will make all of this quite different, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just wanted to improve it a bit enough to remove the hardcoded values. The best to do here is parsing mynewt's partition table, to avoid duplicating info.