Skip to content

Commit f51970a

Browse files
authored
Merge branch 'master' into add_incoming_content_length
2 parents 8b71a25 + 0130856 commit f51970a

File tree

9 files changed

+575
-12
lines changed

9 files changed

+575
-12
lines changed

boards.txt

+395-1
Large diffs are not rendered by default.

cores/esp32/esp32-hal-touch.c

-6
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,13 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar
212212
} else {
213213
// attach ISR User Call
214214
__touchInit();
215-
#if SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3
216215
__touchChannelInit(pad);
217-
#endif
218216
__touchInterruptHandlers[pad].fn = userFunc;
219217
__touchInterruptHandlers[pad].callWithArgs = callWithArgs;
220218
__touchInterruptHandlers[pad].arg = Args;
221219
}
222220

223-
#if SOC_TOUCH_VERSION_1 // ESP32
224-
touch_pad_config(pad, threshold);
225-
#elif SOC_TOUCH_VERSION_2 // ESP32S2, ESP32S3
226221
touch_pad_set_thresh(pad, threshold);
227-
#endif
228222
}
229223

230224
// it keeps backwards compatibility

docs/source/guides/tools_menu.rst

+8
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ Events Run On
196196

197197
This function is also used to select the core that runs the Arduino events. This is only valid if the target SoC has 2 cores.
198198

199+
Erase All Flash Before Sketch Upload
200+
************************************
201+
202+
This option selects the flash memory region to be erased before uploading the new sketch.
203+
204+
* **Disabled** - Upload the sketch without erasing all flash contents. (Default)
205+
* **Enabled** - Erase all flash contents before uploading the sketch.
206+
199207
Port
200208
****
201209

libraries/Update/src/Update.h

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
#define ENCRYPTED_BLOCK_SIZE 16
3030

