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

Commit d19c9e9

Browse files
author
iwahdan88
committed
[v1.18.3] Special release - pre-requisite for OTA update from 1.18.2 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/
2 parents df9f237 + 47980f1 commit d19c9e9

File tree

13 files changed

+238
-18
lines changed

13 files changed

+238
-18
lines changed

esp32/application.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ APP_UTIL_SRC_C = $(addprefix util/,\
168168
mpirq.c \
169169
mpsleep.c \
170170
timeutils.c \
171+
esp32chipinfo.c \
171172
)
172173

173174
APP_FATFS_SRC_C = $(addprefix fatfs/src/,\

esp32/bootloader/bootloader.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ typedef struct _boot_info_t
4141
uint32_t crc;
4242
} boot_info_t;
4343

44-
#define IMG_SIZE ((1024 + 512) * 1024)
44+
#define IMG_SIZE_8MB (1980 * 1024)
45+
#define IMG_UPDATE1_OFFSET_8MB (2112 * 1024) // taken from the partitions table
46+
#define OTA_DATA_ADDRESS_8MB (0x1FF000) // calculated from partitions table
47+
48+
#define IMG_SIZE_4MB (1720 * 1024)
49+
#define IMG_UPDATE1_OFFSET_4MB (1792 * 1024) // taken from the partitions table
50+
#define OTA_DATA_ADDRESS_4MB (0x1BE000) // calculated from partitions table
51+
4552
#define OTAA_DATA_SIZE (4 * 1024)
4653
#define OTA_DATA_INDEX 2
4754
#define IMG_FACTORY_OFFSET (64 * 1024)
48-
#define IMG_UPDATE1_OFFSET (1664 * 1024) // taken from the partitions table
55+
4956
#define IMG_UPDATE2_OFFSET (IMG_FACTORY_OFFSET)
5057

5158
#define IMG_STATUS_CHECK 0
@@ -58,7 +65,8 @@ typedef struct _boot_info_t
5865
#define BOOT_VERSION "V0.2"
5966
#define SPI_SEC_SIZE 0x1000
6067

61-
#define PARTITIONS_COUNT 7
68+
#define PARTITIONS_COUNT_8MB 5
69+
#define PARTITIONS_COUNT_4MB 7
6270

6371
#define PART_TYPE_APP 0x00
6472
#define PART_SUBTYPE_FACTORY 0x00

esp32/fatfs/src/drivers/sflash_diskio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "esp_spi_flash.h"
1616
#include "esp_flash_encrypt.h"
17+
#include "esp32chipinfo.h"
1718

