Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
[v1.18.3] Special release - pre-requisite for OTA update from 1.18.2 …
Browse files Browse the repository at this point in the history
…to 1.20 Firmware

Since new Firmwares [1.20.0.xx] has increasted partition sizes and partition table structure this Intermidiate Firmware is required as 1st Step OTA to a final OTA upgrade to v1.20.0.xx from 1.18.2
before upgrading to this Firmware please see: https://docs.pycom.io/tutorials/all/ota/
  • Loading branch information
iwahdan88 committed Sep 15, 2019
2 parents df9f237 + 47980f1 commit d19c9e9
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 18 deletions.
1 change: 1 addition & 0 deletions esp32/application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ APP_UTIL_SRC_C = $(addprefix util/,\
mpirq.c \
mpsleep.c \
timeutils.c \
esp32chipinfo.c \
)

APP_FATFS_SRC_C = $(addprefix fatfs/src/,\
Expand Down
14 changes: 11 additions & 3 deletions esp32/bootloader/bootloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@ typedef struct _boot_info_t
uint32_t crc;
} boot_info_t;

#define IMG_SIZE ((1024 + 512) * 1024)
#define IMG_SIZE_8MB (1980 * 1024)
#define IMG_UPDATE1_OFFSET_8MB (2112 * 1024) // taken from the partitions table
#define OTA_DATA_ADDRESS_8MB (0x1FF000) // calculated from partitions table

#define IMG_SIZE_4MB (1720 * 1024)
#define IMG_UPDATE1_OFFSET_4MB (1792 * 1024) // taken from the partitions table
#define OTA_DATA_ADDRESS_4MB (0x1BE000) // calculated from partitions table

#define OTAA_DATA_SIZE (4 * 1024)
#define OTA_DATA_INDEX 2
#define IMG_FACTORY_OFFSET (64 * 1024)
#define IMG_UPDATE1_OFFSET (1664 * 1024) // taken from the partitions table

#define IMG_UPDATE2_OFFSET (IMG_FACTORY_OFFSET)

#define IMG_STATUS_CHECK 0
Expand All @@ -58,7 +65,8 @@ typedef struct _boot_info_t
#define BOOT_VERSION "V0.2"
#define SPI_SEC_SIZE 0x1000

#define PARTITIONS_COUNT 7
#define PARTITIONS_COUNT_8MB 5
#define PARTITIONS_COUNT_4MB 7

#define PART_TYPE_APP 0x00
#define PART_SUBTYPE_FACTORY 0x00
Expand Down
3 changes: 2 additions & 1 deletion esp32/fatfs/src/drivers/sflash_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "esp_spi_flash.h"
#include "esp_flash_encrypt.h"
#include "esp32chipinfo.h"

