Skip to content

Commit

Permalink
riscv/k230: revise canmv230:pnsh
Browse files Browse the repository at this point in the history
This revises canm230:pnsh in a few ways:

- adjusting linker scripts structure,
- asserting PMP setting results,
- adjusting configs for both k230d and k230 devices.

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 committed Jul 13, 2024
1 parent 59dfd47 commit 4e17a56
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
/nuttx
/nuttx-*
/nuttx.*
/nuttx_user*
/staging
/tags
/TAGS
Expand Down
7 changes: 5 additions & 2 deletions arch/risc-v/src/k230/k230_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ void k230_userspace(void)

static void configure_mpu(void)
{
riscv_append_pmp_region(UFLASH_F, UFLASH_START, UFLASH_SIZE);
riscv_append_pmp_region(USRAM_F, USRAM_START, USRAM_SIZE);
int ret;
ret = riscv_append_pmp_region(UFLASH_F, UFLASH_START, UFLASH_SIZE);
DEBUGASSERT(ret == 0);
ret = riscv_append_pmp_region(USRAM_F, USRAM_START, USRAM_SIZE);
DEBUGASSERT(ret == 0);
}

#endif /* CONFIG_BUILD_PROTECTED */
2 changes: 2 additions & 0 deletions boards/risc-v/k230/canmv230/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kernel/nuttx_user*
scripts/*.tmp
6 changes: 3 additions & 3 deletions boards/risc-v/k230/canmv230/configs/pnsh/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NUTTX_USERSPACE=0x8040000
CONFIG_NUTTX_USERSPACE=0x6040000
CONFIG_PASS1_BUILDIR="boards/risc-v/k230/canmv230/kernel"
CONFIG_PATH_INITIAL="/system/bin"
CONFIG_RAM_SIZE=16777216
CONFIG_RAM_START=0x8000000
CONFIG_RAM_SIZE=3145728
CONFIG_RAM_START=0x6000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200
Expand Down
23 changes: 13 additions & 10 deletions boards/risc-v/k230/canmv230/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ ENTRYPT = $(patsubst "%",%,$(CONFIG_INIT_ENTRYPOINT))
# is appropriate for the host OS

USER_LIBPATHS = $(addprefix -L,$(call CONVERT_PATH,$(addprefix $(TOPDIR)$(DELIM),$(dir $(USERLIBS)))))
USER_LDSCRIPT = -T $(call CONVERT_PATH,$(BOARD_DIR)$(DELIM)scripts$(DELIM)ld-userland.script)
USER_LDSCRIPT = $(call CONVERT_PATH,$(BOARD_DIR)$(DELIM)scripts$(DELIM)ld-userland.script)
USER_HEXFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.hex)
USER_SRECFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.srec)
USER_BINFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.bin)

USER_LDFLAGS = -melf64lriscv --undefined=$(ENTRYPT) --entry=$(ENTRYPT) $(USER_LDSCRIPT)
USER_LDFLAGS = -melf64lriscv --undefined=$(ENTRYPT) --entry=$(ENTRYPT) -T $(addsuffix .tmp,$(USER_LDSCRIPT))
USER_LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(USERLIBS))))
USER_LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}"

Expand All @@ -47,19 +47,22 @@ OBJS = $(COBJS)

# Targets:

all: $(TOPDIR)$(DELIM)nuttx_user.elf $(TOPDIR)$(DELIM)User.map
.PHONY: nuttx_user.elf depend clean distclean
all: $(TOPDIR)$(DELIM)nuttx_user $(TOPDIR)$(DELIM)User.map
.PHONY: nuttx_user depend clean distclean

$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)

$(addsuffix .tmp,$(USER_LDSCRIPT)): $(USER_LDSCRIPT)
$(call PREPROCESS,$(patsubst %.tmp,%,$@),$@)

# Create the nuttx_user.elf file containing all of the user-mode code

nuttx_user.elf: $(OBJS)
nuttx_user: $(OBJS) $(addsuffix .tmp,$(USER_LDSCRIPT))
$(Q) $(LD) -o $@ $(USER_LDFLAGS) $(USER_LIBPATHS) $(OBJS) --start-group $(USER_LDLIBS) --end-group $(USER_LIBGCC)

$(TOPDIR)$(DELIM)nuttx_user.elf: nuttx_user.elf
@echo "LD: nuttx_user.elf"
$(TOPDIR)$(DELIM)nuttx_user: nuttx_user
@echo "LD: nuttx_user"
$(Q) cp -a $^ $(TOPDIR)$(DELIM)$^
ifeq ($(CONFIG_INTELHEX_BINARY),y)
@echo "CP: nuttx_user.hex"
Expand All @@ -74,17 +77,17 @@ ifeq ($(CONFIG_RAW_BINARY),y)
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $^ $(USER_BINFILE)
endif

$(TOPDIR)$(DELIM)User.map: nuttx_user.elf
$(TOPDIR)$(DELIM)User.map: nuttx_user
@echo "MK: User.map"
$(Q) $(NM) -n $^ >$(TOPDIR)$(DELIM)User.map
$(Q) $(CROSSDEV)size $^

.depend:

depend: .depend

clean:
$(call DELFILE, nuttx_user.elf)
$(call DELFILE, nuttx_user)
$(call DELFILE, $(addsuffix .tmp,$(USER_LDSCRIPT)))
$(call DELFILE, "$(TOPDIR)$(DELIM)nuttx_user.*")
$(call DELFILE, "$(TOPDIR)$(DELIM)User.map")
$(call CLEAN)
Expand Down
66 changes: 66 additions & 0 deletions boards/risc-v/k230/canmv230/scripts/ld-protected.mem
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/****************************************************************************
* boards/risc-v/k230/canmv230/scripts/ld-protected.mem
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

#include <nuttx/config.h>

/* Memory layout for ld-protected.script and ld-userland.script
*
* |-CONFIG_RAM_START
* | |-CONFIG_NUTTX_USERSPACE
* +--------+----------+--------+--------+
* | kflash | uflash | ksram | usram |
* +--------+----------+--------+--------+
* |>-- FLASH_SIZE ---<|>-- SRAM_SIZE --<|
*
*/

