Skip to content

Commit d768568

Browse files
slaffigrr
authored andcommitted
Memory optimization for static const data. (esp8266#30)
1 parent 5282123 commit d768568

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ AR := $(TOOLCHAIN_PREFIX)ar
44
LD := $(TOOLCHAIN_PREFIX)gcc
55
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
66

7+
MFORCE32 := $(shell $(CC) --help=target | grep mforce-l32)
78

89
XTENSA_LIBS ?= $(shell $(CC) -print-sysroot)
910

@@ -43,6 +44,14 @@ LDFLAGS += -L$(XTENSA_LIBS)/lib \
4344
CFLAGS+=-std=c99 -DESP8266
4445

4546
CFLAGS += -Wall -Os -g -O2 -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals -D__ets__ -DICACHE_FLASH
47+
48+
ifneq ($(MFORCE32),)
49+
# Your compiler supports the -mforce-l32 flag which means that
50+
# constants can be stored in flash (program) memory instead of SRAM.
51+
# See: https://www.arduino.cc/en/Reference/PROGMEM
52+
CFLAGS += -DPROGMEM="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))" -mforce-l32
53+
endif
54+
4655
BIN_DIR := bin
4756
AXTLS_AR := $(BIN_DIR)/libaxtls.a
4857

crypto/aes.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
/*
7676
* AES S-box
7777
*/
78-
static const uint8_t aes_sbox[256] =
78+
static const uint8_t aes_sbox[256] PROGMEM =
7979
{
8080
0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5,
8181
0x30,0x01,0x67,0x2B,0xFE,0xD7,0xAB,0x76,
@@ -114,7 +114,7 @@ static const uint8_t aes_sbox[256] =
114114
/*
115115
* AES is-box
116116
*/
117-
static const uint8_t aes_isbox[256] =
117+
static const uint8_t aes_isbox[256] PROGMEM =
118118
{
119119
0x52,0x09,0x6a,0xd5,0x30,0x36,0xa5,0x38,
120120
0xbf,0x40,0xa3,0x9e,0x81,0xf3,0xd7,0xfb,

crypto/crypto_misc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ EXP_FUNC void STDCALL print_blob(const char *format, const unsigned char *data,
309309

310310
#if defined(CONFIG_SSL_HAS_PEM) || defined(CONFIG_HTTP_HAS_AUTHORIZATION)
311311
/* base64 to binary lookup table */
312-
static const uint8_t map[128] =
312+
static const uint8_t map[128] PROGMEM =
313313
{
314314
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
315315
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,

crypto/sha512.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define SIGMA4(x) (ROR64(x, 19) ^ ROR64(x, 61) ^ SHR64(x, 6))
4343
#define MIN(x, y) ((x) < (y) ? x : y)
4444

45-
static const uint8_t padding[128] =
45+
static const uint8_t padding[128] PROGMEM =
4646
{
4747
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4848
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

ssl/os_port.h

+4
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ void exit_now(const char *format, ...);
230230
#define SSL_CTX_UNLOCK(A)
231231
#endif
232232

233+
#ifndef PROGMEM
234+
#define PROGMEM
235+
#endif
236+
233237
#ifdef __cplusplus
234238
}
235239
#endif

0 commit comments

Comments
 (0)