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

Commit ada3f43

Browse files
committed
PYFW-377: Updated OTA partitions offsets according to flash Size - 1.18.3
1 parent 951220e commit ada3f43

File tree

8 files changed

+83
-29
lines changed

8 files changed

+83
-29
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: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,17 @@ typedef struct _boot_info_t
4141
uint32_t crc;
4242
} boot_info_t;
4343

44-
#if defined (FIPY) || defined (GPY) || defined (LOPY4) || defined(WIPY3)
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
4547

46-
#define IMG_SIZE (1980 * 1024)
47-
#define OTAA_DATA_SIZE (4 * 1024)
48-
#define OTA_DATA_INDEX 2
49-
#define IMG_FACTORY_OFFSET (64 * 1024)
50-
#define IMG_UPDATE1_OFFSET (2112 * 1024) // taken from the partitions table
51-
#define OTA_DATA_ADDRESS (0x1FF000)
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
5251

53-
#else
54-
55-
#define IMG_SIZE (1720 * 1024)
5652
#define OTAA_DATA_SIZE (4 * 1024)
5753
#define OTA_DATA_INDEX 2
5854
#define IMG_FACTORY_OFFSET (64 * 1024)
59-
#define IMG_UPDATE1_OFFSET (1792 * 1024) // taken from the partitions table
60-
#define OTA_DATA_ADDRESS (0x1BE000)
61-
62-
#endif
6355

6456
#define IMG_UPDATE2_OFFSET (IMG_FACTORY_OFFSET)
6557

@@ -73,7 +65,8 @@ typedef struct _boot_info_t
7365
#define BOOT_VERSION "V0.2"
7466
#define SPI_SEC_SIZE 0x1000
7567

76-
#define PARTITIONS_COUNT 7
68+
#define PARTITIONS_COUNT_8MB 5
69+
#define PARTITIONS_COUNT_4MB 7
7770

7871
#define PART_TYPE_APP 0x00
7972
#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: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
//#define LOG_LOCAL_LEVEL ESP_LOG_INFO
2222
#include "esp_log.h"
2323
#include "rom/crc.h"
24+
#include "esp32chipinfo.h"
2425

2526
#include "ff.h"
2627