#define KFLASH_ADDR (CONFIG_RAM_START)
#define UFLASH_ADDR (CONFIG_NUTTX_USERSPACE)
#define KFLASH_SIZE (UFLASH_ADDR - KFLASH_ADDR)
#define UFLASH_SIZE (KFLASH_SIZE)

#define FLASH_SIZE (0x100000) /* needs be POT */
#define SRAM_SIZE (0x200000) /* needs be POT */

#if KFLASH_SIZE < 0
#error "Invalid KFLASH_SIZE!"
#endif

#if KFLASH_SIZE + UFLASH_SIZE > FLASH_SIZE
#error "Adjust FLASH_SIZE please!"
#endif

#if CONFIG_RAM_SIZE < FLASH_SIZE + SRAM_SIZE
#error "CONFIG_RAM_SIZE too small?"
#endif

#define KSRAM_SIZE (SRAM_SIZE / 2)
#define USRAM_SIZE (SRAM_SIZE - KSRAM_SIZE)

#define KSRAM_ADDR (KFLASH_ADDR + FLASH_SIZE)
#define USRAM_ADDR (KSRAM_ADDR + KSRAM_SIZE)

MEMORY
{
kflash (rx) : ORIGIN = KFLASH_ADDR, LENGTH = KFLASH_SIZE
uflash (rx) : ORIGIN = UFLASH_ADDR, LENGTH = UFLASH_SIZE
ksram (rwx) : ORIGIN = KSRAM_ADDR, LENGTH = KSRAM_SIZE
usram (rwx) : ORIGIN = USRAM_ADDR, LENGTH = USRAM_SIZE
}
12 changes: 1 addition & 11 deletions boards/risc-v/k230/canmv230/scripts/ld-protected.script
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@
*
****************************************************************************/

/* NOTE: This shares memory layout with ld-userland.script */

MEMORY
{
kflash (rx) : ORIGIN = 0x8000000, LENGTH = 256K /* w/ cache */
uflash (rx) : ORIGIN = 0x8040000, LENGTH = 256K /* w/ cache */

ksram (rwx) : ORIGIN = 0x8200000, LENGTH = 1024K /* w/ cache */
usram (rwx) : ORIGIN = 0x8300000, LENGTH = 1024K /* w/ cache */
}

#include "ld-protected.mem"

OUTPUT_ARCH("riscv")

Expand Down
11 changes: 1 addition & 10 deletions boards/risc-v/k230/canmv230/scripts/ld-userland.script
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@
*
****************************************************************************/

/* NOTE: This shares memory layout with ld-protected.script */

MEMORY
{
kflash (rx) : ORIGIN = 0x8000000, LENGTH = 256K /* w/ cache */
uflash (rx) : ORIGIN = 0x8040000, LENGTH = 256K /* w/ cache */

ksram (rwx) : ORIGIN = 0x8200000, LENGTH = 1024K /* w/ cache */
usram (rwx) : ORIGIN = 0x8300000, LENGTH = 1024K /* w/ cache */
}
#include "ld-protected.mem"

OUTPUT_ARCH("riscv")

Expand Down

0 comments on commit 4e17a56

Please sign in to comment.