tasmota-webserial-esptool 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/.github/dependabot.yml +10 -0
  2. package/.github/workflows/build_upload.yml +31 -0
  3. package/.github/workflows/ci.yml +22 -0
  4. package/.prettierignore +1 -0
  5. package/README.md +18 -0
  6. package/css/dark.css +91 -0
  7. package/css/light.css +79 -0
  8. package/css/style.css +383 -0
  9. package/dist/const.d.ts +159 -0
  10. package/dist/const.js +252 -0
  11. package/dist/esp_loader.d.ts +166 -0
  12. package/dist/esp_loader.js +931 -0
  13. package/dist/index.d.ts +6 -0
  14. package/dist/index.js +12 -0
  15. package/dist/struct.d.ts +2 -0
  16. package/dist/struct.js +105 -0
  17. package/dist/stubs/esp32.json +1 -0
  18. package/dist/stubs/esp32c3.json +1 -0
  19. package/dist/stubs/esp32s2.json +1 -0
  20. package/dist/stubs/esp32s3.json +1 -0
  21. package/dist/stubs/esp8266.json +1 -0
  22. package/dist/stubs/index.d.ts +10 -0
  23. package/dist/stubs/index.js +26 -0
  24. package/dist/util.d.ts +14 -0
  25. package/dist/util.js +46 -0
  26. package/dist/web/esp32-a2dcbc2e.js +1 -0
  27. package/dist/web/esp32c3-18e9678b.js +1 -0
  28. package/dist/web/esp32s2-3109ccc6.js +1 -0
  29. package/dist/web/esp32s3-c1dbd867.js +1 -0
  30. package/dist/web/esp8266-144419c0.js +1 -0
  31. package/dist/web/index.js +1 -0
  32. package/index.html +196 -0
  33. package/js/esptool.js +1292 -0
  34. package/js/modules/esp32-a2dcbc2e.js +1 -0
  35. package/js/modules/esp32c3-18e9678b.js +1 -0
  36. package/js/modules/esp32s2-3109ccc6.js +1 -0
  37. package/js/modules/esp32s3-c1dbd867.js +1 -0
  38. package/js/modules/esp8266-144419c0.js +1 -0
  39. package/js/modules/esptool.js +1 -0
  40. package/js/script.js +447 -0
  41. package/js/utilities.js +148 -0
  42. package/license.md +12 -0
  43. package/package.json +36 -0
  44. package/rollup.config.js +27 -0
  45. package/script/build +8 -0
  46. package/script/develop +17 -0
  47. package/script/stubgen.py +47 -0
  48. package/src/const.ts +315 -0
  49. package/src/esp_loader.ts +1204 -0
  50. package/src/index.ts +27 -0
  51. package/src/struct.ts +115 -0
  52. package/src/stubs/esp32.json +1 -0
  53. package/src/stubs/esp32c2.json +1 -0
  54. package/src/stubs/esp32c3.json +1 -0
  55. package/src/stubs/esp32h2.json +1 -0
  56. package/src/stubs/esp32s2.json +1 -0
  57. package/src/stubs/esp32s3.json +1 -0
  58. package/src/stubs/esp8266.json +1 -0
  59. package/src/stubs/index.ts +48 -0
  60. package/src/util.ts +49 -0
  61. package/stubs/esp32c2.json +1 -0
  62. package/stubs/esp32c3.json +1 -0
  63. package/stubs/esp32h2.json +1 -0
  64. package/stubs/esp32s3.json +1 -0
  65. package/tsconfig.json +19 -0