@@ -78,11 +79,13 @@ static esp_err_t updater_spi_flash_write(size_t dest_addr, void *src, size_t siz
7879
******************************************************************************/
7980

8081
bool updater_read_boot_info (boot_info_t *boot_info, uint32_t *boot_info_offset) {
81-
esp_partition_info_t partition_info[PARTITIONS_COUNT];
82+
esp_partition_info_t partition_info[PARTITIONS_COUNT_4MB];
83+
84+
uint8_t part_count = (esp32_get_chip_rev() > 0 ? PARTITIONS_COUNT_8MB : PARTITIONS_COUNT_4MB);
8285

8386
ESP_LOGV(TAG, "Reading boot info\n");
8487

85-
if (ESP_OK != updater_spi_flash_read(ESP_PARTITION_TABLE_ADDR, (void *)partition_info, sizeof(partition_info), true)) {
88+
if (ESP_OK != updater_spi_flash_read(ESP_PARTITION_TABLE_ADDR, (void *)partition_info, (sizeof(esp_partition_info_t) * part_count), true)) {
8689
ESP_LOGE(TAG, "err1\n");
8790
return false;
8891
}
@@ -175,15 +178,27 @@ bool updater_start (void) {
175178
* The new location of otadata is 0x1BE000 or 0x1FF000 as per updated partition table and has size of
176179
* 4096 bytes which is size of a sector
177180
*/
178-
ret = spi_flash_erase_sector(OTA_DATA_ADDRESS / SPI_FLASH_SEC_SIZE);
181+
if (esp32_get_chip_rev() > 0) {
182+
ret = spi_flash_erase_sector(OTA_DATA_ADDRESS_8MB / SPI_FLASH_SEC_SIZE);
183+
}
184+
else {
185+
ret = spi_flash_erase_sector(OTA_DATA_ADDRESS_4MB / SPI_FLASH_SEC_SIZE);
186+
}
179187
if (ESP_OK != ret) {
180188
ESP_LOGE(TAG, "Erasing new sector of boot info failed, error code: %d!\n", ret);
181189
// TODO: try again ???
182190
return false;
183191
}
184192

185193
// Updating the NEW otadata partition with the OLD information
186-
if (true != updater_write_boot_info(&boot_info_local, OTA_DATA_ADDRESS)) {
194+
bool updater_ret = false;
195+
if (esp32_get_chip_rev() > 0) {
196+
updater_ret = updater_write_boot_info(&boot_info_local, OTA_DATA_ADDRESS_8MB);
197+
}
198+
else {
199+
updater_ret = updater_write_boot_info(&boot_info_local, OTA_DATA_ADDRESS_4MB);
200+
}
201+
if (true != updater_ret) {
187202
ESP_LOGE(TAG, "Writing new sector of boot info failed!\n");
188203
//TODO: try again ???
189204
return false;
@@ -198,7 +213,7 @@ bool updater_start (void) {
198213
}
199214

200215
// Writing the new partition table
201-
if (esp_get_revision() > 0) {
216+
if (esp32_get_chip_rev() > 0) {
202217
ret = spi_flash_write(ESP_PARTITION_TABLE_ADDR, (void *)partitions_bin_8MB, sizeof(partitions_bin_8MB));
203218
}
204219
else {
@@ -210,7 +225,7 @@ bool updater_start (void) {
210225
return false;
211226
}
212227

213-
updater_data.size = IMG_SIZE;
228+
updater_data.size = (esp32_get_chip_rev() > 0 ? IMG_SIZE_8MB : IMG_SIZE_4MB);
214229
// check which one should be the next active image
215230
updater_data.offset = updater_ota_next_slot_address();
216231

@@ -356,7 +371,7 @@ bool updater_write_boot_info(boot_info_t *boot_info, uint32_t boot_info_offset)
356371

357372
int updater_ota_next_slot_address() {
358373

359-
int ota_offset = IMG_UPDATE1_OFFSET;
374+
int ota_offset = (esp32_get_chip_rev() > 0 ? IMG_UPDATE1_OFFSET_8MB : IMG_UPDATE1_OFFSET_4MB);;
360375

361376
// check which one should be the next active image
362377
if (updater_read_boot_info (&boot_info, &boot_info_offset)) {

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: 4 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
******************************************************************************/
@@ -127,11 +128,10 @@ void TASK_Micropython (void *pvParameters) {
127128
uint32_t gc_pool_size;
128129
bool soft_reset = false;
129130
bool wifi_on_boot;
130-
esp_chip_info_t chip_info;
131131
uint32_t stack_len;
132+
uint8_t chip_rev = esp32_get_chip_rev();
132133

133-
esp_chip_info(&chip_info);
134-
if (chip_info.revision > 0) {
134+
if (chip_rev > 0) {
135135
stack_len = (MICROPY_TASK_STACK_SIZE_PSRAM / sizeof(StackType_t));
136136
} else {
137137
stack_len = (MICROPY_TASK_STACK_SIZE / sizeof(StackType_t));
@@ -176,7 +176,7 @@ void TASK_Micropython (void *pvParameters) {
176176
// to recover from hiting the limit (the limit is measured in bytes)
177177
mp_stack_set_limit(stack_len - 1024);
178178

179-
if (esp_get_revision() > 0) {
179+
if (esp32_get_chip_rev() > 0) {
180180
gc_pool_size = GC_POOL_SIZE_BYTES_PSRAM;
181181
gc_pool_upy = heap_caps_malloc(GC_POOL_SIZE_BYTES_PSRAM, MALLOC_CAP_SPIRAM);
182182
} else {

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)