Skip to content

Commit

Permalink
Merge branch 'develop' into feature/rgb-led-mirror
Browse files Browse the repository at this point in the history
  Conflicts:
	hal/src/stm32f2xx/hal_dynalib_export.cpp
	modules/photon/system-part2/module_system_part2_export.ld
	modules/photon/system-part2/src/module_system_part2.cpp
  • Loading branch information
technobly committed Dec 16, 2016
2 parents f0ef423 + 68b7467 commit 0b9e2d3
Show file tree
Hide file tree
Showing 19 changed files with 3,525 additions and 3,058 deletions.
3 changes: 3 additions & 0 deletions hal-dynalib/src/hal_bootloader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef HAL_BOOTLOADER_EXCLUDE
#include "hal_dynalib_bootloader.h"
#endif
35 changes: 35 additions & 0 deletions hal/inc/bootloader_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
Copyright (c) 2013-2016 Particle Industries, Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

#ifndef BOOTLOADER_HAL_H_
#define BOOTLOADER_HAL_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

const uint8_t* HAL_Bootloader_Image(uint32_t* size, void* reserved);

#ifdef __cplusplus
}
#endif

#endif /* BOOTLOADER_HAL_H_ */

36 changes: 36 additions & 0 deletions hal/inc/hal_dynalib_bootloader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
******************************************************************************
* @file hal_dynalib_bootloader.h
* @authors Andrey Tolstoy
* @date 15 December 2016
******************************************************************************
Copyright (c) 2016 Particle Industries, Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

#ifndef HAL_DYNALIB_BOOTLOADER_H
#define HAL_DYNALIB_BOOTLOADER_H

#include "dynalib.h"

#ifdef DYNALIB_EXPORT
#include "bootloader_hal.h"
#endif

DYNALIB_BEGIN(hal_bootloader)

DYNALIB_FN(0, hal_bootloader, HAL_Bootloader_Image, const uint8_t*(uint32_t*, void*))

DYNALIB_END(hal_bootloader)

#endif /* HAL_DYNALIB_BOOTLOADER_H */
25 changes: 11 additions & 14 deletions hal/src/stm32f2xx/bootloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include "flash_mal.h"
#include "bootloader.h"
#include "module_info.h"
#include "bootloader_hal.h"

#if !defined(SYSTEM_MINIMAL)
#if PLATFORM_ID==6 || PLATFORM_ID==8
#if PLATFORM_ID==6 || PLATFORM_ID==8 || PLATFORM_ID==10
#define HAL_REPLACE_BOOTLOADER
#endif
#if PLATFORM_ID==6 || PLATFORM_ID==8 || PLATFORM_ID==10
Expand Down Expand Up @@ -37,21 +38,15 @@ bool bootloader_update(const void*, unsigned)
* Manages upgrading the bootloader.
*/

#define CAT2(a,b) a##b
#define CAT(a,b) CAT2(a,b)

#define BOOTLOADER_IMAGE CAT(bootloader_platform_, CAT(PLATFORM_ID,_bin))
#define BOOTLOADER_IMAGE_LEN CAT(bootloader_platform_, CAT(PLATFORM_ID,_bin_len))

extern "C" const unsigned int BOOTLOADER_IMAGE_LEN;
extern "C" const unsigned char BOOTLOADER_IMAGE[];

bool bootloader_requires_update()
bool bootloader_requires_update(const uint8_t* bootloader_image, uint32_t length)
{
if ((bootloader_image == nullptr) || length == 0)
return false;

const uint32_t VERSION_OFFSET = 0x184+10;

uint16_t current_version = *(uint16_t*)(0x8000000+VERSION_OFFSET);
uint16_t available_version = *(uint16_t*)(BOOTLOADER_IMAGE+VERSION_OFFSET);
uint16_t available_version = *(uint16_t*)(bootloader_image+VERSION_OFFSET);

bool requires_update = current_version<available_version;
return requires_update;
Expand All @@ -60,8 +55,10 @@ bool bootloader_requires_update()
bool bootloader_update_if_needed()
{
bool updated = false;
if (bootloader_requires_update()) {
updated = bootloader_update(BOOTLOADER_IMAGE, BOOTLOADER_IMAGE_LEN);
uint32_t bootloader_image_size = 0;
const uint8_t* bootloader_image = HAL_Bootloader_Image(&bootloader_image_size, nullptr);
if (bootloader_requires_update(bootloader_image, bootloader_image_size)) {
updated = bootloader_update(bootloader_image, bootloader_image_size);
}
return updated;
}
Expand Down
3 changes: 2 additions & 1 deletion hal/src/stm32f2xx/bootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
extern "C" {
#endif

#include <stdint.h>

bool bootloader_requires_update();
bool bootloader_requires_update(const uint8_t* bootloader_image, uint32_t length);
bool bootloader_update_if_needed();

bool bootloader_update(const void* bootloader_image, unsigned length);
Expand Down
45 changes: 45 additions & 0 deletions hal/src/stm32f2xx/bootloader_hal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
Copyright (c) 2013-2016 Particle Industries, Inc. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

#ifndef HAL_BOOTLOADER_EXCLUDE

#include "bootloader_hal.h"

#define CAT2(a,b) a##b
#define CAT(a,b) CAT2(a,b)

#define BOOTLOADER_IMAGE CAT(bootloader_platform_, CAT(PLATFORM_ID,_bin))
#define BOOTLOADER_IMAGE_LEN CAT(bootloader_platform_, CAT(PLATFORM_ID,_bin_len))

#ifdef __cplusplus
extern "C" {
#endif
extern const unsigned int BOOTLOADER_IMAGE_LEN;
extern const unsigned char BOOTLOADER_IMAGE[];
#ifdef __cplusplus
}
#endif

const uint8_t* HAL_Bootloader_Image(uint32_t* size, void* reserved)
{
if (size)
*size = (uint32_t)BOOTLOADER_IMAGE_LEN;
return (const uint8_t*)BOOTLOADER_IMAGE;
}

#endif // HAL_BOOTLOADER_EXCLUDE
Loading

0 comments on commit 0b9e2d3

Please sign in to comment.