static uint8_t *sflash_block_cache;
static bool sflash_cache_is_dirty;
Expand Down Expand Up @@ -43,7 +44,7 @@ static bool sflash_write (void) {
DRESULT sflash_disk_init (void) {
if (!sflash_init_done) {
// this is how we diferentiate flash sizes in Pycom modules
if (esp_get_revision() > 0) {
if (esp32_get_chip_rev() > 0) {
sflash_start_address = SFLASH_START_ADDR_8MB;
sflash_fs_sector_count = SFLASH_FS_SECTOR_COUNT_8MB;
} else {
Expand Down
149 changes: 144 additions & 5 deletions esp32/ftp/updater.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions esp32/lib/.~lock.partitions.csv#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Géza Husi,gezahusi,Geza-laptop,21.05.2019 18:36,file:///home/gezahusi/snap/libreoffice/118/.config/libreoffice/4;
Binary file modified esp32/lib/libspi_flash.a
Binary file not shown.
7 changes: 5 additions & 2 deletions esp32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "pins.h"
#include "mperror.h"
#include "machtimer.h"
#include "esp32chipinfo.h"


TaskHandle_t mpTaskHandle;
Expand Down Expand Up @@ -104,6 +105,8 @@ static StaticTask_t mpTaskTCB;
* Returns : none
*******************************************************************************/
void app_main(void) {

esp32_init_chip_info();
// remove all the logs from the IDF
esp_log_level_set("*", ESP_LOG_NONE);

Expand All @@ -123,15 +126,15 @@ void app_main(void) {
mperror_pre_init();

// differentiate the Flash Size (either 8MB or 4MB) based on ESP32 rev id
micropy_hw_flash_size = (esp_get_revision() > 0 ? 0x800000 : 0x400000);
micropy_hw_flash_size = (esp32_get_chip_rev() > 0 ? 0x800000 : 0x400000);

// propagating the Flash Size in the global variable (used in multiple IDF modules)
g_rom_flashchip.chip_size = micropy_hw_flash_size;

esp_chip_info_t chip_info;
esp_chip_info(&chip_info);

if (chip_info.revision > 0) {
if (esp32_get_chip_rev() > 0) {
micropy_hw_antenna_diversity_pin_num = MICROPY_SECOND_GEN_ANT_SELECT_PIN_NUM;

micropy_lpwan_ncs_pin_index = 1;
Expand Down
34 changes: 30 additions & 4 deletions esp32/mptask.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@


#include "lteppp.h"
#include "esp32chipinfo.h"
/******************************************************************************
DECLARE EXTERNAL FUNCTIONS
******************************************************************************/
Expand All @@ -90,6 +91,8 @@ extern void modpycom_init0(void);
#define GC_POOL_SIZE_BYTES (67 * 1024)
#define GC_POOL_SIZE_BYTES_PSRAM ((2048 + 512) * 1024)

#define OTA_DATA_ADDRESS_OLD (0x190000)

/******************************************************************************
DECLARE PRIVATE FUNCTIONS
******************************************************************************/
Expand All @@ -116,6 +119,8 @@ static uint8_t *gc_pool_upy;
static char fresh_main_py[] = "# main.py -- put your code here!\r\n";
static char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n";

extern bool update_to_factory_partition(void);

/******************************************************************************
DEFINE PUBLIC FUNCTIONS
******************************************************************************/
Expand All @@ -125,16 +130,37 @@ void TASK_Micropython (void *pvParameters) {
uint32_t gc_pool_size;
bool soft_reset = false;
bool wifi_on_boot;
esp_chip_info_t chip_info;
uint32_t stack_len;
uint8_t chip_rev = esp32_get_chip_rev();

esp_chip_info(&chip_info);
if (chip_info.revision > 0) {
if (chip_rev > 0) {
stack_len = (MICROPY_TASK_STACK_SIZE_PSRAM / sizeof(StackType_t));
} else {
stack_len = (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t));
}

boot_info_t boot_info_local;
uint32_t boot_info_offset_local;
bool ret = false;
while(false == ret) {
ret = updater_read_boot_info(&boot_info_local, &boot_info_offset_local);
}
if(boot_info_local.ActiveImg != IMG_ACT_FACTORY) {
// Only copy if coming from older version (1.18.2) and this is not a downgrade
// In case of upgrade the boot_info located under 0x190000 address
// In case of a downgrade, the boot info located somewhere else than 0x190000 because of the updated partition table
if(boot_info_offset_local == (uint32_t)OTA_DATA_ADDRESS_OLD){
printf("Copying image from OTA_0 partition to Factory partition, please wait...\n");
if(true == update_to_factory_partition()) {
printf("Image copy finished successfully!\n");
}

//Restart the system
machine_wdt_start(100);
for ( ; ; );
}
}

// configure the antenna select switch here
antenna_init0();
config_init0();
Expand All @@ -157,7 +183,7 @@ void TASK_Micropython (void *pvParameters) {
// to recover from hiting the limit (the limit is measured in bytes)
mp_stack_set_limit(stack_len - 1024);

if (esp_get_revision() > 0) {
if (esp32_get_chip_rev() > 0) {
gc_pool_size = GC_POOL_SIZE_BYTES_PSRAM;
gc_pool_upy = heap_caps_malloc(GC_POOL_SIZE_BYTES_PSRAM, MALLOC_CAP_SPIRAM);
} else {
Expand Down
2 changes: 1 addition & 1 deletion esp32/mptask.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
******************************************************************************/
#define MICROPY_TASK_PRIORITY MP_THREAD_PRIORITY
#define MICROPY_TASK_STACK_SIZE (8 * 1024)
#define MICROPY_TASK_STACK_SIZE_PSRAM (12 * 1024)
#define MICROPY_TASK_STACK_SIZE_PSRAM (2*12 * 1024)

/******************************************************************************
DECLARE PUBLIC FUNCTIONS
Expand Down
2 changes: 1 addition & 1 deletion esp32/pycom_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef VERSION_H_
#define VERSION_H_

#define SW_VERSION_NUMBER "1.18.2.r7"
#define SW_VERSION_NUMBER "1.18.3"

#define LORAWAN_VERSION_NUMBER "1.0.2"

Expand Down
2 changes: 1 addition & 1 deletion esp32/sdkconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#define CONFIG_MBEDTLS_ECP_C 1
#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1024
#define CONFIG_MBEDTLS_RC4_DISABLED 1
#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED 1
#define CONFIG_CONSOLE_UART_NUM 0
#define CONFIG_ESP32_APPTRACE_LOCK_ENABLE 1
#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1
Expand Down Expand Up @@ -228,6 +229,5 @@
#define CONFIG_MONITOR_BAUD_OTHER_VAL 115200
#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1
#define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0"
#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1
#define CONFIG_OPTIMIZATION_LEVEL_RELEASE 1
#define CONFIG_BLUEDROID_PINNED_TO_CORE 0
25 changes: 25 additions & 0 deletions esp32/util/esp32chipinfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2019, Pycom Limited.
*
* This software is licensed under the GNU GPL version 3 or any
* later version, with permitted additional terms. For more information
* see the Pycom Licence v1.0 document supplied with this file, or
* available at https://www.pycom.io/opensource/licensing
*/

#include "esp_system.h"

static esp_chip_info_t chip_info;

void esp32_init_chip_info(void)
{
// Get chip Info
esp_chip_info(&chip_info);
}

uint8_t esp32_get_chip_rev(void)
{
return chip_info.revision;
}


16 changes: 16 additions & 0 deletions esp32/util/esp32chipinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2019, Pycom Limited.
*
* This software is licensed under the GNU GPL version 3 or any
* later version, with permitted additional terms. For more information
* see the Pycom Licence v1.0 document supplied with this file, or
* available at https://www.pycom.io/opensource/licensing
*/

#ifndef ESP32_UTIL_ESP32CHIPINFO_H_
#define ESP32_UTIL_ESP32CHIPINFO_H_

extern void esp32_init_chip_info(void);
extern uint8_t esp32_get_chip_rev(void);

#endif /* ESP32_UTIL_ESP32CHIPINFO_H_ */

0 comments on commit d19c9e9

Please sign in to comment.