-
Notifications
You must be signed in to change notification settings - Fork 513
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
Adds bootloader as a secondary dependency to Photon/P1/Electron system-part2 #1306
Merged
technobly
merged 22 commits into
feature/photon/wiced-3.7.0-7
from
feature/bootloader-dependency
May 10, 2017
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4c1c306
Load DCT functions dynamically in bootloader (P1)
sergeuz 835bcdb
Compilation fixes, renamings
sergeuz f7ed26b
Panic messages are now logged only in debug builds
sergeuz 09d0351
Disable reading/writing of DCT via DFU if DCT functions cannot be loa…
sergeuz 70c9e2a
Clear module info in DCT before updating modules
sergeuz 66f222e
Load DCT functions on first call; error handling for DCT read operations
sergeuz cf3ca06
Use backup registers to store system flags (stm32f2xx)
sergeuz ead398b
Check module dependencies
sergeuz 56c6158
Enable dynamic loading of the DCT functions on Photon
sergeuz c97d7e0
Check addresses of the dynamically loaded functions
sergeuz c12d5a6
Check IWDG flag in DCT for compatibility with old bootloaders
sergeuz 3e949ab
Don't clear module info slots in DCT unconditionally to avoid slowing…
sergeuz c0f1e62
Fix buttons setup in a situation when DCT functions are missing in bo…
sergeuz 57081e2
Fill DFU packet with zeros to make reading errors more apparent
sergeuz 5d91aaf
Minor fixes
sergeuz 403c980
Moves BOOTLOADER_VERSION definition into system_module_version.mk
avtolstoy a1d5e17
Makes photon/p1 system-part1 and electron system-part3 depend on boot…
avtolstoy d306841
Adds bootloader module validation
avtolstoy b2e7a32
Adds a secondary module dependency.
avtolstoy 5a1d198
Fixes unit tests. sizeof(void*) is 8 on 64-bit systems
avtolstoy 86921a6
Add MODULE_DEPENDENCY2 to main/build.mk
avtolstoy eedde55
Default to invalid in HAL_Core_Validate_Modules
avtolstoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include "bootloader_dct.h" | ||
|
||
#include "flash_mal.h" | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
#define MODULAR_FIRMWARE 1 | ||
#include "../../../hal/src/photon/ota_module_bounds.c" | ||
|
||
#define SYSTEM_PART2_MIN_MODULE_VERSION 107 // 0.7.0-rc.1 | ||
#define DYNALIB_HAL_CORE_INDEX 7 | ||
#define HAL_DCT_READ_APP_DATA_INDEX 33 | ||
#define HAL_DCT_WRITE_APP_DATA_INDEX 34 | ||
|
||
static const void*(*HAL_DCT_Read_App_Data)(uint32_t, void*) = NULL; | ||
static int(*HAL_DCT_Write_App_Data)(const void*, uint32_t, uint32_t, void*) = NULL; | ||
static uint8_t dct_funcs_inited = 0; | ||
|
||
static const module_info_t* get_module_info(const module_bounds_t* bounds, uint16_t min_version) { | ||
const module_info_t* module = FLASH_ModuleInfo(FLASH_INTERNAL, bounds->start_address); | ||
// Check primary module info | ||
if (!module || module->platform_id != PLATFORM_ID || module->module_function != bounds->module_function || | ||
module->module_index != bounds->module_index || module->module_version < min_version) { | ||
return NULL; | ||
} | ||
// Check module boundaries | ||
const uintptr_t startAddr = (uintptr_t)module->module_start_address; | ||
const uintptr_t endAddr = (uintptr_t)module->module_end_address; | ||
if (endAddr < startAddr || startAddr != bounds->start_address || endAddr > bounds->end_address) { | ||
return NULL; | ||
} | ||
// Verify checksum | ||
if (!FLASH_VerifyCRC32(FLASH_INTERNAL, startAddr, endAddr - startAddr)) { | ||
return NULL; | ||
} | ||
return module; | ||
} | ||
|
||
static inline bool check_module_addr(void* ptr, const module_info_t* module) { | ||
return (ptr >= module->module_start_address && ptr < module->module_end_address); | ||
} | ||
|
||
static void init_dct_functions() { | ||
HAL_DCT_Read_App_Data = NULL; | ||
HAL_DCT_Write_App_Data = NULL; | ||
const module_info_t* part2 = get_module_info(&module_system_part2, SYSTEM_PART2_MIN_MODULE_VERSION); | ||
if (!part2) { | ||
return; | ||
} | ||
// Part2 should contain complete DCT implementation, but it's easy to introduce an additional | ||
// dependency during development, so we require part1 to be consistent as well | ||
const module_info_t* part1 = get_module_info(&module_system_part1, part2->dependency.module_version); | ||
if (!part1 || part1->dependency.module_function != MODULE_FUNCTION_NONE) { | ||
return; | ||
} | ||
// Get hal_core's dynalib table | ||
void*** dynalib = (void***)((const char*)part2 + sizeof(module_info_t)); | ||
void** dynalib_hal_core = dynalib[DYNALIB_HAL_CORE_INDEX]; | ||
// Get addresses of the DCT functions | ||
void* hal_dct_read_app_data_ptr = dynalib_hal_core[HAL_DCT_READ_APP_DATA_INDEX]; | ||
void* hal_dct_write_app_data_ptr = dynalib_hal_core[HAL_DCT_WRITE_APP_DATA_INDEX]; | ||
if (!check_module_addr(hal_dct_read_app_data_ptr, part2) || | ||
!check_module_addr(hal_dct_write_app_data_ptr, part2)) { | ||
return; | ||
} | ||
HAL_DCT_Read_App_Data = hal_dct_read_app_data_ptr; | ||
HAL_DCT_Write_App_Data = hal_dct_write_app_data_ptr; | ||
} | ||
|
||
void load_dct_functions() { | ||
dct_funcs_inited = 0; | ||
} | ||
|
||
const void* dct_read_app_data(uint32_t offset) { | ||
if (!dct_funcs_inited) { | ||
init_dct_functions(); | ||
dct_funcs_inited = 1; | ||
} | ||
if (HAL_DCT_Read_App_Data) { | ||
return HAL_DCT_Read_App_Data(offset, NULL /* reserved */); | ||
} | ||
return NULL; | ||
} | ||
|
||
int dct_write_app_data(const void* data, uint32_t offset, uint32_t size) { | ||
if (!dct_funcs_inited) { | ||
init_dct_functions(); | ||
dct_funcs_inited = 1; | ||
} | ||
if (HAL_DCT_Write_App_Data) { | ||
return HAL_DCT_Write_App_Data(data, offset, size, NULL /* reserved */); | ||
} | ||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef BOOTLOADER_DCT_H | ||
#define BOOTLOADER_DCT_H | ||
|
||
void load_dct_functions(); | ||
|
||
#endif // BOOTLOADER_DCT_H |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
#pragma once | ||
|
||
#include "dct_hal_stm32f2xx.h" | ||
#include "dcd_flash.h" | ||
#include "dct.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "ota_flash_hal.h" | ||
#include "spark_macros.h" | ||
|
||
#if MODULAR_FIRMWARE | ||
const module_bounds_t module_bootloader = { 0x4000, 0x8000000, 0x8004000, MODULE_FUNCTION_BOOTLOADER, 0, MODULE_STORE_MAIN }; | ||
const module_bounds_t module_system_part1 = { 0x20000, 0x8020000, 0x8040000, MODULE_FUNCTION_SYSTEM_PART, 1, MODULE_STORE_MAIN }; | ||
const module_bounds_t module_system_part2 = { 0x20000, 0x8040000, 0x8060000, MODULE_FUNCTION_SYSTEM_PART, 2, MODULE_STORE_MAIN }; | ||
const module_bounds_t module_system_part3 = { 0x20000, 0x8060000, 0x8080000, MODULE_FUNCTION_SYSTEM_PART, 3, MODULE_STORE_MAIN }; | ||
const module_bounds_t module_user = { 0x20000, 0x8080000, 0x80A0000, MODULE_FUNCTION_USER_PART, 1, MODULE_STORE_MAIN}; | ||
const module_bounds_t module_factory = { 0x20000, 0x80A0000, 0x80C0000, MODULE_FUNCTION_USER_PART, 1, MODULE_STORE_FACTORY}; | ||
const module_bounds_t* module_bounds[] = { &module_bootloader, &module_system_part1, &module_system_part2, &module_system_part3, &module_user, &module_factory }; | ||
|
||
const module_bounds_t module_ota = { 0x20000, 0x80C0000, 0x80E0000, MODULE_FUNCTION_NONE, 0, MODULE_STORE_SCRATCHPAD}; | ||
#else | ||
const module_bounds_t module_bootloader = { 0x4000, 0x8000000, 0x8004000, MODULE_FUNCTION_BOOTLOADER, 0, MODULE_STORE_MAIN}; | ||
const module_bounds_t module_user = { 0x60000, 0x8020000, 0x8080000, MODULE_FUNCTION_MONO_FIRMWARE, 0, MODULE_STORE_MAIN}; | ||
const module_bounds_t module_factory = { 0x60000, 0x8080000, 0x80E0000, MODULE_FUNCTION_MONO_FIRMWARE, 0, MODULE_STORE_FACTORY}; | ||
const module_bounds_t* module_bounds[] = { &module_bootloader, &module_user, &module_factory }; | ||
|
||
const module_bounds_t module_ota = { 0x60000, 0x8080000, 0x80E0000, MODULE_FUNCTION_NONE, 0, MODULE_STORE_SCRATCHPAD}; | ||
#endif | ||
|
||
const unsigned module_bounds_length = arraySize(module_bounds); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "ota_flash_hal.h" | ||
#include "spark_macros.h" | ||
|
||
#if MODULAR_FIRMWARE | ||
const module_bounds_t module_bootloader = { 0x4000, 0x8000000, 0x8004000, MODULE_FUNCTION_BOOTLOADER, 0, MODULE_STORE_MAIN }; | ||
const module_bounds_t module_system_part1 = { 0x40000, 0x8020000, 0x8060000, MODULE_FUNCTION_SYSTEM_PART, 1, MODULE_STORE_MAIN }; | ||
const module_bounds_t module_system_part2 = { 0x40000, 0x8060000, 0x80A0000, MODULE_FUNCTION_SYSTEM_PART, 2, MODULE_STORE_MAIN}; | ||
const module_bounds_t module_user = { 0x20000, 0x80A0000, 0x80C0000, MODULE_FUNCTION_USER_PART, 1, MODULE_STORE_MAIN}; | ||
const module_bounds_t module_factory = { 0x20000, 0x80E0000, 0x8100000, MODULE_FUNCTION_USER_PART, 1, MODULE_STORE_FACTORY}; | ||
const module_bounds_t* module_bounds[] = { &module_bootloader, &module_system_part1, &module_system_part2, &module_user, &module_factory }; | ||
|
||
const module_bounds_t module_ota = { 0x40000, 0x80C0000, 0x8100000, MODULE_FUNCTION_NONE, 0, MODULE_STORE_SCRATCHPAD}; | ||
#else | ||
const module_bounds_t module_bootloader = { 0x4000, 0x8000000, 0x8004000, MODULE_FUNCTION_BOOTLOADER, 0, MODULE_STORE_MAIN}; | ||
const module_bounds_t module_user = { 0x60000, 0x8020000, 0x8080000, MODULE_FUNCTION_MONO_FIRMWARE, 0, MODULE_STORE_MAIN}; | ||
const module_bounds_t module_factory = { 0x60000, 0x8080000, 0x80E0000, MODULE_FUNCTION_MONO_FIRMWARE, 0, MODULE_STORE_FACTORY}; | ||
const module_bounds_t* module_bounds[] = { &module_bootloader, &module_user, &module_factory }; | ||
|
||
const module_bounds_t module_ota = { 0x60000, 0x8080000, 0x80E0000, MODULE_FUNCTION_NONE, 0, MODULE_STORE_SCRATCHPAD}; | ||
#endif | ||
|
||
const unsigned module_bounds_length = arraySize(module_bounds); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
v0.7.0-rc.1 will start at module version
200
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.
Fixed in ca75375