aboutsummaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-10-27 00:04:47 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-10-27 00:04:47 +0000
commit1f1319f25bc2461eb8970ba0345768df440166ef (patch)
tree615048fb87a55a2421efe353d061d0ded0d8eebf /nuttx
parent7bc6a69f461c9bed82608220960682f3090f742c (diff)
downloadpx4-firmware-1f1319f25bc2461eb8970ba0345768df440166ef.tar.gz
px4-firmware-1f1319f25bc2461eb8970ba0345768df440166ef.tar.bz2
px4-firmware-1f1319f25bc2461eb8970ba0345768df440166ef.zip
The ELF loader is basically functional (needs more testing)
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5265 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_elf.c47
-rw-r--r--nuttx/arch/arm/src/stm32/Kconfig6
-rw-r--r--nuttx/binfmt/libelf/libelf_bind.c5
-rw-r--r--nuttx/binfmt/libelf/libelf_init.c1
-rw-r--r--nuttx/configs/stm32f4discovery/README.txt4
-rw-r--r--nuttx/configs/stm32f4discovery/elf/Make.defs1
-rw-r--r--nuttx/configs/stm32f4discovery/elf/defconfig7
8 files changed, 44 insertions, 29 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 7c4a5a8cd..a80e5009a 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -3522,3 +3522,5 @@
* configs/stm32f4discovery/elf and configs/stm32f4discovery/scripts/gnu-elf.ld
Add a configuration for testing the ARM ELF loader.
* binfmt/libelf: Can't use fstat(). NuttX does not yet support it. Damn!
+ * binfmt/libelf: The basic ELF module execution appears fully functional.
+
diff --git a/nuttx/arch/arm/src/armv7-m/up_elf.c b/nuttx/arch/arm/src/armv7-m/up_elf.c
index 5f77470fa..202c902b4 100644
--- a/nuttx/arch/arm/src/armv7-m/up_elf.c
+++ b/nuttx/arch/arm/src/armv7-m/up_elf.c
@@ -218,8 +218,8 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
* The branch target is encoded in these bits:
*
* S = upper_insn[10]
- * imm10 = upper_insn[9:0]
- * imm11 = lower_insn[10:0]
+ * imm10 = upper_insn[0:9]
+ * imm11 = lower_insn[0:10]
* J1 = lower_insn[13]
* J2 = lower_insn[11]
*/
@@ -227,7 +227,7 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
upper_insn = (uint32_t)(*(uint16_t*)addr);
lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
- bvdbg("Performing JUMP24 [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
+ bvdbg("Performing THM_JUMP24 [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
sym, (long)sym->st_value);
@@ -235,9 +235,9 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
*
* offset[24] = S
* offset[23] = ~(J1 ^ S)
- * offset[22 = ~(J2 ^ S)]
- * offset[21:12] = imm10
- * offset[11:1] = imm11
+ * offset[22] = ~(J2 ^ S)]
+ * offset[12:21] = imm10
+ * offset[1:11] = imm11
* offset[0] = 0
*/
@@ -245,11 +245,12 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
J1 = (lower_insn >> 13) & 1;
J2 = (lower_insn >> 11) & 1;
- offset = (S << 24) |
- ((~(J1 ^ S) & 1) << 23) |
- ((~(J2 ^ S) & 1) << 22) |
- ((upper_insn & 0x03ff) << 12) |
- ((lower_insn & 0x07ff) << 1);
+ offset = (S << 24) | /* S - > offset[24] */
+ ((~(J1 ^ S) & 1) << 23) | /* J1 -> offset[23] */
+ ((~(J2 ^ S) & 1) << 22) | /* J2 -> offset[22] */
+ ((upper_insn & 0x03ff) << 12) | /* imm10 -> offset[12:21] */
+ ((lower_insn & 0x07ff) << 1); /* imm11 -> offset[1:11] */
+ /* 0 -> offset[0] */
/* Sign extend */
@@ -374,31 +375,31 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
* 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
* +---+---------------------------------------------------------+
* |OP | | 32-Bit Instructions
- * +---+--+-------+--------------+-------------------------------+
- * |0 |1 | imm3 | Rd | imm8 | MOVT Instruction
- * +---+--+-------+--------------+-------------------------------+
+ * +---+----------+--------------+-------------------------------+
+ * |0 | imm3 | Rd | imm8 | MOVT Instruction
+ * +---+----------+--------------+-------------------------------+
*
* The 16-bit immediate value is encoded in these bits:
*
* i = imm16[11] = upper_insn[10]
* imm4 = imm16[12:15] = upper_insn[3:0]
- * imm3 = imm16[9:11] = lower_insn[14:12]
- * imm8 = imm16[0:8] = lower_insn[7:0]
+ * imm3 = imm16[8:10] = lower_insn[14:12]
+ * imm8 = imm16[0:7] = lower_insn[7:0]
*/
upper_insn = (uint32_t)(*(uint16_t*)addr);
lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
- bvdbg("Performing MOVx [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
+ bvdbg("Performing THM_MOVx [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
sym, (long)sym->st_value);
/* Extract the 16-bit offset from the 32-bit instruction */
- offset = ((upper_insn & 0x000f) << 12) |
- ((upper_insn & 0x0400) << 1) |
- ((lower_insn & 0x7000) >> 4) |
- (lower_insn & 0x00ff);
+ offset = ((upper_insn & 0x000f) << 12) | /* imm4 -> imm16[8:10] */
+ ((upper_insn & 0x0400) << 1) | /* i -> imm16[11] */
+ ((lower_insn & 0x7000) >> 4) | /* imm3 -> imm16[8:10] */
+ (lower_insn & 0x00ff); /* imm8 -> imm16[0:7] */
/* Sign extend */
@@ -406,8 +407,8 @@ int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
/* And perform the relocation */
- bvdbg(" S=%d J1=%d J2=%d offset=%08lx branch target=%08lx\n",
- S, J1, J2, (long)offset, offset + sym->st_value);
+ bvdbg(" offset=%08lx branch target=%08lx\n",
+ (long)offset, offset + sym->st_value);
offset += sym->st_value;
diff --git a/nuttx/arch/arm/src/stm32/Kconfig b/nuttx/arch/arm/src/stm32/Kconfig
index 5fd0ae7a2..acfac81aa 100644
--- a/nuttx/arch/arm/src/stm32/Kconfig
+++ b/nuttx/arch/arm/src/stm32/Kconfig
@@ -636,9 +636,11 @@ config ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG
config STM32_CCMEXCLUDE
bool "Exclude CCM SRAM from the heap"
depends on STM32_STM32F20XX || STM32_STM32F40XX
- default y if ARCH_DMA
+ default y if ARCH_DMA || ELF
---help---
- Exclude CCM SRAM from the HEAP because it cannot be used for DMA.
+ Exclude CCM SRAM from the HEAP because (1) it cannot be used for DMA
+ and (2) it appears to be impossible to execute ELF modules from CCM
+ RAM.
config STM32_FSMC_SRAM
bool "External SRAM on FSMC"
diff --git a/nuttx/binfmt/libelf/libelf_bind.c b/nuttx/binfmt/libelf/libelf_bind.c
index f41b5a0b6..54ea8f1f0 100644
--- a/nuttx/binfmt/libelf/libelf_bind.c
+++ b/nuttx/binfmt/libelf/libelf_bind.c
@@ -142,7 +142,10 @@ static int elf_relocate(FAR struct elf_loadinfo_s *loadinfo, int relidx,
int ret;
int i;
- /* Examine each relocation in the section */
+ /* Examine each relocation in the section. 'relsec' is the section
+ * containing the relations. 'dstsec' is the section containing the data
+ * to be relocated.
+ */
for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++)
{
diff --git a/nuttx/binfmt/libelf/libelf_init.c b/nuttx/binfmt/libelf/libelf_init.c
index e1b9f73d6..fa4b7983c 100644
--- a/nuttx/binfmt/libelf/libelf_init.c
+++ b/nuttx/binfmt/libelf/libelf_init.c
@@ -154,6 +154,7 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
/* Get the length of the file. */
ret = elf_filelen(loadinfo, filename);
+ if (ret < 0)
{
bdbg("elf_filelen failed: %d\n", ret);
return ret;
diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt
index d1a55daa9..e8f0ae166 100644
--- a/nuttx/configs/stm32f4discovery/README.txt
+++ b/nuttx/configs/stm32f4discovery/README.txt
@@ -1007,6 +1007,10 @@ Where <subdir> is one of the following:
3. By default, this project assumes that you are *NOT* using the DFU
bootloader.
+ 4. This configuration requires that you have the genromfs tool installed
+ on your system and that you have the full path to the installed genromfs
+ executable in PATH variable (see apps/examples/README.txt)
+
ostest:
------
This configuration directory, performs a simple OS test using
diff --git a/nuttx/configs/stm32f4discovery/elf/Make.defs b/nuttx/configs/stm32f4discovery/elf/Make.defs
index 7f5be08f0..c64102d17 100644
--- a/nuttx/configs/stm32f4discovery/elf/Make.defs
+++ b/nuttx/configs/stm32f4discovery/elf/Make.defs
@@ -160,6 +160,7 @@ LDNXFLATFLAGS = -e main -s 2048
# ELF module definitions
+CELFFLAGS = $(CFLAGS) -mlong-calls
LDELFFLAGS = -r -e main
ifeq ($(WINTOOL),y)
LDELFFLAGS += -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/gnu-elf.ld}"
diff --git a/nuttx/configs/stm32f4discovery/elf/defconfig b/nuttx/configs/stm32f4discovery/elf/defconfig
index dd5bd2829..6d72e4a9e 100644
--- a/nuttx/configs/stm32f4discovery/elf/defconfig
+++ b/nuttx/configs/stm32f4discovery/elf/defconfig
@@ -179,7 +179,7 @@ CONFIG_STM32_USART2=y
CONFIG_STM32_JTAG_SW_ENABLE=y
# CONFIG_STM32_FORCEPOWER is not set
# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set
-# CONFIG_STM32_CCMEXCLUDE is not set
+CONFIG_STM32_CCMEXCLUDE=y
#
# USB Host Configuration
@@ -251,7 +251,7 @@ CONFIG_SDCLONE_DISABLE=y
# CONFIG_SCHED_WAITPID is not set
# CONFIG_SCHED_ATEXIT is not set
# CONFIG_SCHED_ONEXIT is not set
-CONFIG_USER_ENTRYPOINT="ostest_main"
+CONFIG_USER_ENTRYPOINT="elf_main"
CONFIG_DISABLE_OS_API=y
# CONFIG_DISABLE_CLOCK is not set
# CONFIG_DISABLE_POSIX_TIMERS is not set
@@ -387,6 +387,7 @@ CONFIG_ELF_ALIGN_LOG2=2
CONFIG_ELF_STACKSIZE=2048
CONFIG_ELF_BUFFERSIZE=128
CONFIG_ELF_BUFFERINCR=32
+# CONFIG_ELF_CONSTRUCTORS is not set
CONFIG_SYMTAB_ORDEREDBYNAME=y
#
@@ -409,7 +410,7 @@ CONFIG_ARCH_LOWPUTC=y
CONFIG_LIB_SENDFILE_BUFSIZE=512
# CONFIG_ARCH_ROMGETC is not set
# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set
-# CONFIG_HAVE_CXX is not set
+CONFIG_HAVE_CXX=y
# CONFIG_HAVE_CXXINITIALIZE is not set
# CONFIG_CXX_NEWLONG is not set