bootloader_support: refactor to better support multi target

This commit is contained in:
morris
2019-12-12 19:03:25 +08:00
committed by bot
parent ba7c67ece8
commit 888316fc64
10 changed files with 822 additions and 509 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -11,30 +11,17 @@
// 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.
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include "esp_log.h"
#include "bootloader_config.h"
#include "bootloader_init.h"
#include "bootloader_utility.h"
#include "bootloader_common.h"
#include "sdkconfig.h"
#include "esp_image_format.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp32/rom/gpio.h"
#include "esp32/rom/rtc.h"
#include "esp32/rom/spi_flash.h"
#elif CONFIG_IDF_TARGET_ESP32S2BETA
#include "esp32s2beta/rom/gpio.h"
#include "esp32s2beta/rom/rtc.h"
#include "esp32s2beta/rom/spi_flash.h"
#endif
static const char *TAG = "boot";
static int select_partition_number (bootloader_state_t *bs);
static int select_partition_number(bootloader_state_t *bs);
static int selected_boot_partition(const bootloader_state_t *bs);
/*
* We arrive here after the ROM bootloader finished loading this second stage bootloader from flash.
* The hardware is mostly uninitialized, flash cache is down and the app CPU is in reset.
@@ -56,7 +43,7 @@ void __attribute__((noreturn)) call_start_cpu0(void)
#endif
// 2. Select the number of boot partition
bootloader_state_t bs = { 0 };
bootloader_state_t bs = {0};
int boot_index = select_partition_number(&bs);
if (boot_index == INVALID_INDEX) {
bootloader_reset();
@@ -67,7 +54,7 @@ void __attribute__((noreturn)) call_start_cpu0(void)
}
// Select the number of boot partition
static int select_partition_number (bootloader_state_t *bs)
static int select_partition_number(bootloader_state_t *bs)
{
// 1. Load partition table
if (!bootloader_utility_load_partition_table(bs)) {
@@ -89,7 +76,7 @@ static int selected_boot_partition(const bootloader_state_t *bs)
if (boot_index == INVALID_INDEX) {
return boot_index; // Unrecoverable failure (not due to corrupt ota data or bad partition contents)
}
if (rtc_get_reset_reason(0) != DEEPSLEEP_RESET) {
if (bootloader_common_get_reset_reason(0) != DEEPSLEEP_RESET) {
// Factory firmware.
#ifdef CONFIG_BOOTLOADER_FACTORY_RESET
if (bootloader_common_check_long_hold_gpio(CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET, CONFIG_BOOTLOADER_HOLD_TIME_GPIO) == 1) {
@@ -128,7 +115,7 @@ static int selected_boot_partition(const bootloader_state_t *bs)
}
// Return global reent struct if any newlib functions are linked to bootloader
struct _reent* __getreent(void) {
struct _reent *__getreent(void)
{
return _GLOBAL_REENT;
}