@@ -0,0 +1,159 @@
1
+ export interface Logger {
2
+ log(msg: string, ...args: any[]): void;
3
+ error(msg: string, ...args: any[]): void;
4
+ debug(msg: string, ...args: any[]): void;
5
+ }
6
+ export declare const baudRates: number[];
7
+ export declare const FLASH_SIZES: {
8
+ "512KB": number;
9
+ "256KB": number;
10
+ "1MB": number;
11
+ "2MB": number;
12
+ "4MB": number;
13
+ "2MB-c1": number;
14
+ "4MB-c1": number;
15
+ "8MB": number;
16
+ "16MB": number;
17
+ };
18
+ export declare const ESP32_FLASH_SIZES: {
19
+ "1MB": number;
20
+ "2MB": number;
21
+ "4MB": number;
22
+ "8MB": number;
23
+ "16MB": number;
24
+ "32MB": number;
25
+ "64MB": number;
26
+ "128MB": number;
27
+ };
28
+ interface FlashSize {
29
+ [key: number]: string;
30
+ }
31
+ export declare const DETECTED_FLASH_SIZES: FlashSize;
32
+ export declare const FLASH_WRITE_SIZE = 1024;
33
+ export declare const STUB_FLASH_WRITE_SIZE = 16384;
34
+ export declare const FLASH_SECTOR_SIZE = 4096;
35
+ export declare const ESP_ROM_BAUD = 115200;
36
+ export declare const USB_JTAG_SERIAL_PID = 4097;
37
+ export declare const ESP8266_SPI_REG_BASE = 1610613248;
38
+ export declare const ESP8266_BASEFUSEADDR = 1072693328;
39
+ export declare const ESP8266_MACFUSEADDR = 1072693328;
40
+ export declare const ESP8266_SPI_USR_OFFS = 28;
41
+ export declare const ESP8266_SPI_USR1_OFFS = 32;
42
+ export declare const ESP8266_SPI_USR2_OFFS = 36;
43
+ export declare const ESP8266_SPI_MOSI_DLEN_OFFS = -1;
44
+ export declare const ESP8266_SPI_MISO_DLEN_OFFS = -1;
45
+ export declare const ESP8266_SPI_W0_OFFS = 64;
46
+ export declare const ESP8266_UART_DATE_REG_ADDR = 1610612856;
47
+ export declare const ESP8266_BOOTLOADER_FLASH_OFFSET = 0;
48
+ export declare const ESP32_SPI_REG_BASE = 1072963584;
49
+ export declare const ESP32_BASEFUSEADDR = 1073061888;
50
+ export declare const ESP32_MACFUSEADDR = 1073061888;
51
+ export declare const ESP32_SPI_USR_OFFS = 28;
52
+ export declare const ESP32_SPI_USR1_OFFS = 32;
53
+ export declare const ESP32_SPI_USR2_OFFS = 36;
54
+ export declare const ESP32_SPI_MOSI_DLEN_OFFS = 40;
55
+ export declare const ESP32_SPI_MISO_DLEN_OFFS = 44;
56
+ export declare const ESP32_SPI_W0_OFFS = 128;
57
+ export declare const ESP32_UART_DATE_REG_ADDR = 1610612856;
58
+ export declare const ESP32_BOOTLOADER_FLASH_OFFSET = 4096;
59
+ export declare const ESP32S2_SPI_REG_BASE = 1061167104;
60
+ export declare const ESP32S2_BASEFUSEADDR = 1061265408;
61
+ export declare const ESP32S2_MACFUSEADDR = 1061265476;
62
+ export declare const ESP32S2_SPI_USR_OFFS = 24;
63
+ export declare const ESP32S2_SPI_USR1_OFFS = 28;
64
+ export declare const ESP32S2_SPI_USR2_OFFS = 32;
65
+ export declare const ESP32S2_SPI_MOSI_DLEN_OFFS = 36;
66
+ export declare const ESP32S2_SPI_MISO_DLEN_OFFS = 40;
67
+ export declare const ESP32S2_SPI_W0_OFFS = 88;
68
+ export declare const ESP32S2_UART_DATE_REG_ADDR = 1610612856;
69
+ export declare const ESP32S2_BOOTLOADER_FLASH_OFFSET = 4096;
70
+ export declare const ESP32S3_SPI_REG_BASE = 1610620928;
71
+ export declare const ESP32S3_BASEFUSEADDR = 1610641408;
72
+ export declare const ESP32S3_MACFUSEADDR: number;
73
+ export declare const ESP32S3_SPI_USR_OFFS = 24;
74
+ export declare const ESP32S3_SPI_USR1_OFFS = 28;
75
+ export declare const ESP32S3_SPI_USR2_OFFS = 32;
76
+ export declare const ESP32S3_SPI_MOSI_DLEN_OFFS = 36;
77
+ export declare const ESP32S3_SPI_MISO_DLEN_OFFS = 40;
78
+ export declare const ESP32S3_SPI_W0_OFFS = 88;
79
+ export declare const ESP32S3_UART_DATE_REG_ADDR = 1610612864;
80
+ export declare const ESP32S3_BOOTLOADER_FLASH_OFFSET = 0;
81
+ export declare const ESP32C3_SPI_REG_BASE = 1610620928;
82
+ export declare const ESP32C3_BASEFUSEADDR = 1610647552;
83
+ export declare const ESP32C3_MACFUSEADDR: number;
84
+ export declare const ESP32C3_SPI_USR_OFFS = 24;
85
+ export declare const ESP32C3_SPI_USR1_OFFS = 28;
86
+ export declare const ESP32C3_SPI_USR2_OFFS = 32;
87
+ export declare const ESP32C3_SPI_MOSI_DLEN_OFFS = 36;
88
+ export declare const ESP32C3_SPI_MISO_DLEN_OFFS = 40;
89
+ export declare const ESP32C3_SPI_W0_OFFS = 88;
90
+ export declare const ESP32C3_UART_DATE_REG_ADDR = 1610612860;
91
+ export declare const ESP32C3_BOOTLOADER_FLASH_OFFSET = 0;
92
+ export interface SpiFlashAddresses {
93
+ regBase: number;
94
+ baseFuse: number;
95
+ macFuse: number;
96
+ usrOffs: number;
97
+ usr1Offs: number;
98
+ usr2Offs: number;
99
+ mosiDlenOffs: number;
100
+ misoDlenOffs: number;
101
+ w0Offs: number;
102
+ uartDateReg: number;
103
+ flashOffs: number;
104
+ }
105
+ export declare const SYNC_PACKET: number[];
106
+ export declare const CHIP_DETECT_MAGIC_REG_ADDR = 1073745920;
107
+ export declare const CHIP_FAMILY_ESP8266 = 33382;
108
+ export declare const CHIP_FAMILY_ESP32 = 50;
109
+ export declare const CHIP_FAMILY_ESP32S2 = 12882;
110
+ export declare const CHIP_FAMILY_ESP32S3 = 12883;
111
+ export declare const CHIP_FAMILY_ESP32C3 = 12995;
112
+ export declare const CHIP_FAMILY_ESP32C6 = 12998;
113
+ export declare const CHIP_FAMILY_ESP32H2 = 12914;
114
+ export type ChipFamily = typeof CHIP_FAMILY_ESP8266 | typeof CHIP_FAMILY_ESP32 | typeof CHIP_FAMILY_ESP32S2 | typeof CHIP_FAMILY_ESP32S3 | typeof CHIP_FAMILY_ESP32C3 | typeof CHIP_FAMILY_ESP32C6 | typeof CHIP_FAMILY_ESP32H2;
115
+ interface ChipInfo {
116
+ [magicValue: number]: {
117
+ name: string;
118
+ family: ChipFamily;
119
+ };
120
+ }
121
+ export declare const CHIP_DETECT_MAGIC_VALUES: ChipInfo;
122
+ export declare const ESP_FLASH_BEGIN = 2;
123
+ export declare const ESP_FLASH_DATA = 3;
124
+ export declare const ESP_FLASH_END = 4;
125
+ export declare const ESP_MEM_BEGIN = 5;
126
+ export declare const ESP_MEM_END = 6;
127
+ export declare const ESP_MEM_DATA = 7;
128
+ export declare const ESP_SYNC = 8;
129
+ export declare const ESP_WRITE_REG = 9;
130
+ export declare const ESP_READ_REG = 10;
131
+ export declare const ESP_ERASE_FLASH = 208;
132
+ export declare const ESP_ERASE_REGION = 209;
133
+ export declare const ESP_SPI_SET_PARAMS = 11;
134
+ export declare const ESP_SPI_ATTACH = 13;
135
+ export declare const ESP_CHANGE_BAUDRATE = 15;
136
+ export declare const ESP_SPI_FLASH_MD5 = 19;
137
+ export declare const ESP_CHECKSUM_MAGIC = 239;
138
+ export declare const ESP_FLASH_DEFL_BEGIN = 16;
139
+ export declare const ESP_FLASH_DEFL_DATA = 17;
140
+ export declare const ESP_FLASH_DEFL_END = 18;
141
+ export declare const ROM_INVALID_RECV_MSG = 5;
142
+ export declare const USB_RAM_BLOCK = 2048;
143
+ export declare const ESP_RAM_BLOCK = 6144;
144
+ export declare const DEFAULT_TIMEOUT = 3000;
145
+ export declare const CHIP_ERASE_TIMEOUT = 600000;
146
+ export declare const MAX_TIMEOUT: number;
147
+ export declare const SYNC_TIMEOUT = 100;
148
+ export declare const ERASE_REGION_TIMEOUT_PER_MB = 30000;
149
+ export declare const MEM_END_ROM_TIMEOUT = 500;
150
+ /**
151
+ * @name timeoutPerMb
152
+ * Scales timeouts which are size-specific
153
+ */
154
+ export declare const timeoutPerMb: (secondsPerMb: number, sizeBytes: number) => number;
155
+ export declare const getSpiFlashAddresses: (chipFamily: ChipFamily) => SpiFlashAddresses;
156
+ export declare class SlipReadError extends Error {
157
+ constructor(message: string);
158
+ }
159
+ export {};
package/dist/const.js ADDED
@@ -0,0 +1,252 @@
1
+ import { toByteArray } from "./util";
2
+ export const baudRates = [
3
+ 115200, 128000, 153600, 230400, 460800, 921600, 1500000, 2000000,
4
+ ];
5
+ export const FLASH_SIZES = {
6
+ "512KB": 0x00,
7
+ "256KB": 0x10,
8
+ "1MB": 0x20,
9
+ "2MB": 0x30,
10
+ "4MB": 0x40,
11
+ "2MB-c1": 0x50,
12
+ "4MB-c1": 0x60,
13
+ "8MB": 0x80,
14
+ "16MB": 0x90,
15
+ };
16
+ export const ESP32_FLASH_SIZES = {
17
+ "1MB": 0x00,
18
+ "2MB": 0x10,
19
+ "4MB": 0x20,
20
+ "8MB": 0x30,
21
+ "16MB": 0x40,
22
+ "32MB": 0x50,
23
+ "64MB": 0x60,
24
+ "128MB": 0x70,
25
+ };
26
+ export const DETECTED_FLASH_SIZES = {
27
+ 0x12: "256KB",
28
+ 0x13: "512KB",
29
+ 0x14: "1MB",
30
+ 0x15: "2MB",
31
+ 0x16: "4MB",
32
+ 0x17: "8MB",
33
+ 0x18: "16MB",
34
+ 0x19: "32MB",
35
+ 0x1a: "64MB",
36
+ };
37
+ export const FLASH_WRITE_SIZE = 0x400;
38
+ export const STUB_FLASH_WRITE_SIZE = 0x4000;
39
+ export const FLASH_SECTOR_SIZE = 0x1000; // Flash sector size, minimum unit of erase.
40
+ export const ESP_ROM_BAUD = 115200;
41
+ export const USB_JTAG_SERIAL_PID = 0x1001;
42
+ export const ESP8266_SPI_REG_BASE = 0x60000200;
43
+ export const ESP8266_BASEFUSEADDR = 0x3ff00050;
44
+ export const ESP8266_MACFUSEADDR = 0x3ff00050;
45
+ export const ESP8266_SPI_USR_OFFS = 0x1c;
46
+ export const ESP8266_SPI_USR1_OFFS = 0x20;
47
+ export const ESP8266_SPI_USR2_OFFS = 0x24;
48
+ export const ESP8266_SPI_MOSI_DLEN_OFFS = -1;
49
+ export const ESP8266_SPI_MISO_DLEN_OFFS = -1;
50
+ export const ESP8266_SPI_W0_OFFS = 0x40;
51
+ export const ESP8266_UART_DATE_REG_ADDR = 0x60000078;
52
+ export const ESP8266_BOOTLOADER_FLASH_OFFSET = 0x0;
53
+ export const ESP32_SPI_REG_BASE = 0x3ff42000;
54
+ export const ESP32_BASEFUSEADDR = 0x3ff5a000;
55
+ export const ESP32_MACFUSEADDR = 0x3ff5a000;
56
+ export const ESP32_SPI_USR_OFFS = 0x1c;
57
+ export const ESP32_SPI_USR1_OFFS = 0x20;
58
+ export const ESP32_SPI_USR2_OFFS = 0x24;
59
+ export const ESP32_SPI_MOSI_DLEN_OFFS = 0x28;
60
+ export const ESP32_SPI_MISO_DLEN_OFFS = 0x2c;
61
+ export const ESP32_SPI_W0_OFFS = 0x80;
62
+ export const ESP32_UART_DATE_REG_ADDR = 0x60000078;
63
+ export const ESP32_BOOTLOADER_FLASH_OFFSET = 0x1000;
64
+ export const ESP32S2_SPI_REG_BASE = 0x3f402000;
65
+ export const ESP32S2_BASEFUSEADDR = 0x3f41a000;
66
+ export const ESP32S2_MACFUSEADDR = 0x3f41a044;
67
+ export const ESP32S2_SPI_USR_OFFS = 0x18;
68
+ export const ESP32S2_SPI_USR1_OFFS = 0x1c;
69
+ export const ESP32S2_SPI_USR2_OFFS = 0x20;
70
+ export const ESP32S2_SPI_MOSI_DLEN_OFFS = 0x24;
71
+ export const ESP32S2_SPI_MISO_DLEN_OFFS = 0x28;
72
+ export const ESP32S2_SPI_W0_OFFS = 0x58;
73
+ export const ESP32S2_UART_DATE_REG_ADDR = 0x60000078;
74
+ export const ESP32S2_BOOTLOADER_FLASH_OFFSET = 0x1000;
75
+ export const ESP32S3_SPI_REG_BASE = 0x60002000;
76
+ export const ESP32S3_BASEFUSEADDR = 0x60007000;
77
+ export const ESP32S3_MACFUSEADDR = 0x60007000 + 0x044;
78
+ export const ESP32S3_SPI_USR_OFFS = 0x18;
79
+ export const ESP32S3_SPI_USR1_OFFS = 0x1c;
80
+ export const ESP32S3_SPI_USR2_OFFS = 0x20;
81
+ export const ESP32S3_SPI_MOSI_DLEN_OFFS = 0x24;
82
+ export const ESP32S3_SPI_MISO_DLEN_OFFS = 0x28;
83
+ export const ESP32S3_SPI_W0_OFFS = 0x58;
84
+ export const ESP32S3_UART_DATE_REG_ADDR = 0x60000080;
85
+ export const ESP32S3_BOOTLOADER_FLASH_OFFSET = 0x0;
86
+ export const ESP32C3_SPI_REG_BASE = 0x60002000;
87
+ export const ESP32C3_BASEFUSEADDR = 0x60008800;
88
+ export const ESP32C3_MACFUSEADDR = 0x60008800 + 0x044;
89
+ export const ESP32C3_SPI_USR_OFFS = 0x18;
90
+ export const ESP32C3_SPI_USR1_OFFS = 0x1c;
91
+ export const ESP32C3_SPI_USR2_OFFS = 0x20;
92
+ export const ESP32C3_SPI_MOSI_DLEN_OFFS = 0x24;
93
+ export const ESP32C3_SPI_MISO_DLEN_OFFS = 0x28;
94
+ export const ESP32C3_SPI_W0_OFFS = 0x58;
95
+ export const ESP32C3_UART_DATE_REG_ADDR = 0x6000007c;
96
+ export const ESP32C3_BOOTLOADER_FLASH_OFFSET = 0x0;
97
+ export const SYNC_PACKET = toByteArray("\x07\x07\x12 UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU");
98
+ export const CHIP_DETECT_MAGIC_REG_ADDR = 0x40001000;
99
+ // These values for the families are made up; nothing that esptool uses.
100
+ export const CHIP_FAMILY_ESP8266 = 0x8266;
101
+ export const CHIP_FAMILY_ESP32 = 0x32;
102
+ export const CHIP_FAMILY_ESP32S2 = 0x3252;
103
+ export const CHIP_FAMILY_ESP32S3 = 0x3253;
104
+ export const CHIP_FAMILY_ESP32C3 = 0x32c3;
105
+ export const CHIP_FAMILY_ESP32C6 = 0x32c6;
106
+ export const CHIP_FAMILY_ESP32H2 = 0x3272;
107
+ export const CHIP_DETECT_MAGIC_VALUES = {
108
+ 0xfff0c101: { name: "ESP8266", family: CHIP_FAMILY_ESP8266 },
109
+ 0x00f01d83: { name: "ESP32", family: CHIP_FAMILY_ESP32 },
110
+ 0x000007c6: { name: "ESP32-S2", family: CHIP_FAMILY_ESP32S2 },
111
+ 0x9: { name: "ESP32-S3", family: CHIP_FAMILY_ESP32S3 },
112
+ 0xeb004136: { name: "ESP32-S3(beta2)", family: CHIP_FAMILY_ESP32S3 },
113
+ 0x6921506f: { name: "ESP32-C3", family: CHIP_FAMILY_ESP32C3 },
114
+ 0x1b31506f: { name: "ESP32-C3", family: CHIP_FAMILY_ESP32C3 },
115
+ 0xca26cc22: { name: "ESP32-H2", family: CHIP_FAMILY_ESP32H2 },
116
+ 0x0da1806f: { name: "ESP32-C6(beta)", family: CHIP_FAMILY_ESP32C6 },
117
+ };
118
+ // Commands supported by ESP8266 ROM bootloader
119
+ export const ESP_FLASH_BEGIN = 0x02;
120
+ export const ESP_FLASH_DATA = 0x03;
121
+ export const ESP_FLASH_END = 0x04;
122
+ export const ESP_MEM_BEGIN = 0x05;
123
+ export const ESP_MEM_END = 0x06;
124
+ export const ESP_MEM_DATA = 0x07;
125
+ export const ESP_SYNC = 0x08;
126
+ export const ESP_WRITE_REG = 0x09;
127
+ export const ESP_READ_REG = 0x0a;
128
+ export const ESP_ERASE_FLASH = 0xd0;
129
+ export const ESP_ERASE_REGION = 0xd1;
130
+ export const ESP_SPI_SET_PARAMS = 0x0b;
131
+ export const ESP_SPI_ATTACH = 0x0d;
132
+ export const ESP_CHANGE_BAUDRATE = 0x0f;
133
+ export const ESP_SPI_FLASH_MD5 = 0x13;
134
+ export const ESP_CHECKSUM_MAGIC = 0xef;
135
+ export const ESP_FLASH_DEFL_BEGIN = 0x10;
136
+ export const ESP_FLASH_DEFL_DATA = 0x11;
137
+ export const ESP_FLASH_DEFL_END = 0x12;
138
+ export const ROM_INVALID_RECV_MSG = 0x05;
139
+ export const USB_RAM_BLOCK = 0x800;
140
+ export const ESP_RAM_BLOCK = 0x1800;
141
+ // Timeouts
142
+ export const DEFAULT_TIMEOUT = 3000;
143
+ export const CHIP_ERASE_TIMEOUT = 600000; // timeout for full chip erase in ms
144
+ export const MAX_TIMEOUT = CHIP_ERASE_TIMEOUT * 2; // longest any command can run in ms
145
+ export const SYNC_TIMEOUT = 100; // timeout for syncing with bootloader in ms
146
+ export const ERASE_REGION_TIMEOUT_PER_MB = 30000; // timeout (per megabyte) for erasing a region in ms
147
+ export const MEM_END_ROM_TIMEOUT = 500;
148
+ /**
149
+ * @name timeoutPerMb
150
+ * Scales timeouts which are size-specific
151
+ */
152
+ export const timeoutPerMb = (secondsPerMb, sizeBytes) => {
153
+ let result = Math.floor(secondsPerMb * (sizeBytes / 0x1e6));
154
+ if (result < DEFAULT_TIMEOUT) {
155
+ return DEFAULT_TIMEOUT;
156
+ }
157
+ return result;
158
+ };
159
+ export const getSpiFlashAddresses = (chipFamily) => {
160
+ switch (chipFamily) {
161
+ case CHIP_FAMILY_ESP32:
162
+ return {
163
+ regBase: ESP32_SPI_REG_BASE,
164
+ baseFuse: ESP32_BASEFUSEADDR,
165
+ macFuse: ESP32_MACFUSEADDR,
166
+ usrOffs: ESP32_SPI_USR_OFFS,
167
+ usr1Offs: ESP32_SPI_USR1_OFFS,
168
+ usr2Offs: ESP32_SPI_USR2_OFFS,
169
+ mosiDlenOffs: ESP32_SPI_MOSI_DLEN_OFFS,
170
+ misoDlenOffs: ESP32_SPI_MISO_DLEN_OFFS,
171
+ w0Offs: ESP32_SPI_W0_OFFS,
172
+ uartDateReg: ESP32_UART_DATE_REG_ADDR,
173
+ flashOffs: ESP32_BOOTLOADER_FLASH_OFFSET,
174
+ };
175
+ case CHIP_FAMILY_ESP32S2:
176
+ return {
177
+ regBase: ESP32S2_SPI_REG_BASE,
178
+ baseFuse: ESP32S2_BASEFUSEADDR,
179
+ macFuse: ESP32S2_MACFUSEADDR,
180
+ usrOffs: ESP32S2_SPI_USR_OFFS,
181
+ usr1Offs: ESP32S2_SPI_USR1_OFFS,
182
+ usr2Offs: ESP32S2_SPI_USR2_OFFS,
183
+ mosiDlenOffs: ESP32S2_SPI_MOSI_DLEN_OFFS,
184
+ misoDlenOffs: ESP32S2_SPI_MISO_DLEN_OFFS,
185
+ w0Offs: ESP32S2_SPI_W0_OFFS,
186
+ uartDateReg: ESP32S2_UART_DATE_REG_ADDR,
187
+ flashOffs: ESP32S2_BOOTLOADER_FLASH_OFFSET,
188
+ };
189
+ case CHIP_FAMILY_ESP32S3:
190
+ return {
191
+ regBase: ESP32S3_SPI_REG_BASE,
192
+ usrOffs: ESP32S3_SPI_USR_OFFS,
193
+ baseFuse: ESP32S3_BASEFUSEADDR,
194
+ macFuse: ESP32S3_MACFUSEADDR,
195
+ usr1Offs: ESP32S3_SPI_USR1_OFFS,
196
+ usr2Offs: ESP32S3_SPI_USR2_OFFS,
197
+ mosiDlenOffs: ESP32S3_SPI_MOSI_DLEN_OFFS,
198
+ misoDlenOffs: ESP32S3_SPI_MISO_DLEN_OFFS,
199
+ w0Offs: ESP32S3_SPI_W0_OFFS,
200
+ uartDateReg: ESP32S3_UART_DATE_REG_ADDR,
201
+ flashOffs: ESP32S3_BOOTLOADER_FLASH_OFFSET,
202
+ };
203
+ case CHIP_FAMILY_ESP8266:
204
+ return {
205
+ regBase: ESP8266_SPI_REG_BASE,
206
+ usrOffs: ESP8266_SPI_USR_OFFS,
207
+ baseFuse: ESP8266_BASEFUSEADDR,
208
+ macFuse: ESP8266_MACFUSEADDR,
209
+ usr1Offs: ESP8266_SPI_USR1_OFFS,
210
+ usr2Offs: ESP8266_SPI_USR2_OFFS,
211
+ mosiDlenOffs: ESP8266_SPI_MOSI_DLEN_OFFS,
212
+ misoDlenOffs: ESP8266_SPI_MISO_DLEN_OFFS,
213
+ w0Offs: ESP8266_SPI_W0_OFFS,
214
+ uartDateReg: ESP8266_UART_DATE_REG_ADDR,
215
+ flashOffs: ESP8266_BOOTLOADER_FLASH_OFFSET,
216
+ };
217
+ case CHIP_FAMILY_ESP32C3:
218
+ return {
219
+ regBase: ESP32C3_SPI_REG_BASE,
220
+ baseFuse: ESP32C3_BASEFUSEADDR,
221
+ macFuse: ESP32C3_MACFUSEADDR,
222
+ usrOffs: ESP32C3_SPI_USR_OFFS,
223
+ usr1Offs: ESP32C3_SPI_USR1_OFFS,
224
+ usr2Offs: ESP32C3_SPI_USR2_OFFS,
225
+ mosiDlenOffs: ESP32C3_SPI_MOSI_DLEN_OFFS,
226
+ misoDlenOffs: ESP32C3_SPI_MISO_DLEN_OFFS,
227
+ w0Offs: ESP32C3_SPI_W0_OFFS,
228
+ uartDateReg: ESP32C3_UART_DATE_REG_ADDR,
229
+ flashOffs: ESP32C3_BOOTLOADER_FLASH_OFFSET,
230
+ };
231
+ default:
232
+ return {
233
+ regBase: -1,
234
+ baseFuse: -1,
235
+ macFuse: -1,
236
+ usrOffs: -1,
237
+ usr1Offs: -1,
238
+ usr2Offs: -1,
239
+ mosiDlenOffs: -1,
240
+ misoDlenOffs: -1,
241
+ w0Offs: -1,
242
+ uartDateReg: -1,
243
+ flashOffs: -1,
244
+ };
245
+ }
246
+ };
247
+ export class SlipReadError extends Error {
248
+ constructor(message) {
249
+ super(message);
250
+ this.name = "SlipReadError";
251
+ }
252
+ }
@@ -0,0 +1,166 @@
1
+ /// <reference types="w3c-web-serial" />
2
+ import { Logger, ChipFamily, SpiFlashAddresses } from "./const";
3
+ export declare class ESPLoader extends EventTarget {
4
+ port: SerialPort;
5
+ logger: Logger;
6
+ private _parent?;
7
+ chipFamily: ChipFamily;
8
+ chipName: string | null;
9
+ _efuses: any[];
10
+ _flashsize: number;
11
+ debug: boolean;
12
+ IS_STUB: boolean;
13
+ connected: boolean;
14
+ flashSize: string | null;
15
+ __inputBuffer?: number[];
16
+ private _reader?;
17
+ constructor(port: SerialPort, logger: Logger, _parent?: ESPLoader | undefined);
18
+ private get _inputBuffer();
19
+ initialize(): Promise<void>;
20
+ /**
21
+ * @name readLoop
22
+ * Reads data from the input stream and places it in the inputBuffer
23
+ */
24
+ readLoop(): Promise<void>;
25
+ sleep(ms?: number): Promise<unknown>;
26
+ state_DTR: boolean;
27
+ setRTS(state: boolean): Promise<void>;
28
+ setDTR(state: boolean): Promise<void>;
29
+ hardReset(bootloader?: boolean): Promise<void>;
30
+ /**
31
+ * @name macAddr
32
+ * The MAC address burned into the OTP memory of the ESP chip
33
+ */
34
+ macAddr(): any[];
35
+ readRegister(reg: number): Promise<number>;
36
+ /**
37
+ * @name checkCommand
38
+ * Send a command packet, check that the command succeeded and
39
+ * return a tuple with the value and data.
40
+ * See the ESP Serial Protocol for more details on what value/data are
41
+ */
42
+ checkCommand(opcode: number, buffer: number[], checksum?: number, timeout?: number): Promise<[number, number[]]>;
43
+ /**
44
+ * @name sendCommand
45
+ * Send a slip-encoded, checksummed command over the UART,
46
+ * does not check response
47
+ */
48
+ sendCommand(opcode: number, buffer: number[], checksum?: number): Promise<void>;
49
+ /**
50
+ * @name readPacket
51
+ * Generator to read SLIP packets from a serial port.
52
+ * Yields one full SLIP packet at a time, raises exception on timeout or invalid data.
53
+ * Designed to avoid too many calls to serial.read(1), which can bog
54
+ * down on slow systems.
55
+ */
56
+ readPacket(timeout: number): Promise<number[]>;
57
+ /**
58
+ * @name getResponse
59
+ * Read response data and decodes the slip packet, then parses
60
+ * out the value/data and returns as a tuple of (value, data) where
61
+ * each is a list of bytes
62
+ */
63
+ getResponse(opcode: number, timeout?: number): Promise<[number, number[]]>;
64
+ /**
65
+ * @name checksum
66
+ * Calculate checksum of a blob, as it is defined by the ROM
67
+ */
68
+ checksum(data: number[], state?: number): number;
69
+ setBaudrate(baud: number): Promise<void>;
70
+ reconfigurePort(baud: number): Promise<void>;
71
+ /**
72
+ * @name sync
73
+ * Put into ROM bootload mode & attempt to synchronize with the
74
+ * ESP ROM bootloader, we will retry a few times
75
+ */
76
+ sync(): Promise<boolean>;
77
+ /**
78
+ * @name _sync
79
+ * Perform a soft-sync using AT sync packets, does not perform
80
+ * any hardware resetting
81
+ */
82
+ _sync(): Promise<boolean>;
83
+ /**
84
+ * @name getFlashWriteSize
85
+ * Get the Flash write size based on the chip
86
+ */
87
+ getFlashWriteSize(): 1024 | 16384;
88
+ /**
89
+ * @name flashData
90
+ * Program a full, uncompressed binary file into SPI Flash at
91
+ * a given offset. If an ESP32 and md5 string is passed in, will also
92
+ * verify memory. ESP8266 does not have checksum memory verification in
93
+ * ROM
94
+ */
95
+ flashData(binaryData: ArrayBuffer, updateProgress: (bytesWritten: number, totalBytes: number) => void, offset?: number, compress?: boolean): Promise<void>;
96
+ /**
97
+ * @name flashBlock
98
+ * Send one block of data to program into SPI Flash memory
99
+ */
100
+ flashBlock(data: number[], seq: number, timeout?: number): Promise<void>;
101
+ flashDeflBlock(data: number[], seq: number, timeout?: number): Promise<void>;
102
+ /**
103
+ * @name flashBegin
104
+ * Prepare for flashing by attaching SPI chip and erasing the
105
+ * number of blocks requred.
106
+ */
107
+ flashBegin(size?: number, offset?: number, encrypted?: boolean): Promise<number>;
108
+ /**
109
+ * @name flashDeflBegin
110
+ *
111
+ */
112
+ flashDeflBegin(size?: number, compressedSize?: number, offset?: number, encrypted?: boolean): Promise<number>;
113
+ flashFinish(): Promise<void>;
114
+ flashDeflFinish(): Promise<void>;
115
+ getBootloaderOffset(): number;
116
+ flashId(): Promise<number>;
117
+ getChipFamily(): ChipFamily;
118
+ writeRegister(address: number, value: number, mask?: number, delayUs?: number, delayAfterUs?: number): Promise<void>;
119
+ setDataLengths(spiAddresses: SpiFlashAddresses, mosiBits: number, misoBits: number): Promise<void>;
120
+ waitDone(spiCmdReg: number, spiCmdUsr: number): Promise<void>;
121
+ runSpiFlashCommand(spiflashCommand: number, data: number[], readBits?: number): Promise<number>;
122
+ detectFlashSize(): Promise<void>;
123
+ /**
124
+ * @name getEraseSize
125
+ * Calculate an erase size given a specific size in bytes.
126
+ * Provides a workaround for the bootloader erase bug on ESP8266.
127
+ */
128
+ getEraseSize(offset: number, size: number): number;
129
+ /**
130
+ * @name memBegin (592)
131
+ * Start downloading an application image to RAM
132
+ */
133
+ memBegin(size: number, blocks: number, blocksize: number, offset: number): Promise<[number, number[]]>;
134
+ /**
135
+ * @name memBlock (609)
136
+ * Send a block of an image to RAM
137
+ */
138
+ memBlock(data: number[], seq: number): Promise<[number, number[]]>;
139
+ /**
140
+ * @name memFinish (615)
141
+ * Leave download mode and run the application
142
+ *
143
+ * Sending ESP_MEM_END usually sends a correct response back, however sometimes
144
+ * (with ROM loader) the executed code may reset the UART or change the baud rate
145
+ * before the transmit FIFO is empty. So in these cases we set a short timeout and
146
+ * ignore errors.
147
+ */
148
+ memFinish(entrypoint?: number): Promise<[number, number[]]>;
149
+ runStub(): Promise<EspStubLoader>;
150
+ writeToStream(data: number[]): Promise<void>;
151
+ disconnect(): Promise<void>;
152
+ }
153
+ declare class EspStubLoader extends ESPLoader {
154
+ IS_STUB: boolean;
155
+ /**
156
+ * @name memBegin (592)
157
+ * Start downloading an application image to RAM
158
+ */
159
+ memBegin(size: number, blocks: number, blocksize: number, offset: number): Promise<any>;
160
+ /**
161
+ * @name getEraseSize
162
+ * depending on flash chip model the erase may take this long (maybe longer!)
163
+ */
164
+ eraseFlash(): Promise<void>;
165
+ }
166
+ export {};