1819
static uint8_t *sflash_block_cache;
1920
static bool sflash_cache_is_dirty;
@@ -43,7 +44,7 @@ static bool sflash_write (void) {
4344
DRESULT sflash_disk_init (void) {
4445
if (!sflash_init_done) {
4546
// this is how we diferentiate flash sizes in Pycom modules
46-
if (esp_get_revision() > 0) {
47+
if (esp32_get_chip_rev() > 0) {
4748
sflash_start_address = SFLASH_START_ADDR_8MB;
4849
sflash_fs_sector_count = SFLASH_FS_SECTOR_COUNT_8MB;
4950
} else {

esp32/ftp/updater.c

Lines changed: 144 additions & 5 deletions
Large diffs are not rendered by default.

esp32/lib/.~lock.partitions.csv#

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Géza Husi,gezahusi,Geza-laptop,21.05.2019 18:36,file:///home/gezahusi/snap/libreoffice/118/.config/libreoffice/4;

esp32/lib/libspi_flash.a

-1.28 KB
Binary file not shown.

esp32/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "pins.h"
5252
#include "mperror.h"
5353
#include "machtimer.h"
54+
#include "esp32chipinfo.h"
5455

5556

5657
TaskHandle_t mpTaskHandle;
@@ -104,6 +105,8 @@ static StaticTask_t mpTaskTCB;
104105
* Returns : none
105106
*******************************************************************************/
106107
void app_main(void) {
108+
109+
esp32_init_chip_info();
107110
// remove all the logs from the IDF
108111
esp_log_level_set("*", ESP_LOG_NONE);
109112

@@ -123,15 +126,15 @@ void app_main(void) {
123126
mperror_pre_init();
124127

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

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

131134
esp_chip_info_t chip_info;
132135
esp_chip_info(&chip_info);
133136

134-
if (chip_info.revision > 0) {
137+
if (esp32_get_chip_rev() > 0) {
135138
micropy_hw_antenna_diversity_pin_num = MICROPY_SECOND_GEN_ANT_SELECT_PIN_NUM;
136139

137140
micropy_lpwan_ncs_pin_index = 1;

esp32/mptask.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979

8080

8181
#include "lteppp.h"
82+
#include "esp32chipinfo.h"
8283
/******************************************************************************
8384
DECLARE EXTERNAL FUNCTIONS
8485
******************************************************************************/
@@ -90,6 +91,8 @@ extern void modpycom_init0(void);
9091
#define GC_POOL_SIZE_BYTES (67 * 1024)
9192
#define GC_POOL_SIZE_BYTES_PSRAM ((2048 + 512) * 1024)
9293

94+
#define OTA_DATA_ADDRESS_OLD (0x190000)
95+
9396
/******************************************************************************
9497
DECLARE PRIVATE FUNCTIONS
9598
******************************************************************************/
@@ -116,6 +119,8 @@ static uint8_t *gc_pool_upy;
116119
static char fresh_main_py[] = "# main.py -- put your code here!\r\n";
117120
static char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n";
118121

122+
extern bool update_to_factory_partition(void);
123+
119124
/******************************************************************************
120125
DEFINE PUBLIC FUNCTIONS
121126
******************************************************************************/
@@ -125,16 +130,37 @@ void TASK_Micropython (void *pvParameters) {
125130
uint32_t gc_pool_size;
126131
bool soft_reset = false;
127132
bool wifi_on_boot;
128-
esp_chip_info_t chip_info;
129133
uint32_t stack_len;
134+
uint8_t chip_rev = esp32_get_chip_rev();
130135

131-
esp_chip_info(&chip_info);
132-
if (chip_info.revision > 0) {
136+
if (chip_rev > 0) {
133137
stack_len = (MICROPY_TASK_STACK_SIZE_PSRAM / sizeof(StackType_t));
134138
} else {
135139
stack_len = (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t));
136140
}
137141

142+
boot_info_t boot_info_local;
143+
uint32_t boot_info_offset_local;
144+
bool ret = false;
145+
while(false == ret) {
146+
ret = updater_read_boot_info(&boot_info_local, &boot_info_offset_local);
147+
}
148+
if(boot_info_local.ActiveImg != IMG_ACT_FACTORY) {
149+
// Only copy if coming from older version (1.18.2) and this is not a downgrade
150+
// In case of upgrade the boot_info located under 0x190000 address
151+
// In case of a downgrade, the boot info located somewhere else than 0x190000 because of the updated partition table
152+
if(boot_info_offset_local == (uint32_t)OTA_DATA_ADDRESS_OLD){
153+
printf("Copying image from OTA_0 partition to Factory partition, please wait...\n");
154+
if(true == update_to_factory_partition()) {
155+
printf("Image copy finished successfully!\n");
156+
}
157+
158+
//Restart the system
159+
machine_wdt_start(100);
160+
for ( ; ; );
161+
}
162+
}
163+
138164
// configure the antenna select switch here
139165
antenna_init0();
140166
config_init0();
@@ -157,7 +183,7 @@ void TASK_Micropython (void *pvParameters) {
157183
// to recover from hiting the limit (the limit is measured in bytes)
158184
mp_stack_set_limit(stack_len - 1024);
159185

160-
if (esp_get_revision() > 0) {
186+
if (esp32_get_chip_rev() > 0) {
161187
gc_pool_size = GC_POOL_SIZE_BYTES_PSRAM;
162188
gc_pool_upy = heap_caps_malloc(GC_POOL_SIZE_BYTES_PSRAM, MALLOC_CAP_SPIRAM);
163189
} else {

esp32/mptask.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
******************************************************************************/
1818
#define MICROPY_TASK_PRIORITY MP_THREAD_PRIORITY
1919
#define MICROPY_TASK_STACK_SIZE (8 * 1024)
20-
#define MICROPY_TASK_STACK_SIZE_PSRAM (12 * 1024)
20+
#define MICROPY_TASK_STACK_SIZE_PSRAM (2*12 * 1024)
2121

2222
/******************************************************************************
2323
DECLARE PUBLIC FUNCTIONS

esp32/pycom_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef VERSION_H_
1111
#define VERSION_H_
1212

13-
#define SW_VERSION_NUMBER "1.18.2.r7"
13+
#define SW_VERSION_NUMBER "1.18.3"
1414

1515
#define LORAWAN_VERSION_NUMBER "1.0.2"
1616

esp32/sdkconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#define CONFIG_MBEDTLS_ECP_C 1
7272
#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1024
7373
#define CONFIG_MBEDTLS_RC4_DISABLED 1
74+
#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED 1
7475
#define CONFIG_CONSOLE_UART_NUM 0
7576
#define CONFIG_ESP32_APPTRACE_LOCK_ENABLE 1
7677
#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1
@@ -228,6 +229,5 @@
228229
#define CONFIG_MONITOR_BAUD_OTHER_VAL 115200
229230
#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1
230231
#define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0"
231-
#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1
232232
#define CONFIG_OPTIMIZATION_LEVEL_RELEASE 1
233233
#define CONFIG_BLUEDROID_PINNED_TO_CORE 0

esp32/util/esp32chipinfo.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2019, Pycom Limited.
3+
*
4+
* This software is licensed under the GNU GPL version 3 or any
5+
* later version, with permitted additional terms. For more information
6+
* see the Pycom Licence v1.0 document supplied with this file, or
7+
* available at https://www.pycom.io/opensource/licensing
8+
*/
9+
10+
#include "esp_system.h"
11+
12+
static esp_chip_info_t chip_info;
13+
14+
void esp32_init_chip_info(void)
15+
{
16+
// Get chip Info
17+
esp_chip_info(&chip_info);
18+
}
19+
20+
uint8_t esp32_get_chip_rev(void)
21+
{
22+
return chip_info.revision;
23+
}
24+
25+

esp32/util/esp32chipinfo.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2019, Pycom Limited.
3+
*
4+
* This software is licensed under the GNU GPL version 3 or any
5+
* later version, with permitted additional terms. For more information
6+
* see the Pycom Licence v1.0 document supplied with this file, or
7+
* available at https://www.pycom.io/opensource/licensing
8+
*/
9+
10+
#ifndef ESP32_UTIL_ESP32CHIPINFO_H_
11+
#define ESP32_UTIL_ESP32CHIPINFO_H_
12+
13+
extern void esp32_init_chip_info(void);
14+
extern uint8_t esp32_get_chip_rev(void);
15+
16+
#endif /* ESP32_UTIL_ESP32CHIPINFO_H_ */

0 commit comments

Comments
 (0)