Simplify BOARD_MEMORY_RANGE initialization logic
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
parent
89f3ef4480
commit
fa59adde40
|
@ -4896,4 +4896,4 @@ config BOARD_MEMORY_RANGE
|
|||
start: start address of memory range
|
||||
end: end address of memory range
|
||||
flags: Readable 0x1, writable 0x2, executable 0x4
|
||||
example:0x1000,0x2000,0x1,0x2000,0x3000,0x3,0x3000,0x4000,0x7
|
||||
example:0x1000,0x2000,0x1},{0x2000,0x3000,0x3},{0x3000,0x4000,0x7} ... {0x0,0x0,0x0}
|
||||
|
|
|
@ -68,6 +68,7 @@ set(DEQUOTELIST
|
|||
"CONFIG_PASS1_OBJECT" # Pass1 build object
|
||||
"CONFIG_TTY_LAUNCH_ENTRYPOINT" # Name of entry point from tty launch
|
||||
"CONFIG_TTY_LAUNCH_ARGS" # Argument list of entry point from tty launch
|
||||
"CONFIG_BOARD_MEMORY_RANGE" # Memory range for board
|
||||
# NxWidgets/NxWM
|
||||
"CONFIG_NXWM_BACKGROUND_IMAGE" # Name of bitmap image class
|
||||
"CONFIG_NXWM_CALIBRATION_ICON" # Name of bitmap image class
|
||||
|
|
|
@ -34,6 +34,13 @@
|
|||
|
||||
#define DEVMEM_REGION 8
|
||||
|
||||
#ifdef CONFIG_BOARD_MEMORY_RANGE
|
||||
static const struct memory_region_s g_memory_region[] =
|
||||
{
|
||||
CONFIG_BOARD_MEMORY_RANGE
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
@ -208,58 +215,50 @@ static int devmem_mmap(FAR struct file *filep,
|
|||
int devmem_register(void)
|
||||
{
|
||||
FAR struct memory_region_s *region;
|
||||
bool merge = (&_edata[0] == &_sbss[0]);
|
||||
ssize_t len = 0;
|
||||
int ret;
|
||||
|
||||
#ifndef CONFIG_BOARD_MEMORY_RANGE
|
||||
bool merge = (&_edata[0] == &_sbss[0]);
|
||||
ssize_t len = 0;
|
||||
region = kmm_calloc(DEVMEM_REGION, sizeof(*region));
|
||||
if (region == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (CONFIG_BOARD_MEMORY_RANGE[0] != '\0')
|
||||
if (len + (4 - merge) > DEVMEM_REGION)
|
||||
{
|
||||
len = parse_memory_region(CONFIG_BOARD_MEMORY_RANGE, region,
|
||||
DEVMEM_REGION - 1);
|
||||
if (len < 0)
|
||||
{
|
||||
kmm_free(region);
|
||||
return len;
|
||||
}
|
||||
len = DEVMEM_REGION - (4 - merge);
|
||||
}
|
||||
|
||||
region[len].flags = PROT_EXEC | PROT_READ;
|
||||
region[len].start = (uintptr_t)_stext;
|
||||
region[len++].end = (uintptr_t)_etext;
|
||||
region[len].flags = PROT_WRITE | PROT_READ;
|
||||
region[len].start = (uintptr_t)_sdata;
|
||||
region[len++].end = (uintptr_t)_edata;
|
||||
|
||||
if (merge)
|
||||
{
|
||||
region[len - 1].end = (uintptr_t)_ebss;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (len + (4 - merge) > DEVMEM_REGION)
|
||||
{
|
||||
len = DEVMEM_REGION - (4 - merge);
|
||||
}
|
||||
|
||||
region[len].flags = PROT_EXEC | PROT_READ;
|
||||
region[len].start = (uintptr_t)_stext;
|
||||
region[len++].end = (uintptr_t)_etext;
|
||||
region[len].flags = PROT_WRITE | PROT_READ;
|
||||
region[len].start = (uintptr_t)_sdata;
|
||||
region[len++].end = (uintptr_t)_edata;
|
||||
|
||||
if (merge)
|
||||
{
|
||||
region[len - 1].end = (uintptr_t)_ebss;
|
||||
}
|
||||
else
|
||||
{
|
||||
region[len].flags = PROT_WRITE | PROT_READ;
|
||||
region[len].start = (uintptr_t)_sbss;
|
||||
region[len++].end = (uintptr_t)_ebss;
|
||||
}
|
||||
region[len].start = (uintptr_t)_sbss;
|
||||
region[len++].end = (uintptr_t)_ebss;
|
||||
}
|
||||
|
||||
#else
|
||||
region = (FAR struct memory_region_s *)g_memory_region;
|
||||
#endif
|
||||
/* register the new MEM driver */
|
||||
|
||||
ret = register_driver("/dev/mem", &g_devmem_fops, 0666, region);
|
||||
if (ret < 0)
|
||||
{
|
||||
#ifndef CONFIG_BOARD_MEMORY_RANGE
|
||||
kmm_free(region);
|
||||
#endif
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,13 @@
|
|||
|
||||
#define BUFSIZE CONFIG_LIB_GDBSTUB_PKTSIZE
|
||||
|
||||
#ifdef CONFIG_BOARD_MEMORY_RANGE
|
||||
FAR const struct memory_region_s g_memory_region[] =
|
||||
{
|
||||
CONFIG_BOARD_MEMORY_RANGE
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
@ -72,7 +79,6 @@ struct gdb_state_s
|
|||
size_t pkt_len; /* Packet send and receive length */
|
||||
uint8_t running_regs[XCPTCONTEXT_SIZE]; /* Registers of running thread */
|
||||
size_t size; /* Size of registers */
|
||||
FAR struct memory_region_s *range; /* Memory regions */
|
||||
uintptr_t registers[0]; /* Registers of other threads */
|
||||
};
|
||||
|
||||
|
@ -818,14 +824,8 @@ static size_t gdb_encode_rle(FAR void *data, size_t data_len)
|
|||
static bool gdb_is_valid_region(FAR struct gdb_state_s *state,
|
||||
uintptr_t addr, size_t len, uint32_t flags)
|
||||
{
|
||||
FAR struct memory_region_s *region = state->range;
|
||||
|
||||
if (state->range == NULL)
|
||||
{
|
||||
/* No memory region, so allow all access */
|
||||
|
||||
return true;
|
||||
}
|
||||
#ifdef CONFIG_BOARD_MEMORY_RANGE
|
||||
FAR const struct memory_region_s *region = g_memory_region;
|
||||
|
||||
while (region->start < region->end)
|
||||
{
|
||||
|
@ -840,6 +840,9 @@ static bool gdb_is_valid_region(FAR struct gdb_state_s *state,
|
|||
}
|
||||
|
||||
return false;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -1939,16 +1942,6 @@ FAR struct gdb_state_s *gdb_state_init(gdb_send_func_t send,
|
|||
state->priv = priv;
|
||||
state->monitor = monitor;
|
||||
|
||||
if (CONFIG_BOARD_MEMORY_RANGE[0] != '\0')
|
||||
{
|
||||
state->range = alloc_memory_region(CONFIG_BOARD_MEMORY_RANGE);
|
||||
if (state->range == NULL)
|
||||
{
|
||||
lib_free(state);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -1967,11 +1960,6 @@ void gdb_state_uninit(FAR struct gdb_state_s *state)
|
|||
{
|
||||
if (state != NULL)
|
||||
{
|
||||
if (state->range != NULL)
|
||||
{
|
||||
free_memory_region(state->range);
|
||||
}
|
||||
|
||||
lib_free(state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,12 @@ static struct lib_blkoutstream_s g_blockstream;
|
|||
static unsigned char *g_blockinfo;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BOARD_MEMORY_RANGE
|
||||
static struct memory_region_s g_memory_region[] =
|
||||
{
|
||||
CONFIG_BOARD_MEMORY_RANGE
|
||||
};
|
||||
#endif
|
||||
static const struct memory_region_s *g_regions;
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -254,13 +260,23 @@ int coredump_add_memory_region(FAR const void *ptr, size_t size)
|
|||
/* Need a new region */
|
||||
}
|
||||
|
||||
region = lib_realloc((FAR void *)g_regions,
|
||||
sizeof(struct memory_region_s) * (count + 1));
|
||||
region = lib_malloc(sizeof(struct memory_region_s) * (count + 1));
|
||||
if (region == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(region, g_regions, sizeof(struct memory_region_s) * count);
|
||||
|
||||
if (g_regions != NULL
|
||||
#ifdef CONFIG_BOARD_MEMORY_RANGE
|
||||
&& g_regions != g_memory_region
|
||||
#endif
|
||||
)
|
||||
{
|
||||
lib_free((FAR void *)g_regions);
|
||||
}
|
||||
|
||||
region[count - 1].start = (uintptr_t)ptr;
|
||||
region[count - 1].end = (uintptr_t)ptr + size;
|
||||
region[count - 1].flags = 0;
|
||||
|
@ -284,16 +300,9 @@ int coredump_initialize(void)
|
|||
blkcnt_t nsectors;
|
||||
int ret = 0;
|
||||
|
||||
if (CONFIG_BOARD_MEMORY_RANGE[0] != '\0')
|
||||
{
|
||||
coredump_set_memory_region(
|
||||
alloc_memory_region(CONFIG_BOARD_MEMORY_RANGE));
|
||||
if (g_regions == NULL)
|
||||
{
|
||||
_alert("Coredump memory region alloc fail\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_BOARD_MEMORY_RANGE
|
||||
g_regions = g_memory_region;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BOARD_COREDUMP_BLKDEV
|
||||
ret = lib_blkoutstream_open(&g_blockstream,
|
||||
|
@ -302,8 +311,6 @@ int coredump_initialize(void)
|
|||
{
|
||||
_alert("%s Coredump device not found\n",
|
||||
CONFIG_BOARD_COREDUMP_BLKDEV_PATH);
|
||||
free_memory_region(g_regions);
|
||||
g_regions = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -315,8 +322,6 @@ int coredump_initialize(void)
|
|||
if (g_blockinfo == NULL)
|
||||
{
|
||||
_alert("Coredump device memory alloc fail\n");
|
||||
free_memory_region(g_regions);
|
||||
g_regions = NULL;
|
||||
lib_blkoutstream_close(&g_blockstream);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ static const char *dequote_list[] =
|
|||
"CONFIG_PASS1_OBJECT", /* Pass1 build object */
|
||||
"CONFIG_TTY_LAUNCH_ENTRYPOINT", /* Name of entry point from tty launch */
|
||||
"CONFIG_TTY_LAUNCH_ARGS", /* Argument list of entry point from tty launch */
|
||||
"CONFIG_BOARD_MEMORY_RANGE", /* Memory range for board */
|
||||
|
||||
/* NxWidgets/NxWM */
|
||||
|
||||
|
|
Loading…
Reference in New Issue