Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3572f3

Browse files
committed
fix: ensure stubs for targets are stored in flash to save RAM space
Compiled stub was incorrectly placed in RAM, because the arrays with data were placed in data.__compound_literal section, which is linked to RAM. This commit adds const qualifier to the arrays, so they are placed in rodata.__compound_literal section, which is linked to flash.
1 parent 3c424d2 commit e3572f3

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

cmake/gen_stub_sources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ def read_stub_json(json_file):
6969
{{
7070
.addr = {text_start},
7171
.size = {text_size},
72-
.data = (uint8_t[]){{{text_str}}},
72+
.data = (const uint8_t[]){{{text_str}}},
7373
}},
7474
{{
7575
.addr = {data_start},
7676
.size = {data_size},
77-
.data = (uint8_t[]){{{data_str}}},
77+
.data = (const uint8_t[]){{{data_str}}},
7878
}},
7979
}},
8080
}},

examples/common/example_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ esp_loader_error_t load_ram_binary(const uint8_t *bin)
539539
}
540540

541541
size_t remain_size = segments[seg].size;
542-
uint8_t *data_pos = segments[seg].data;
542+
const uint8_t *data_pos = segments[seg].data;
543543
while (remain_size > 0) {
544544
size_t data_size = MIN(ESP_RAM_BLOCK, remain_size);
545545
err = esp_loader_mem_write(data_pos, data_size);

include/esp_loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ typedef struct {
8787
typedef struct {
8888
uint32_t addr;
8989
uint32_t size;
90-
uint8_t *data;
90+
const uint8_t *data;
9191
} esp_loader_bin_segment_t;
9292

9393
typedef struct {

src/esp_sdio_stubs.c

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

src/esp_stubs.c

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

src/protocol_uart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ esp_loader_error_t loader_run_stub(target_chip_t target)
5757
}
5858

5959
size_t remain_size = stub->segments[seg].size;
60-
uint8_t *data_pos = stub->segments[seg].data;
60+
const uint8_t *data_pos = stub->segments[seg].data;
6161
while (remain_size > 0) {
6262
size_t data_size = MIN(ESP_RAM_BLOCK, remain_size);
6363
err = esp_loader_mem_write(data_pos, data_size);

0 commit comments

Comments
 (0)