mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2025-10-29 11:33:20 +00:00
easyflash linux (#1827)
This commit is contained in:
parent
c208c19f3e
commit
6708337768
3
.gitignore
vendored
3
.gitignore
vendored
@ -38,4 +38,5 @@ configMemory.bin
|
||||
enc_temp_folder/**
|
||||
|
||||
*.su
|
||||
/.idea/**
|
||||
/.idea/**
|
||||
*.so
|
||||
|
||||
@ -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
|
||||
|
||||
44
libraries/easyflash/ports/Makefile.linux
Normal file
44
libraries/easyflash/ports/Makefile.linux
Normal file
@ -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,$@)
|
||||
@ -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"
|
||||
@ -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 */
|
||||
@ -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
|
||||
@ -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);
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user