Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
618f71d
Fix core panics: Don't use m_malloc and gc_malloc unintended
amotl Nov 14, 2019
97620ae
assert the layout of the config block
peter-pycom Mar 20, 2020
873040c
document the pycom_config_block_t layout
peter-pycom Mar 20, 2020
8495c7d
Fixed memory allocations in LittleFS files.
salal-m May 6, 2020
669dfe2
Updated mem free in socketfifo.c required for last commit's changes i…
salal-m May 7, 2020
6cb700a
Fixed memory allocations in Pycom Modules files
salal-m May 7, 2020
25183fb
Re-added the indentations to signify the code blocks under mutex lock.
salal-m May 8, 2020
a106cb4
Added a check before accessing the IP Address in the MDNS query respo…
salal-m May 8, 2020
8e08fab
Replaced heap_caps_malloc/free with malloc/free.
salal-m May 8, 2020
f58301e
Merge pull request #123 from pycom/pr418
May 18, 2020
5a6aa0a
PyJTAG: LTE uart 1
peter-pycom May 19, 2020
71354b9
Merge pull request #124 from pycom/pyjtag_lte
peter-pycom May 19, 2020
ba5b4f1
sigfox: fix commit hash (#125)
peter-pycom May 25, 2020
79ee9bf
Merge pull request #115 from pycom/pybytes_config_block
peter-pycom May 25, 2020
6cc3aff
Fix an issue in wrap_socket() results exception when no certificate v…
geza-pycom May 31, 2020
36b44d3
Merge pull request #126 from geza-pycom/SSL_no_verification
Jun 2, 2020
b74db42
Fix integer overflow in filesystem stat implementation. Resolve #409.…
geza-pycom Jun 10, 2020
669d1e3
add wlan_ap_tcpip_sta_list function that lists the connected devices …
geza-pycom Jun 10, 2020
73f0021
HTTP/S Server/Client Module (#118)
mate-pycom Jun 10, 2020
c9b534a
update idf hash (#130)
peter-pycom Jun 10, 2020
29d8021
Revert "update idf hash (#130)"
peter-pycom Jun 10, 2020
7f84b9c
Revert "HTTP/S Server/Client Module (#118)"
peter-pycom Jun 10, 2020
2186b33
idf 6ec081c (#132)
peter-pycom Jun 10, 2020
9f6e28e
Update pybytes to 1.5.0 (#133)
Xykon Jun 10, 2020
63d7be9
v1.20.2.rc9 (#135)
peter-pycom Jun 10, 2020
38d9cc7
Merge remote-tracking branch 'pycom-public/Dev'
peter-pycom Jun 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion esp32/fatfs/src/drivers/sflash_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DRESULT sflash_disk_init (void) {
sflash_start_address = SFLASH_START_ADDR_4MB;
sflash_fs_sector_count = SFLASH_FS_SECTOR_COUNT_4MB;
}
sflash_block_cache = (uint8_t *)heap_caps_malloc(SFLASH_BLOCK_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
sflash_block_cache = (uint8_t *)malloc(SFLASH_BLOCK_SIZE);
sflash_prev_block_addr = UINT32_MAX;
sflash_cache_is_dirty = false;
sflash_init_done = true;
Expand Down
20 changes: 10 additions & 10 deletions esp32/ftp/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ STATIC FRESULT f_readdir_helper(ftp_dir_t *dp, ftp_fileinfo_t *fno ) {
if(length_of_relative_path > 1) {
path_length++;
}
char* file_relative_path = m_malloc(path_length);
char* file_relative_path = malloc(path_length);

// Copy the current working directory (relative path)
memcpy(file_relative_path, path_relative, length_of_relative_path);
Expand All @@ -359,7 +359,7 @@ STATIC FRESULT f_readdir_helper(ftp_dir_t *dp, ftp_fileinfo_t *fno ) {
fno->u.fpinfo_lfs.timestamp.ftime = 0;
}

m_free(file_relative_path);
free(file_relative_path);
}

xSemaphoreGive(littlefs->mutex);
Expand Down Expand Up @@ -614,10 +614,10 @@ static void ftp_return_to_previous_path (char *pwd, char *dir);
******************************************************************************/
void ftp_init (void) {
// allocate memory for the data buffer, and the file system structs (from the RTOS heap)
ftp_data.dBuffer = heap_caps_malloc(FTP_BUFFER_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
ftp_path = heap_caps_malloc(FTP_MAX_PARAM_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
ftp_scratch_buffer = heap_caps_malloc(FTP_MAX_PARAM_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
ftp_cmd_buffer = heap_caps_malloc(FTP_MAX_PARAM_SIZE + FTP_CMD_SIZE_MAX, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
ftp_data.dBuffer = malloc(FTP_BUFFER_SIZE);
ftp_path = malloc(FTP_MAX_PARAM_SIZE);
ftp_scratch_buffer = malloc(FTP_MAX_PARAM_SIZE);
ftp_cmd_buffer = malloc(FTP_MAX_PARAM_SIZE + FTP_CMD_SIZE_MAX);
SOCKETFIFO_Init (&ftp_socketfifo, (void *)ftp_fifoelements, FTP_SOCKETFIFO_ELEMENTS_MAX);
ftp_data.c_sd = -1;
ftp_data.d_sd = -1;
Expand Down Expand Up @@ -933,7 +933,7 @@ static void ftp_send_reply (uint32_t status, char *message) {
strcat ((char *)ftp_cmd_buffer, "\r\n");
fifoelement.sd = &ftp_data.c_sd;
fifoelement.datasize = strlen((char *)ftp_cmd_buffer);
fifoelement.data = pvPortMalloc(fifoelement.datasize);
fifoelement.data = malloc(fifoelement.datasize);
if (status == 221) {
fifoelement.closesockets = E_FTP_CLOSE_CMD_AND_DATA;
} else if (status == 426 || status == 451 || status == 550) {
Expand All @@ -945,7 +945,7 @@ static void ftp_send_reply (uint32_t status, char *message) {
if (fifoelement.data) {
memcpy (fifoelement.data, ftp_cmd_buffer, fifoelement.datasize);
if (!SOCKETFIFO_Push (&fifoelement)) {
vPortFree(fifoelement.data);
free(fifoelement.data);
}
}
}
Expand Down Expand Up @@ -979,13 +979,13 @@ static void ftp_send_from_fifo (void) {
ftp_close_filesystem_on_error();
}
if (fifoelement.freedata) {
vPortFree(fifoelement.data);
free(fifoelement.data);
}
}
} else { // socket closed, remove it from the queue
SOCKETFIFO_Pop (&fifoelement);
if (fifoelement.freedata) {
vPortFree(fifoelement.data);
free(fifoelement.data);
}
}
} else if (ftp_data.state == E_FTP_STE_END_TRANSFER && (ftp_data.d_sd > 0)) {
Expand Down
5 changes: 2 additions & 3 deletions esp32/littlefs/lfs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "py/mpconfig.h"
#include "py/misc.h"
#include "py/gc.h"

// System includes
#include <stdint.h>
Expand Down Expand Up @@ -204,7 +203,7 @@ uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size);
// Note, memory must be 64-bit aligned
static inline void *lfs_malloc(size_t size) {
#ifndef LFS_NO_MALLOC
return gc_alloc(size, false);
return malloc(size);
#else
return NULL;
#endif
Expand All @@ -213,7 +212,7 @@ static inline void *lfs_malloc(size_t size) {
// Deallocate memory, only used if buffers are not provided to littlefs
static inline void lfs_free(void *p) {
#ifndef LFS_NO_MALLOC
m_free(p);
free(p);
#endif
}

Expand Down
79 changes: 31 additions & 48 deletions esp32/littlefs/vfs_littlefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <string.h>
#include "py/runtime.h"
#include "py/mperrno.h"
#include "py/gc.h"
#include "lib/oofatfs/ff.h"
#include "extmod/vfs.h"
#include "vfs_littlefs.h"
Expand All @@ -18,22 +17,22 @@ int lfs_statvfs_count(void *p, lfs_block_t b)
return 0;
}

// After this function m_free() must be called on the returned address after usage!!
// After this function free() must be called on the returned address after usage!!
const char* concat_with_cwd(vfs_lfs_struct_t* littlefs, const char* path)
{
char* path_out = NULL;

if (path[0] == '/') /* Absolute path */
{
path_out = (char*)gc_alloc(strlen(path) + 1, false); // Count the \0 too
path_out = (char*)malloc(strlen(path) + 1); // Count the \0 too
if(path_out != NULL)
{
strcpy(path_out, path);
}
}
else
{
path_out = (char*)gc_alloc(strlen(littlefs->cwd) + 1 + strlen(path) + 1, false);
path_out = (char*)malloc(strlen(littlefs->cwd) + 1 + strlen(path) + 1);
if(path_out != NULL)
{
strcpy(path_out, littlefs->cwd);
Expand Down Expand Up @@ -130,9 +129,8 @@ static int change_cwd(vfs_lfs_struct_t* littlefs, const char* path_in)
}
else if(is_valid_directory(littlefs, new_path))
{
m_free(littlefs->cwd);
free(littlefs->cwd);
littlefs->cwd = (char*)new_path;
MP_STATE_PORT(lfs_cwd) = littlefs->cwd;

res = LFS_ERR_OK;
}
Expand Down Expand Up @@ -354,21 +352,21 @@ void littlefs_prepare_attributes(struct lfs_file_config *cfg)
{
// Currently we only have 1 attribute
cfg->attr_count = 1;
cfg->attrs = m_malloc(cfg->attr_count * sizeof(struct lfs_attr));
cfg->attrs = malloc(cfg->attr_count * sizeof(struct lfs_attr));

// Set attribute for storing the timestamp
cfg->attrs[0].size = sizeof(lfs_timestamp_attribute_t);
cfg->attrs[0].type = LFS_ATTRIBUTE_TIMESTAMP;
cfg->attrs[0].buffer = m_malloc(sizeof(lfs_timestamp_attribute_t));
cfg->attrs[0].buffer = malloc(sizeof(lfs_timestamp_attribute_t));

}

void littlefs_free_up_attributes(struct lfs_file_config *cfg)
{
cfg->attr_count = 0;
// Currently we only have 1 attribute for timestamp
m_free(cfg->attrs[0].buffer);
m_free(cfg->attrs);
free(cfg->attrs[0].buffer);
free(cfg->attrs);
}


Expand Down Expand Up @@ -479,18 +477,15 @@ STATIC mp_obj_t littlefs_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args)
iter->is_str = is_str_type;

xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY);
const char* path = concat_with_cwd(&self->fs.littlefs, path_in);
if(path == NULL)
{
const char *path = concat_with_cwd(&self->fs.littlefs, path_in);
if (path == NULL) {
res = LFS_ERR_NOMEM;
}
else
{
} else {
res = lfs_dir_open(&self->fs.littlefs.lfs, &iter->dir, path);
}
xSemaphoreGive(self->fs.littlefs.mutex);

m_free((void*)path);
free((void*)path);

if (res != LFS_ERR_OK) {
mp_raise_OSError(littleFsErrorToErrno(res));
Expand All @@ -507,21 +502,18 @@ STATIC mp_obj_t littlefs_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_param) {
const char *path_in = mp_obj_str_get_str(path_param);

xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY);
const char* path = concat_with_cwd(&self->fs.littlefs, path_in);
if(path == NULL)
{
const char *path = concat_with_cwd(&self->fs.littlefs, path_in);
if (path == NULL) {
res = LFS_ERR_NOMEM;
}
else
{
} else {
res = lfs_mkdir(&self->fs.littlefs.lfs, path);
if(res == LFS_ERR_OK) {
if (res == LFS_ERR_OK) {
littlefs_update_timestamp(&self->fs.littlefs.lfs, path);
}
}
xSemaphoreGive(self->fs.littlefs.mutex);

m_free((void*)path);
free((void*)path);

if (res != LFS_ERR_OK) {
mp_raise_OSError(littleFsErrorToErrno(res));
Expand All @@ -539,18 +531,15 @@ STATIC mp_obj_t littlefs_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_param) {
const char *path_in = mp_obj_str_get_str(path_param);

xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY);
const char* path = concat_with_cwd(&self->fs.littlefs, path_in);
if(path == NULL)
{
const char *path = concat_with_cwd(&self->fs.littlefs, path_in);
if (path == NULL) {
res = LFS_ERR_NOMEM;
}
else
{
} else {
res = lfs_remove(&self->fs.littlefs.lfs, path);
}
xSemaphoreGive(self->fs.littlefs.mutex);

m_free((void*)path);
free((void*)path);

if (res != LFS_ERR_OK) {
mp_raise_OSError(littleFsErrorToErrno(res));
Expand All @@ -569,21 +558,18 @@ STATIC mp_obj_t littlefs_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_param_in, mp_
const char *path_out = mp_obj_str_get_str(path_param_out);

xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY);
const char* old_path = concat_with_cwd(&self->fs.littlefs, path_in);
const char* new_path = concat_with_cwd(&self->fs.littlefs, path_out);
const char *old_path = concat_with_cwd(&self->fs.littlefs, path_in);
const char *new_path = concat_with_cwd(&self->fs.littlefs, path_out);

if(old_path == NULL || new_path == NULL)
{
if (old_path == NULL || new_path == NULL) {
res = LFS_ERR_NOMEM;
}
else
{
} else {
res = lfs_rename(&self->fs.littlefs.lfs, old_path, new_path);
}
xSemaphoreGive(self->fs.littlefs.mutex);

m_free((void*)old_path);
m_free((void*)new_path);
free((void*)old_path);
free((void*)new_path);

if (res != LFS_ERR_OK) {
mp_raise_OSError(littleFsErrorToErrno(res));
Expand Down Expand Up @@ -634,13 +620,10 @@ STATIC mp_obj_t littlefs_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_param) {


xSemaphoreTake(self->fs.littlefs.mutex, portMAX_DELAY);
const char* path = concat_with_cwd(&self->fs.littlefs, path_in);
if(path == NULL)
{
const char *path = concat_with_cwd(&self->fs.littlefs, path_in);
if (path == NULL) {
res = LFS_ERR_NOMEM;
}
else if (path[0] == 0 || (path[0] == '/' && path[1] == 0))
{
} else if (path[0] == 0 || (path[0] == '/' && path[1] == 0)) {
// stat root directory
fno.size = 0;
fno.type = LFS_TYPE_DIR;
Expand All @@ -650,7 +633,7 @@ STATIC mp_obj_t littlefs_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_param) {

xSemaphoreGive(self->fs.littlefs.mutex);

m_free((void*)path);
free((void*)path);

if (res < LFS_ERR_OK) {
mp_raise_OSError(littleFsErrorToErrno(res));
Expand Down
2 changes: 1 addition & 1 deletion esp32/littlefs/vfs_littlefs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
int res = littlefs_open_common_helper(&vfs->fs.littlefs.lfs, fname, &o->fp, mode, &o->cfg, &o->timestamp_update);
xSemaphoreGive(vfs->fs.littlefs.mutex);

m_free((void*)fname);
free((void*)fname);
if (res < LFS_ERR_OK) {
m_del_obj(pyb_file_obj_t, o);
mp_raise_OSError(littleFsErrorToErrno(res));
Expand Down
2 changes: 1 addition & 1 deletion esp32/lte/lteppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void lteppp_init(void) {

lteppp_connstatus = LTE_PPP_IDLE;
#ifdef LTE_DEBUG_BUFF
lteppp_log.log = heap_caps_malloc(LTE_LOG_BUFF_SIZE, MALLOC_CAP_SPIRAM);
lteppp_log.log = malloc(LTE_LOG_BUFF_SIZE);
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions esp32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void app_main(void) {
micropy_lpwan_dio_pin_num = 23;
micropy_lpwan_dio_pin = &pin_GPIO23;

mpTaskStack = heap_caps_malloc(MICROPY_TASK_STACK_SIZE_PSRAM, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
mpTaskStack = malloc(MICROPY_TASK_STACK_SIZE_PSRAM);

// create the MicroPython task
mpTaskHandle =
Expand All @@ -172,7 +172,7 @@ void app_main(void) {
micropy_lpwan_dio_pin_num = 23;
micropy_lpwan_dio_pin = &pin_GPIO23;

mpTaskStack = heap_caps_malloc(MICROPY_TASK_STACK_SIZE, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
mpTaskStack = malloc(MICROPY_TASK_STACK_SIZE);

// create the MicroPython task
mpTaskHandle =
Expand Down
4 changes: 2 additions & 2 deletions esp32/mods/machrmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ STATIC mp_obj_t mach_rmt_pulses_send(mp_uint_t n_args, const mp_obj_t *pos_args,

/* An rmt_item32_t can contain 2 bits, calculate the number of the necessary objects needed to store the input data */
mp_uint_t items_to_send_count = (data_length / 2) + (data_length % 2);
rmt_item32_t* items_to_send = (rmt_item32_t*)m_malloc(items_to_send_count * sizeof(rmt_item32_t));
rmt_item32_t* items_to_send = (rmt_item32_t*)malloc(items_to_send_count * sizeof(rmt_item32_t));
for(mp_uint_t i = 0, j = 0; i < items_to_send_count; i++, j++) {

items_to_send[i].level0 = mp_obj_get_int(data_ptr[j]);
Expand Down Expand Up @@ -396,7 +396,7 @@ STATIC mp_obj_t mach_rmt_pulses_send(mp_uint_t n_args, const mp_obj_t *pos_args,
esp_err_t retval = rmt_write_items(self->config.channel, items_to_send, items_to_send_count, wait_tx_done);
MP_THREAD_GIL_ENTER();

m_free(items_to_send);
free(items_to_send);

if (retval != ESP_OK) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Could not send data!"));
Expand Down
3 changes: 1 addition & 2 deletions esp32/mods/machtimer_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "py/mpconfig.h"
#include "py/nlr.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "py/mperrno.h"
#include "util/mpirq.h"

Expand Down Expand Up @@ -56,7 +55,7 @@ void mach_timer_alarm_preinit(void) {

void mach_timer_alarm_init_heap(void) {
alarm_heap.count = 0;
MP_STATE_PORT(mp_alarm_heap) = gc_alloc(ALARM_HEAP_MAX_ELEMENTS * sizeof(mp_obj_alarm_t *), false);
MP_STATE_PORT(mp_alarm_heap) = m_malloc(ALARM_HEAP_MAX_ELEMENTS * sizeof(mp_obj_alarm_t *));
alarm_heap.data = MP_STATE_PORT(mp_alarm_heap);
if (alarm_heap.data == NULL) {
mp_printf(&mp_plat_print, "FATAL ERROR: not enough memory for the alarms heap\n");
Expand Down
Loading