Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ configMemory.bin
enc_temp_folder/**

*.su
/.idea/**
/.idea/**
*.so
6 changes: 6 additions & 0 deletions libraries/easyflash/inc/ef_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@
extern uint32_t ENV_AREA_SIZE;
#define DllExport __declspec(dllexport)

#elif LINUX

#define EF_START_ADDR 0
extern uint32_t ENV_AREA_SIZE;
#define DllExport __attribute__((dllexport))

#endif
/* print debug information of flash */
#ifdef PKG_EASYFLASH_DEBUG
Expand Down
44 changes: 44 additions & 0 deletions libraries/easyflash/ports/Makefile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CROSS_COMPILE ?=
CC := $(CROSS_COMPILE)gcc
OP := $(CROSS_COMPILE)objcopy
AR := $(CROSS_COMPILE)ar
AS := $(CROSS_COMPILE)as
LD := $(CROSS_COMPILE)gcc
NM := $(CROSS_COMPILE)nm
OD := $(CROSS_COMPILE)objdump
RD := $(CROSS_COMPILE)readelf
ST := $(CROSS_COMPILE)strip

all: library

SRC_C += ef_port.c
SRC_C += ../src/easyflash.c
SRC_C += ../src/ef_env.c
SRC_C += ../src/ef_env_legacy.c
SRC_C += ../src/ef_env_legacy_wl.c
SRC_C += ../src/ef_iap.c
SRC_C += ../src/ef_log.c
SRC_C += ../src/ef_utils.c

SRC_O = $(patsubst %.c,%.o,$(SRC_C))

INCLUDES = -I../inc
LDFLAGS = -g -ggdb -fPIC -shared -Lstatic -Lpthread
CFLAGS = -Os -g -ggdb -fPIC
DEFINES = -DLINUX=1

.PHONY: library
library: $(SRC_O)
@ echo "Linking"
@$(CC) $(LDFLAGS) -o libef.so $(SRC_O)


.PHONY: clean
clean:
rm -f $(SRC_O)
rm -f libef.so

$(SRC_O): %.o : %.c
@ echo "build_c $@"
@$(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
@$(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) -c $< -MM -MT $@ -MF $(patsubst %.o,%.d,$@)
50 changes: 46 additions & 4 deletions libraries/easyflash/ports/ef_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#if !WINDOWS && !PLATFORM_TXW81X && !PLATFORM_RDA5981
#if !WINDOWS && !PLATFORM_TXW81X && !PLATFORM_RDA5981 && !LINUX
#include "FreeRTOS.h"
#include "semphr.h"
#include "queue.h"
Expand Down Expand Up @@ -119,6 +119,48 @@ void xSemaphoreGive(HANDLE handle)
ReleaseMutex(ef_mutex);
}

#elif LINUX

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <pthread.h>

#define QueueHandle_t pthread_mutex_t
extern QueueHandle_t ef_mutex;

uint8_t* env_area = NULL;
uint32_t ENV_AREA_SIZE = 0;

DllExport uint8_t* get_env_area(void)
{
return env_area;
}

DllExport void set_env_size(uint32_t size)
{
ENV_AREA_SIZE = size;
if(env_area) free(env_area);
env_area = malloc(size * sizeof(uint8_t));
}

QueueHandle_t xSemaphoreCreateMutex()
{
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_init(&mutex, NULL);
return mutex;
}

void xSemaphoreTake(QueueHandle_t handle, int time)
{
pthread_mutex_lock(&handle);
}

void xSemaphoreGive(QueueHandle_t handle)
{
pthread_mutex_unlock(&handle);
}

#endif

/* default ENV set for user */
Expand Down Expand Up @@ -179,7 +221,7 @@ EfErrCode ef_port_read(uint32_t addr, uint32_t* buf, size_t size)
if(res == 0) res = EF_READ_ERR;
else res = EF_NO_ERR;
return res;
#elif WINDOWS
#elif WINDOWS || LINUX
memcpy(buf, env_area + addr, size);
return EF_NO_ERR;
#elif PLATFORM_TXW81X || PLATFORM_RDA5981
Expand Down Expand Up @@ -219,7 +261,7 @@ EfErrCode ef_port_erase(uint32_t addr, size_t size)
if(res != 0) res = EF_ERASE_ERR;
else res = EF_NO_ERR;
return res;
#elif WINDOWS
#elif WINDOWS || LINUX
memset(env_area + addr, 0xFF, size);
#elif PLATFORM_TXW81X || PLATFORM_RDA5981
HAL_FlashEraseSector(addr);
Expand Down Expand Up @@ -257,7 +299,7 @@ EfErrCode ef_port_write(uint32_t addr, const uint32_t* buf, size_t size)
if(res == 0) res = EF_WRITE_ERR;
else res = EF_NO_ERR;
return res;
#elif WINDOWS
#elif WINDOWS || LINUX
memcpy(env_area + addr, buf, size);
return EF_NO_ERR;
#elif PLATFORM_TXW81X || PLATFORM_RDA5981
Expand Down
2 changes: 1 addition & 1 deletion libraries/easyflash/src/ef_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
#define SECTOR_SIZE EF_ERASE_MIN_SIZE
#define SECTOR_NUM (ENV_AREA_SIZE / (EF_ERASE_MIN_SIZE))

#if !WINDOWS
#if !WINDOWS && !LINUX
#if (SECTOR_NUM < 2)
#error "The sector number must lager then or equal to 2"
#endif
Expand Down