31+
#define SPI_SECTORS_PER_BLOCK 16 // usually large erase block is 32k/64k
32+
#define SPI_FLASH_BLOCK_SIZE (SPI_SECTORS_PER_BLOCK*SPI_FLASH_SEC_SIZE)
33+
3134
class UpdateClass {
3235
public:
3336
typedef std::function<void(size_t, size_t)> THandlerFunction_Progress;
@@ -166,6 +169,7 @@ class UpdateClass {
166169
bool _verifyHeader(uint8_t data);
167170
bool _verifyEnd();
168171
bool _enablePartition(const esp_partition_t* partition);
172+
bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty
169173

170174

171175
uint8_t _error;

libraries/Update/src/Updater.cpp

+29-4
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,23 @@ bool UpdateClass::_writeBuffer(){
203203
if (!_progress && _progress_callback) {
204204
_progress_callback(0, _size);
205205
}
206-
if(!ESP.partitionEraseRange(_partition, _progress, SPI_FLASH_SEC_SIZE)){
207-
_abort(UPDATE_ERROR_ERASE);
208-
return false;
206+
size_t offset = _partition->address + _progress;
207+
bool block_erase = (_size - _progress >= SPI_FLASH_BLOCK_SIZE) && (offset % SPI_FLASH_BLOCK_SIZE == 0); // if it's the block boundary, than erase the whole block from here
208+
bool part_head_sectors = _partition->address % SPI_FLASH_BLOCK_SIZE && offset < (_partition->address / SPI_FLASH_BLOCK_SIZE + 1) * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition heading block
209+
bool part_tail_sectors = offset >= (_partition->address + _size) / SPI_FLASH_BLOCK_SIZE * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition tailing block
210+
if (block_erase || part_head_sectors || part_tail_sectors){
211+
if(!ESP.partitionEraseRange(_partition, _progress, block_erase ? SPI_FLASH_BLOCK_SIZE : SPI_FLASH_SEC_SIZE)){
212+
_abort(UPDATE_ERROR_ERASE);
213+
return false;
214+
}
209215
}
210-
if (!ESP.partitionWrite(_partition, _progress + skip, (uint32_t*)_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) {
216+
217+
// try to skip empty blocks on unecrypted partitions
218+
if ((_partition->encrypted || _chkDataInBlock(_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) && !ESP.partitionWrite(_partition, _progress + skip, (uint32_t*)_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) {
211219
_abort(UPDATE_ERROR_WRITE);
212220
return false;
213221
}
222+
214223
//restore magic or md5 will fail
215224
if(!_progress && _command == U_FLASH){
216225
_buffer[0] = ESP_IMAGE_HEADER_MAGIC;
@@ -389,4 +398,20 @@ const char * UpdateClass::errorString(){
389398
return _err2str(_error);
390399
}
391400

401+
bool UpdateClass::_chkDataInBlock(const uint8_t *data, size_t len) const {
402+
// check 32-bit aligned blocks only
403+
if (!len || len % sizeof(uint32_t))
404+
return true;
405+
406+
size_t dwl = len / sizeof(uint32_t);
407+
408+
do {
409+
if (*(uint32_t*)data ^ 0xffffffff) // for SPI NOR flash empty blocks are all one's, i.e. filled with 0xff byte
410+
return true;
411+
412+
data += sizeof(uint32_t);
413+
} while (--dwl);
414+
return false;
415+
}
416+
392417
UpdateClass Update;

platform.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pluggable_monitor.required.serial=builtin:serial-monitor
211211
tools.esptool_py.upload.protocol=serial
212212
tools.esptool_py.upload.params.verbose=
213213
tools.esptool_py.upload.params.quiet=
214-
tools.esptool_py.upload.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" {upload.extra_flags}
214+
tools.esptool_py.upload.pattern_args=--chip {build.mcu} --port "{serial.port}" --baud {upload.speed} {upload.flags} --before default_reset --after hard_reset write_flash {upload.erase_cmd} -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x10000 "{build.path}/{build.project_name}.bin" {upload.extra_flags}
215215
tools.esptool_py.upload.pattern="{path}/{cmd}" {upload.pattern_args}
216216
tools.esptool_py.upload.pattern.linux=python3 "{path}/{cmd}" {upload.pattern_args}
217217

tools/partitions/max_app_8MB.csv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Name, Type, SubType, Offset, Size, Flags
2+
nvs, data, nvs, 0x9000, 0x5000,
3+
otadata, data, ota, 0xe000, 0x2000,
4+
app0, app, factory, 0x10000, 0x7F0000,

variants/unphone8/pins_arduino.h

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifndef Pins_Arduino_h
2+
#define Pins_Arduino_h
3+
4+
#include <stdint.h>
5+
6+
#define USB_VID 0x16D0
7+
#define USB_PID 0x1178
8+
9+
#define EXTERNAL_NUM_INTERRUPTS 46
10+
#define NUM_DIGITAL_PINS 48
11+
#define NUM_ANALOG_INPUTS 20
12+
13+
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
14+
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
15+
#define digitalPinHasPWM(p) (p < 46)
16+
17+
#define LED_BUILTIN 13
18+
#define BUILTIN_LED LED_BUILTIN // backward compatibility
19+
20+
static const uint8_t TX = 37;
21+
static const uint8_t RX = 36;
22+
23+
static const uint8_t SDA = 1;
24+
static const uint8_t SCL = 2;
25+
26+
static const uint8_t SS = 3;
27+
static const uint8_t MOSI = 39;
28+
static const uint8_t MISO = 40;
29+
static const uint8_t SCK = 38;
30+
31+
static const uint8_t A0 = 1;
32+
static const uint8_t A1 = 2;
33+
static const uint8_t A2 = 8;
34+
static const uint8_t A3 = 9;
35+
static const uint8_t A4 = 5;
36+
static const uint8_t A5 = 6;
37+
static const uint8_t A6 = 14;
38+
static const uint8_t A7 = 7;
39+
static const uint8_t A8 = 15;
40+
static const uint8_t A9 = 33;
41+
static const uint8_t A10 = 27;
42+
static const uint8_t A11 = 12;
43+
static const uint8_t A12 = 13;
44+
static const uint8_t A13 = 14;
45+
static const uint8_t A14 = 15;
46+
static const uint8_t A15 = 16;
47+
static const uint8_t A16 = 17;
48+
static const uint8_t A17 = 18;
49+
static const uint8_t A18 = 19;
50+
static const uint8_t A19 = 20;
51+
52+
static const uint8_t T1 = 2;
53+
static const uint8_t T2 = 8;
54+
static const uint8_t T3 = 9;
55+
static const uint8_t T4 = 5;
56+
static const uint8_t T5 = 6;
57+
static const uint8_t T6 = 14;
58+
static const uint8_t T7 = 7;
59+
static const uint8_t T8 = 15;
60+
static const uint8_t T9 = 33;
61+
static const uint8_t T10 = 27;
62+
static const uint8_t T11 = 12;
63+
static const uint8_t T12 = 13;
64+
static const uint8_t T13 = 14;
65+
static const uint8_t T14 = 15;
66+
67+
#endif /* Pins_Arduino_h */

variants/unphone9/pins_arduino.h

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifndef Pins_Arduino_h
2+
#define Pins_Arduino_h
3+
4+
#include <stdint.h>
5+
6+
#define USB_VID 0x16D0
7+
#define USB_PID 0x1178
8+
9+
#define EXTERNAL_NUM_INTERRUPTS 46
10+
#define NUM_DIGITAL_PINS 48
11+
#define NUM_ANALOG_INPUTS 20
12+
13+
#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)
14+
#define digitalPinToInterrupt(p) (((p)<48)?(p):-1)
15+
#define digitalPinHasPWM(p) (p < 46)
16+
17+
#define LED_BUILTIN 13
18+
#define BUILTIN_LED LED_BUILTIN // backward compatibility
19+
20+
static const uint8_t TX = 43;
21+
static const uint8_t RX = 44;
22+
23+
static const uint8_t SDA = 3;
24+
static const uint8_t SCL = 4;
25+
26+
static const uint8_t SS = 13;
27+
static const uint8_t MOSI = 40;
28+
static const uint8_t MISO = 41;
29+
static const uint8_t SCK = 39;
30+
31+
static const uint8_t A0 = 1;
32+
static const uint8_t A1 = 2;
33+
static const uint8_t A2 = 8;
34+
static const uint8_t A3 = 9;
35+
static const uint8_t A4 = 5;
36+
static const uint8_t A5 = 6;
37+
static const uint8_t A6 = 14;
38+
static const uint8_t A7 = 7;
39+
static const uint8_t A8 = 15;
40+
static const uint8_t A9 = 33;
41+
static const uint8_t A10 = 27;
42+
static const uint8_t A11 = 12;
43+
static const uint8_t A12 = 13;
44+
static const uint8_t A13 = 14;
45+
static const uint8_t A14 = 15;
46+
static const uint8_t A15 = 16;
47+
static const uint8_t A16 = 17;
48+
static const uint8_t A17 = 18;
49+
static const uint8_t A18 = 19;
50+
static const uint8_t A19 = 20;
51+
52+
static const uint8_t T1 = 2;
53+
static const uint8_t T2 = 8;
54+
static const uint8_t T3 = 9;
55+
static const uint8_t T4 = 5;
56+
static const uint8_t T5 = 6;
57+
static const uint8_t T6 = 14;
58+
static const uint8_t T7 = 7;
59+
static const uint8_t T8 = 15;
60+
static const uint8_t T9 = 33;
61+
static const uint8_t T10 = 27;
62+
static const uint8_t T11 = 12;
63+
static const uint8_t T12 = 13;
64+
static const uint8_t T13 = 14;
65+
static const uint8_t T14 = 15;
66+
67+
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)