Skip to content

Commit ff91a91

Browse files
committed
feat(wpa_supplicant): Redefine usd heap to DRAM instead of IRAM
1 parent b25a003 commit ff91a91

File tree

4 files changed

+28
-48
lines changed

4 files changed

+28
-48
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
COMPONENT_ADD_INCLUDEDIRS := include port/include
2-
COMPONENT_SRCDIRS := src/crypto
2+
COMPONENT_SRCDIRS := src/crypto port
33

44
CFLAGS += -DEMBEDDED_SUPP -D__ets__ -DESPRESSIF_USE

components/wpa_supplicant/port/include/os.h

+6-14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include "esp_err.h"
2222
#include "rom/ets_sys.h"
2323

24+
#include "FreeRTOS.h"
25+
#include "esp_libc.h"
26+
2427
typedef long os_time_t;
2528

2629
/**
@@ -188,19 +191,6 @@ char * os_readfile(const char *name, size_t *len);
188191
* OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
189192
* these functions need to be implemented in os_*.c file for the target system.
190193
*/
191-
192-
#ifndef os_malloc
193-
#define os_malloc(s) malloc((s))
194-
#endif
195-
#ifndef os_realloc
196-
#define os_realloc(p, s) realloc((p), (s))
197-
#endif
198-
#ifndef os_zalloc
199-
#define os_zalloc(s) calloc(1, (s))
200-
#endif
201-
#ifndef os_free
202-
#define os_free(p) free((p))
203-
#endif
204194

205195
#ifndef os_bzero
206196
#define os_bzero(s, n) bzero(s, n)
@@ -286,6 +276,8 @@ char * ets_strdup(const char *s);
286276
*/
287277
size_t os_strlcpy(char *dest, const char *src, size_t siz);
288278

289-
279+
void *_xmalloc(size_t n);
280+
void _xfree(void *ptr);
281+
void *_xrealloc(void *ptr, size_t n);
290282

291283
#endif /* OS_H */

components/wpa_supplicant/port/os_xtensa.c

+18-30
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,32 @@
2121
* this file to work correctly. Note that these implementations are only
2222
* examples and are not optimized for speed.
2323
*/
24+
#include <string.h>
25+
#include "FreeRTOS.h"
2426

25-
#include "crypto/common.h"
26-
#include "os.h"
27-
#include <stdlib.h>
28-
#include <time.h>
29-
#include <sys/time.h>
30-
#include "esp_system.h"
31-
32-
int os_get_time(struct os_time *t)
27+
void *_xmalloc(size_t n)
3328
{
34-
return gettimeofday((struct timeval*) t, NULL);
35-
}
29+
void *return_addr = (void *)__builtin_return_address(0);
3630

37-
unsigned long os_random(void)
38-
{
39-
return esp_random();
31+
return pvPortMalloc_trace(n, return_addr, (unsigned)-1, false);
4032
}
4133

42-
unsigned long r_rand(void) __attribute__((alias("os_random")));
43-
44-
45-
int os_get_random(unsigned char *buf, size_t len)
34+
void _xfree(void *ptr)
4635
{
47-
int i, j;
48-
unsigned long tmp;
36+
void *return_addr = (void *)__builtin_return_address(0);
4937

50-
for (i = 0; i < ((len + 3) & ~3) / 4; i++) {
51-
tmp = r_rand();
38+
vPortFree_trace(ptr, return_addr, (unsigned)-1);
39+
}
5240

53-
for (j = 0; j < 4; j++) {
54-
if ((i * 4 + j) < len) {
55-
buf[i * 4 + j] = (uint8_t)(tmp >> (j * 8));
56-
} else {
57-
break;
58-
}
59-
}
41+
void *_xrealloc(void *ptr, size_t n)
42+
{
43+
void *return_addr = (void *)__builtin_return_address(0);
44+
void *p = pvPortMalloc_trace(n, return_addr, (unsigned)-1, false);
45+
if (p && ptr) {
46+
// n ?
47+
memcpy(p, ptr, n);
48+
vPortFree_trace(ptr, return_addr, (unsigned)-1);
6049
}
6150

62-
return 0;
51+
return p;
6352
}
64-

components/wpa_supplicant/src/crypto/libtommath.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ typedef u64 mp_word;
7777
#define MP_28BIT
7878

7979

80-
#define XMALLOC os_malloc
81-
#define XFREE os_free
82-
#define XREALLOC os_realloc
80+
#define XMALLOC _xmalloc
81+
#define XFREE _xfree
82+
#define XREALLOC _xrealloc
8383

8484

8585
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))

0 commit comments

Comments
 (0)