链接问题/-nostdlib(RPi4 上的 FreeRTOS+CLI)
背景: 我按照 Tlmada (https://github.com/TImada/raspi4_freertos) 的说明获取 FreeRTOS在 RPi4 上。 (主机:Ubuntu 18.04,交叉编译器:aarch64-none-elf) 下一步是在板上安装 FreeRTOS+CLI。我遵循了本教程(https://www.freertos.org/FreeRTOS-Plus /FreeRTOS_Plus_CLI/FreeRTOS_Plus_Command_Line_Interface.html),又名添加库(FreeRTOS_CLI.c
和 FreeRTOS_CLI.h
) 到我的项目并运行 makefile:
CROSS ?= aarch64-none-elf-
CFLAGS = -mcpu=cortex-a72 \
-fpic \
-ffreestanding \
-std=gnu99 \
-O2 \
-Wall \
-Wextra \
-DGUEST \
-I$(INCLUDEPATH1) \
-I$(INCLUDEPATH2) \
-I$(INCLUDEPATH3) \
-I$(INCLUDEPATH4) \
-I$(INCLUDEPATH5) \
-D__LINUX__
BUILTIN_OPS = -fno-builtin-memset
ASMFLAGS = -mcpu=cortex-a72
INCLUDEPATH1 ?= ./src
INCLUDEPATH2 ?= ../musl_libc
INCLUDEPATH3 ?= ../mmu
INCLUDEPATH4 ?= ../../../Source/include
INCLUDEPATH5 ?= ../../../Source/portable /GCC/ARM_CA72_64_BIT
# From ./src
OBJS = build/startup.o
OBJS +=build/FreeRTOS_asm_vector.o
OBJS +=build/FreeRTOS_tick_config.o
OBJS +=build/interrupt.o
OBJS +=build/FreeRTOS_CLI.o
OBJS +=build/main.o
OBJS +=build/mmu_cfg.o
OBJS +=build/uart.o
# From ../mmu
OBJS +=build/mmu.o
# From ../cache
OBJS +=build/cache.o
# From ../musl_libc
OBJS +=build/memset.o
OBJS +=build/memcpy.o
# From ../../../Source/portable /GCC/ARM_CA72_64_BIT
OBJS +=build/port.o
OBJS +=build/portASM.o
OBJS +=build/list.o
OBJS +=build/queue.o
OBJS +=build/tasks.o
OBJS +=build/timers.o
OBJS +=build/heap_1.o
uart.elf : src/raspberrypi4.ld $(OBJS)
$(CROSS)gcc --build-id=none -std=gnu99 -T src/raspberrypi4.ld -o $@ -nostdlib -ffreestanding --specs=nosys.specs $(BUILTIN_OPS) $(OBJS)
$(CROSS)objdump -d uart.elf > uart.list
build/%.o : src/%.S
$(CROSS)as $(ASMFLAGS) -c -o $@ $<
build/%.o : src/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ $<
build/%.o : ../mmu/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ $<
build/%.o : ../cache/%.S
$(CROSS)gcc $(CFLAGS) -c -o $@ $<
build/%.o : ../musl_libc/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ $<
build/%.o : ../../../Source/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ $<
build/%.o : ../../../Source/portable/GCC/ARM_CA72_64_BIT/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ $<
build/%.o : ../../../Source/portable/GCC/ARM_CA72_64_BIT/%.S
$(CROSS)as $(ASMFLAGS) -c -o $@ $<
build/%.o : ../../../Source/portable/MemMang/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ $<
clean :
rm -f build/*.o
rm -f *.elf
rm -f *.list
问题: 文件 FreeRTOS_CLI.c
引用了 string.h
,因此函数 strlen
、strncpy
、 无法找到 strncmp
,并且我得到以下 make 输出:
make CROSS=aarch64-none-elf-
aarch64-none-elf-gcc -Wl,--build-id=none -std=gnu99 -T src/raspberrypi4.ld -o uart.elf -ffreestanding -nostdlib --specs=nosys.specs -fno-builtin-memset build/startup.o build/FreeRTOS_asm_vector.o build/FreeRTOS_tick_config.o build/interrupt.o build/FreeRTOS_CLI.o build/main.o build/mmu_cfg.o build/uart.o build/mmu.o build/cache.o build/memset.o build/memcpy.o build/port.o build/portASM.o build/list.o build/queue.o build/tasks.o build/timers.o build/heap_1.o
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: build/FreeRTOS_CLI.o: in function `prvHelpCommand':
FreeRTOS_CLI.c:(.text+0x34): undefined reference to `strncpy'
FreeRTOS_CLI.c:(.text+0x34): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strncpy'
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: build/FreeRTOS_CLI.o: in function `FreeRTOS_CLIProcessCommand':
FreeRTOS_CLI.c:(.text+0x15c): undefined reference to `strlen'
FreeRTOS_CLI.c:(.text+0x15c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strlen'
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: FreeRTOS_CLI.c:(.text+0x170): undefined reference to `strncmp'
FreeRTOS_CLI.c:(.text+0x170): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strncmp'
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: FreeRTOS_CLI.c:(.text+0x1a8): undefined reference to `strncpy'
FreeRTOS_CLI.c:(.text+0x1a8): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strncpy'
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: FreeRTOS_CLI.c:(.text+0x244): undefined reference to `strncpy'
FreeRTOS_CLI.c:(.text+0x244): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strncpy'
collect2: error: ld returned 1 exit status
Makefile:63: recipe for target 'uart.elf' failed
make: *** [uart.elf] Error 1
输出对我来说很清楚,因为 makefile 使用选项 - 禁止标准库
string.h
nostdlib。
FreeRTOS_CLI.c
:
/*
* FreeRTOS+CLI V1.0.4
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/* Standard includes. */
#include <string.h>
#include <stdint.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Utils includes. */
#include "FreeRTOS_CLI.h"
/* If the application writer needs to place the buffer used by the CLI at a
fixed address then set configAPPLICATION_PROVIDES_cOutputBuffer to 1 in
FreeRTOSConfig.h, then declare an array with the following name and size in
one of the application files:
char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
*/
#ifndef configAPPLICATION_PROVIDES_cOutputBuffer
#define configAPPLICATION_PROVIDES_cOutputBuffer 0
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 400
#endif
typedef struct xCOMMAND_INPUT_LIST
{
const CLI_Command_Definition_t *pxCommandLineDefinition;
struct xCOMMAND_INPUT_LIST *pxNext;
} CLI_Definition_List_Item_t;
/*----------------------------------------------------------------*/
// My own Commands:
/* This function implements the behaviour of a command, so must have the correct
prototype. */
static BaseType_t prvTaskStatsCommand( int8_t *pcWriteBuffer,
size_t xWriteBufferLen,
const int8_t *pcCommandString )
{
/* For simplicity, this function assumes the output buffer is large enough
to hold all the text generated by executing the vTaskList() API function,
so the xWriteBufferLen parameter is not used. */
( void ) xWriteBufferLen;
/* pcWriteBuffer is used directly as the vTaskList() parameter, so the table
generated by executing vTaskList() is written directly into the output
buffer. */
//vTaskList( pcWriteBuffer + strlen( pcHeader ) );
*pcWriteBuffer = ( char ) 0x00;
pcWriteBuffer = "Hello world";
/* The entire table was written directly to the output buffer. Execution
of this command is complete, so return pdFALSE. */
return pdFALSE;
}
static const CLI_Command_Definition_t xTaskStatsCommand =
{
"hello",
"hello: CLI say Hello to the world",
prvTaskStatsCommand,
0
};
// Registering the xDelCommand structure with FreeRTOS+CLI
//FreeRTOS_CLIRegisterCommand( &xTaskStatsCommand );
/*----------------------------------------------------------------*/
/*
* The callback function that is executed when "help" is entered. This is the
* only default command that is always present.
*/
static BaseType_t prvHelpCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/*
* Return the number of parameters that follow the command name.
*/
static int8_t prvGetNumberOfParameters( const char *pcCommandString );
/* The definition of the "help" command. This command is always at the front
of the list of registered commands. */
static const CLI_Command_Definition_t xHelpCommand =
{
"help",
"\r\nhelp:\r\n Lists all the registered commands\r\n\r\n",
prvHelpCommand,
0
};
/* The definition of the list of commands. Commands that are registered are
added to this list. */
static CLI_Definition_List_Item_t xRegisteredCommands =
{
&xHelpCommand, /* The first command in the list is always the help command, defined in this file. */
&xTaskStatsCommand,
NULL /* The next pointer is initialised to NULL, as there are no other registered commands yet. */
};
/* A buffer into which command outputs can be written is declared here, rather
than in the command console implementation, to allow multiple command consoles
to share the same buffer. For example, an application may allow access to the
command interpreter by UART and by Ethernet. Sharing a buffer is done purely
to save RAM. Note, however, that the command console itself is not re-entrant,
so only one command interpreter interface can be used at any one time. For that
reason, no attempt at providing mutual exclusion to the cOutputBuffer array is
attempted.
configAPPLICATION_PROVIDES_cOutputBuffer is provided to allow the application
writer to provide their own cOutputBuffer declaration in cases where the
buffer needs to be placed at a fixed address (rather than by the linker). */
#if( configAPPLICATION_PROVIDES_cOutputBuffer == 0 )
static char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
#else
extern char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
#endif
/*-----------------------------------------------------------*/
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
{
static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
CLI_Definition_List_Item_t *pxNewListItem;
BaseType_t xReturn = pdFAIL;
/* Check the parameter is not NULL. */
configASSERT( pxCommandToRegister );
/* Create a new list item that will reference the command being registered. */
pxNewListItem = ( CLI_Definition_List_Item_t * ) pvPortMalloc( sizeof( CLI_Definition_List_Item_t ) );
configASSERT( pxNewListItem );
if( pxNewListItem != NULL )
{
taskENTER_CRITICAL();
{
/* Reference the command being registered from the newly created
list item. */
pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;
/* The new list item will get added to the end of the list, so
pxNext has nowhere to point. */
pxNewListItem->pxNext = NULL;
/* Add the newly created list item to the end of the already existing
list. */
pxLastCommandInList->pxNext = pxNewListItem;
/* Set the end of list marker to the new list item. */
pxLastCommandInList = pxNewListItem;
}
taskEXIT_CRITICAL();
xReturn = pdPASS;
}
return xReturn;
}
/*-----------------------------------------------------------*/
BaseType_t FreeRTOS_CLIProcessCommand( const char * const pcCommandInput, char * pcWriteBuffer, size_t xWriteBufferLen )
{
static const CLI_Definition_List_Item_t *pxCommand = NULL;
BaseType_t xReturn = pdTRUE;
const char *pcRegisteredCommandString;
size_t xCommandStringLength;
/* Note: This function is not re-entrant. It must not be called from more
thank one task. */
if( pxCommand == NULL )
{
/* Search for the command string in the list of registered commands. */
for( pxCommand = &xRegisteredCommands; pxCommand != NULL; pxCommand = pxCommand->pxNext )
{
pcRegisteredCommandString = pxCommand->pxCommandLineDefinition->pcCommand;
xCommandStringLength = strlen( pcRegisteredCommandString );
/* To ensure the string lengths match exactly, so as not to pick up
a sub-string of a longer command, check the byte after the expected
end of the string is either the end of the string or a space before
a parameter. */
if( strncmp( pcCommandInput, pcRegisteredCommandString, xCommandStringLength ) == 0 )
{
if( ( pcCommandInput[ xCommandStringLength ] == ' ' ) || ( pcCommandInput[ xCommandStringLength ] == 0x00 ) )
{
/* The command has been found. Check it has the expected
number of parameters. If cExpectedNumberOfParameters is -1,
then there could be a variable number of parameters and no
check is made. */
if( pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters >= 0 )
{
if( prvGetNumberOfParameters( pcCommandInput ) != pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters )
{
xReturn = pdFALSE;
}
}
break;
}
}
}
}
if( ( pxCommand != NULL ) && ( xReturn == pdFALSE ) )
{
/* The command was found, but the number of parameters with the command
was incorrect. */
strncpy( pcWriteBuffer, "Incorrect command parameter(s). Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );
pxCommand = NULL;
}
else if( pxCommand != NULL )
{
/* Call the callback function that is registered to this command. */
xReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter( pcWriteBuffer, xWriteBufferLen, pcCommandInput );
/* If xReturn is pdFALSE, then no further strings will be returned
after this one, and pxCommand can be reset to NULL ready to search
for the next entered command. */
if( xReturn == pdFALSE )
{
pxCommand = NULL;
}
}
else
{
/* pxCommand was NULL, the command was not found. */
strncpy( pcWriteBuffer, "Command not recognised. Enter 'help' to view a list of available commands.\r\n\r\n", xWriteBufferLen );
xReturn = pdFALSE;
}
return xReturn;
}
/*-----------------------------------------------------------*/
char *FreeRTOS_CLIGetOutputBuffer( void )
{
return cOutputBuffer;
}
/*-----------------------------------------------------------*/
const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t uxWantedParameter, BaseType_t *pxParameterStringLength )
{
UBaseType_t uxParametersFound = 0;
const char *pcReturn = NULL;
*pxParameterStringLength = 0;
while( uxParametersFound < uxWantedParameter )
{
/* Index the character pointer past the current word. If this is the start
of the command string then the first word is the command itself. */
while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )
{
pcCommandString++;
}
/* Find the start of the next string. */
while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) == ' ' ) )
{
pcCommandString++;
}
/* Was a string found? */
if( *pcCommandString != 0x00 )
{
/* Is this the start of the required parameter? */
uxParametersFound++;
if( uxParametersFound == uxWantedParameter )
{
/* How long is the parameter? */
pcReturn = pcCommandString;
while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )
{
( *pxParameterStringLength )++;
pcCommandString++;
}
if( *pxParameterStringLength == 0 )
{
pcReturn = NULL;
}
break;
}
}
else
{
break;
}
}
return pcReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvHelpCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
static const CLI_Definition_List_Item_t * pxCommand = NULL;
BaseType_t xReturn;
( void ) pcCommandString;
if( pxCommand == NULL )
{
/* Reset the pxCommand pointer back to the start of the list. */
pxCommand = &xRegisteredCommands;
}
/* Return the next command help string, before moving the pointer on to
the next command in the list. */
strncpy( pcWriteBuffer, pxCommand->pxCommandLineDefinition->pcHelpString, xWriteBufferLen );
pxCommand = pxCommand->pxNext;
if( pxCommand == NULL )
{
/* There are no more commands in the list, so there will be no more
strings to return after this one and pdFALSE should be returned. */
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static int8_t prvGetNumberOfParameters( const char *pcCommandString )
{
int8_t cParameters = 0;
BaseType_t xLastCharacterWasSpace = pdFALSE;
/* Count the number of space delimited words in pcCommandString. */
while( *pcCommandString != 0x00 )
{
if( ( *pcCommandString ) == ' ' )
{
if( xLastCharacterWasSpace != pdTRUE )
{
cParameters++;
xLastCharacterWasSpace = pdTRUE;
}
}
else
{
xLastCharacterWasSpace = pdFALSE;
}
pcCommandString++;
}
/* If the command string ended with spaces, then there will have been too
many parameters counted. */
if( xLastCharacterWasSpace == pdTRUE )
{
cParameters--;
}
/* The value returned is one less than the number of space delimited words,
as the first word should be the command itself. */
return cParameters;
}
到目前为止我做了什么:
删除 makefile 中的
-nostdlib
。 ->这会导致链接器文件中没有对 __bss_start__ 的引用。 错误输出:make CROSS=aarch64-none-elf-
aarch64-none-elf-gcc -Wl,--build-id=none -std=gnu99 -T src/raspberrypi4.ld -o uart.elf -ffreestand --specs=nosys.specs -fno-builtin- memset build/startup.o build/FreeRTOS_asm_vector.o build/FreeRTOS_tick_config.o build/interrupt.o构建/FreeRTOS_CLI.o 构建/main.o 构建/mmu_cfg.o 构建/uart.o 构建/mmu.o 构建/cache.o 构建/memset.o 构建/memcpy.o 构建/port.o 构建/portASM.o构建/list.o 构建/queue.o 构建/tasks.o 构建/timers.o 构建/heap_1.o /usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../. ./aarch64-none-elf/bin/ld: /usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../. ./aarch64-none-elf/lib/crt0.o:在函数“_cpu_init_hook”中: /tmp/dgboter/bbs/rhev-vm1--rhe6x86_64/buildbot/rhe6x86_64--aarch64-none-elf/build/src/newlib-cygwin/libgloss/aarch64/crt0.S:269:对“__bss_start__”的未定义引用/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../. ./aarch64-none-elf/bin/ld: /tmp/dgboter/bbs/rhev-vm1--rhe6x86_64/buildbot/rhe6x86_64--aarch64-none-elf/build/src/newlib-cygwin/libgloss/aarch64/crt0.S:269:对“__bss_end__”collect2的未定义引用: 错误: ld 返回 1 退出状态 Makefile:63:目标“uart.elf”的配方失败:*** [uart.elf]错误1
这是链接文件(raspberrypi4.ld
):
ENTRY(_boot)
CODE_BASE = 0x20000000;
DATA_BASE = 0x20200000;
STACK_TOP = 0x20600000;
PT_BASE = 0x20600000;
SECTIONS
{
/* Starts at 0x20000000 (assuming ends at 0x208FFFFF, 9MB). */
. = CODE_BASE;
__start = .;
__text_start = .;
.text :
{
KEEP(*(.vectors))
KEEP(*(.text.boot))
*(.text)
}
__text_end = .;
. = ALIGN(4096); /* align to page size */
__data_start = DATA_BASE;
.data :
{
*(.data)
}
. = ALIGN(4096); /* align to page size */
__data_end = .;
__bss_start = .;
.bss :
{
bss = .;
*(.bss)
}
. = ALIGN(4096); /* align to page size */
__bss_end = .;
__end = .;
. = STACK_TOP; /* stack memory */
stack_top = .;
. = PT_BASE; /* Page tables */
.pt :
{
*(.pt)
}
}
__bss_size = (__bss_end -
__bss_start)>>3;
- 我想把
string.h
位于包含原始内容的项目子文件夹中,这样我就不需要标准库了。但我在互联网上找不到正确的string.h
文件(string.h
本身没有错误)。
有人有解决方案或者可以为我指明方向吗? 先感谢您。
Background:
I followed the instruction from Tlmada (https://github.com/TImada/raspi4_freertos) to get FreeRTOS on RPi4. (Host: Ubuntu 18.04, Cross-Compiler: aarch64-none-elf)
Next step was to get FreeRTOS+CLI on the board. I followed this tutorial (https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_CLI/FreeRTOS_Plus_Command_Line_Interface.html), aka added the libraries (FreeRTOS_CLI.c
and FreeRTOS_CLI.h
) to my project and ran the makefile:
CROSS ?= aarch64-none-elf-
CFLAGS = -mcpu=cortex-a72 \
-fpic \
-ffreestanding \
-std=gnu99 \
-O2 \
-Wall \
-Wextra \
-DGUEST \
-I$(INCLUDEPATH1) \
-I$(INCLUDEPATH2) \
-I$(INCLUDEPATH3) \
-I$(INCLUDEPATH4) \
-I$(INCLUDEPATH5) \
-D__LINUX__
BUILTIN_OPS = -fno-builtin-memset
ASMFLAGS = -mcpu=cortex-a72
INCLUDEPATH1 ?= ./src
INCLUDEPATH2 ?= ../musl_libc
INCLUDEPATH3 ?= ../mmu
INCLUDEPATH4 ?= ../../../Source/include
INCLUDEPATH5 ?= ../../../Source/portable /GCC/ARM_CA72_64_BIT
# From ./src
OBJS = build/startup.o
OBJS +=build/FreeRTOS_asm_vector.o
OBJS +=build/FreeRTOS_tick_config.o
OBJS +=build/interrupt.o
OBJS +=build/FreeRTOS_CLI.o
OBJS +=build/main.o
OBJS +=build/mmu_cfg.o
OBJS +=build/uart.o
# From ../mmu
OBJS +=build/mmu.o
# From ../cache
OBJS +=build/cache.o
# From ../musl_libc
OBJS +=build/memset.o
OBJS +=build/memcpy.o
# From ../../../Source/portable /GCC/ARM_CA72_64_BIT
OBJS +=build/port.o
OBJS +=build/portASM.o
OBJS +=build/list.o
OBJS +=build/queue.o
OBJS +=build/tasks.o
OBJS +=build/timers.o
OBJS +=build/heap_1.o
uart.elf : src/raspberrypi4.ld $(OBJS)
$(CROSS)gcc --build-id=none -std=gnu99 -T src/raspberrypi4.ld -o $@ -nostdlib -ffreestanding --specs=nosys.specs $(BUILTIN_OPS) $(OBJS)
$(CROSS)objdump -d uart.elf > uart.list
build/%.o : src/%.S
$(CROSS)as $(ASMFLAGS) -c -o $@ lt;
build/%.o : src/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ lt;
build/%.o : ../mmu/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ lt;
build/%.o : ../cache/%.S
$(CROSS)gcc $(CFLAGS) -c -o $@ lt;
build/%.o : ../musl_libc/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ lt;
build/%.o : ../../../Source/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ lt;
build/%.o : ../../../Source/portable/GCC/ARM_CA72_64_BIT/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ lt;
build/%.o : ../../../Source/portable/GCC/ARM_CA72_64_BIT/%.S
$(CROSS)as $(ASMFLAGS) -c -o $@ lt;
build/%.o : ../../../Source/portable/MemMang/%.c
$(CROSS)gcc $(CFLAGS) -c -o $@ lt;
clean :
rm -f build/*.o
rm -f *.elf
rm -f *.list
Problem:
The file FreeRTOS_CLI.c
is referring to string.h
, so the functions strlen
, strncpy
, strncmp
can't be found and I get the following output for make:
make CROSS=aarch64-none-elf-
aarch64-none-elf-gcc -Wl,--build-id=none -std=gnu99 -T src/raspberrypi4.ld -o uart.elf -ffreestanding -nostdlib --specs=nosys.specs -fno-builtin-memset build/startup.o build/FreeRTOS_asm_vector.o build/FreeRTOS_tick_config.o build/interrupt.o build/FreeRTOS_CLI.o build/main.o build/mmu_cfg.o build/uart.o build/mmu.o build/cache.o build/memset.o build/memcpy.o build/port.o build/portASM.o build/list.o build/queue.o build/tasks.o build/timers.o build/heap_1.o
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: build/FreeRTOS_CLI.o: in function `prvHelpCommand':
FreeRTOS_CLI.c:(.text+0x34): undefined reference to `strncpy'
FreeRTOS_CLI.c:(.text+0x34): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strncpy'
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: build/FreeRTOS_CLI.o: in function `FreeRTOS_CLIProcessCommand':
FreeRTOS_CLI.c:(.text+0x15c): undefined reference to `strlen'
FreeRTOS_CLI.c:(.text+0x15c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strlen'
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: FreeRTOS_CLI.c:(.text+0x170): undefined reference to `strncmp'
FreeRTOS_CLI.c:(.text+0x170): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strncmp'
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: FreeRTOS_CLI.c:(.text+0x1a8): undefined reference to `strncpy'
FreeRTOS_CLI.c:(.text+0x1a8): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strncpy'
/usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: FreeRTOS_CLI.c:(.text+0x244): undefined reference to `strncpy'
FreeRTOS_CLI.c:(.text+0x244): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `strncpy'
collect2: error: ld returned 1 exit status
Makefile:63: recipe for target 'uart.elf' failed
make: *** [uart.elf] Error 1
The output is clear to me, because the makefile prohibits the standard library string.h
with the option -nostdlib
.
FreeRTOS_CLI.c
:
/*
* FreeRTOS+CLI V1.0.4
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/* Standard includes. */
#include <string.h>
#include <stdint.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Utils includes. */
#include "FreeRTOS_CLI.h"
/* If the application writer needs to place the buffer used by the CLI at a
fixed address then set configAPPLICATION_PROVIDES_cOutputBuffer to 1 in
FreeRTOSConfig.h, then declare an array with the following name and size in
one of the application files:
char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
*/
#ifndef configAPPLICATION_PROVIDES_cOutputBuffer
#define configAPPLICATION_PROVIDES_cOutputBuffer 0
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 400
#endif
typedef struct xCOMMAND_INPUT_LIST
{
const CLI_Command_Definition_t *pxCommandLineDefinition;
struct xCOMMAND_INPUT_LIST *pxNext;
} CLI_Definition_List_Item_t;
/*----------------------------------------------------------------*/
// My own Commands:
/* This function implements the behaviour of a command, so must have the correct
prototype. */
static BaseType_t prvTaskStatsCommand( int8_t *pcWriteBuffer,
size_t xWriteBufferLen,
const int8_t *pcCommandString )
{
/* For simplicity, this function assumes the output buffer is large enough
to hold all the text generated by executing the vTaskList() API function,
so the xWriteBufferLen parameter is not used. */
( void ) xWriteBufferLen;
/* pcWriteBuffer is used directly as the vTaskList() parameter, so the table
generated by executing vTaskList() is written directly into the output
buffer. */
//vTaskList( pcWriteBuffer + strlen( pcHeader ) );
*pcWriteBuffer = ( char ) 0x00;
pcWriteBuffer = "Hello world";
/* The entire table was written directly to the output buffer. Execution
of this command is complete, so return pdFALSE. */
return pdFALSE;
}
static const CLI_Command_Definition_t xTaskStatsCommand =
{
"hello",
"hello: CLI say Hello to the world",
prvTaskStatsCommand,
0
};
// Registering the xDelCommand structure with FreeRTOS+CLI
//FreeRTOS_CLIRegisterCommand( &xTaskStatsCommand );
/*----------------------------------------------------------------*/
/*
* The callback function that is executed when "help" is entered. This is the
* only default command that is always present.
*/
static BaseType_t prvHelpCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/*
* Return the number of parameters that follow the command name.
*/
static int8_t prvGetNumberOfParameters( const char *pcCommandString );
/* The definition of the "help" command. This command is always at the front
of the list of registered commands. */
static const CLI_Command_Definition_t xHelpCommand =
{
"help",
"\r\nhelp:\r\n Lists all the registered commands\r\n\r\n",
prvHelpCommand,
0
};
/* The definition of the list of commands. Commands that are registered are
added to this list. */
static CLI_Definition_List_Item_t xRegisteredCommands =
{
&xHelpCommand, /* The first command in the list is always the help command, defined in this file. */
&xTaskStatsCommand,
NULL /* The next pointer is initialised to NULL, as there are no other registered commands yet. */
};
/* A buffer into which command outputs can be written is declared here, rather
than in the command console implementation, to allow multiple command consoles
to share the same buffer. For example, an application may allow access to the
command interpreter by UART and by Ethernet. Sharing a buffer is done purely
to save RAM. Note, however, that the command console itself is not re-entrant,
so only one command interpreter interface can be used at any one time. For that
reason, no attempt at providing mutual exclusion to the cOutputBuffer array is
attempted.
configAPPLICATION_PROVIDES_cOutputBuffer is provided to allow the application
writer to provide their own cOutputBuffer declaration in cases where the
buffer needs to be placed at a fixed address (rather than by the linker). */
#if( configAPPLICATION_PROVIDES_cOutputBuffer == 0 )
static char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
#else
extern char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
#endif
/*-----------------------------------------------------------*/
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
{
static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
CLI_Definition_List_Item_t *pxNewListItem;
BaseType_t xReturn = pdFAIL;
/* Check the parameter is not NULL. */
configASSERT( pxCommandToRegister );
/* Create a new list item that will reference the command being registered. */
pxNewListItem = ( CLI_Definition_List_Item_t * ) pvPortMalloc( sizeof( CLI_Definition_List_Item_t ) );
configASSERT( pxNewListItem );
if( pxNewListItem != NULL )
{
taskENTER_CRITICAL();
{
/* Reference the command being registered from the newly created
list item. */
pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;
/* The new list item will get added to the end of the list, so
pxNext has nowhere to point. */
pxNewListItem->pxNext = NULL;
/* Add the newly created list item to the end of the already existing
list. */
pxLastCommandInList->pxNext = pxNewListItem;
/* Set the end of list marker to the new list item. */
pxLastCommandInList = pxNewListItem;
}
taskEXIT_CRITICAL();
xReturn = pdPASS;
}
return xReturn;
}
/*-----------------------------------------------------------*/
BaseType_t FreeRTOS_CLIProcessCommand( const char * const pcCommandInput, char * pcWriteBuffer, size_t xWriteBufferLen )
{
static const CLI_Definition_List_Item_t *pxCommand = NULL;
BaseType_t xReturn = pdTRUE;
const char *pcRegisteredCommandString;
size_t xCommandStringLength;
/* Note: This function is not re-entrant. It must not be called from more
thank one task. */
if( pxCommand == NULL )
{
/* Search for the command string in the list of registered commands. */
for( pxCommand = &xRegisteredCommands; pxCommand != NULL; pxCommand = pxCommand->pxNext )
{
pcRegisteredCommandString = pxCommand->pxCommandLineDefinition->pcCommand;
xCommandStringLength = strlen( pcRegisteredCommandString );
/* To ensure the string lengths match exactly, so as not to pick up
a sub-string of a longer command, check the byte after the expected
end of the string is either the end of the string or a space before
a parameter. */
if( strncmp( pcCommandInput, pcRegisteredCommandString, xCommandStringLength ) == 0 )
{
if( ( pcCommandInput[ xCommandStringLength ] == ' ' ) || ( pcCommandInput[ xCommandStringLength ] == 0x00 ) )
{
/* The command has been found. Check it has the expected
number of parameters. If cExpectedNumberOfParameters is -1,
then there could be a variable number of parameters and no
check is made. */
if( pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters >= 0 )
{
if( prvGetNumberOfParameters( pcCommandInput ) != pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters )
{
xReturn = pdFALSE;
}
}
break;
}
}
}
}
if( ( pxCommand != NULL ) && ( xReturn == pdFALSE ) )
{
/* The command was found, but the number of parameters with the command
was incorrect. */
strncpy( pcWriteBuffer, "Incorrect command parameter(s). Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );
pxCommand = NULL;
}
else if( pxCommand != NULL )
{
/* Call the callback function that is registered to this command. */
xReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter( pcWriteBuffer, xWriteBufferLen, pcCommandInput );
/* If xReturn is pdFALSE, then no further strings will be returned
after this one, and pxCommand can be reset to NULL ready to search
for the next entered command. */
if( xReturn == pdFALSE )
{
pxCommand = NULL;
}
}
else
{
/* pxCommand was NULL, the command was not found. */
strncpy( pcWriteBuffer, "Command not recognised. Enter 'help' to view a list of available commands.\r\n\r\n", xWriteBufferLen );
xReturn = pdFALSE;
}
return xReturn;
}
/*-----------------------------------------------------------*/
char *FreeRTOS_CLIGetOutputBuffer( void )
{
return cOutputBuffer;
}
/*-----------------------------------------------------------*/
const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t uxWantedParameter, BaseType_t *pxParameterStringLength )
{
UBaseType_t uxParametersFound = 0;
const char *pcReturn = NULL;
*pxParameterStringLength = 0;
while( uxParametersFound < uxWantedParameter )
{
/* Index the character pointer past the current word. If this is the start
of the command string then the first word is the command itself. */
while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )
{
pcCommandString++;
}
/* Find the start of the next string. */
while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) == ' ' ) )
{
pcCommandString++;
}
/* Was a string found? */
if( *pcCommandString != 0x00 )
{
/* Is this the start of the required parameter? */
uxParametersFound++;
if( uxParametersFound == uxWantedParameter )
{
/* How long is the parameter? */
pcReturn = pcCommandString;
while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )
{
( *pxParameterStringLength )++;
pcCommandString++;
}
if( *pxParameterStringLength == 0 )
{
pcReturn = NULL;
}
break;
}
}
else
{
break;
}
}
return pcReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvHelpCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
static const CLI_Definition_List_Item_t * pxCommand = NULL;
BaseType_t xReturn;
( void ) pcCommandString;
if( pxCommand == NULL )
{
/* Reset the pxCommand pointer back to the start of the list. */
pxCommand = &xRegisteredCommands;
}
/* Return the next command help string, before moving the pointer on to
the next command in the list. */
strncpy( pcWriteBuffer, pxCommand->pxCommandLineDefinition->pcHelpString, xWriteBufferLen );
pxCommand = pxCommand->pxNext;
if( pxCommand == NULL )
{
/* There are no more commands in the list, so there will be no more
strings to return after this one and pdFALSE should be returned. */
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
return xReturn;
}
/*-----------------------------------------------------------*/
static int8_t prvGetNumberOfParameters( const char *pcCommandString )
{
int8_t cParameters = 0;
BaseType_t xLastCharacterWasSpace = pdFALSE;
/* Count the number of space delimited words in pcCommandString. */
while( *pcCommandString != 0x00 )
{
if( ( *pcCommandString ) == ' ' )
{
if( xLastCharacterWasSpace != pdTRUE )
{
cParameters++;
xLastCharacterWasSpace = pdTRUE;
}
}
else
{
xLastCharacterWasSpace = pdFALSE;
}
pcCommandString++;
}
/* If the command string ended with spaces, then there will have been too
many parameters counted. */
if( xLastCharacterWasSpace == pdTRUE )
{
cParameters--;
}
/* The value returned is one less than the number of space delimited words,
as the first word should be the command itself. */
return cParameters;
}
What I did so far:
Deleting
-nostdlib
in makefile. -> This leads tono reference to __bss_start__
in linker file.
Error output:make CROSS=aarch64-none-elf-
aarch64-none-elf-gcc -Wl,--build-id=none -std=gnu99 -T src/raspberrypi4.ld -o uart.elf -ffreestanding --specs=nosys.specs -fno-builtin-memset build/startup.o build/FreeRTOS_asm_vector.o build/FreeRTOS_tick_config.o build/interrupt.o build/FreeRTOS_CLI.o build/main.o build/mmu_cfg.o build/uart.o build/mmu.o build/cache.o build/memset.o build/memcpy.o build/port.o build/portASM.o build/list.o build/queue.o build/tasks.o build/timers.o build/heap_1.o /usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: /usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/lib/crt0.o: in function '_cpu_init_hook': /tmp/dgboter/bbs/rhev-vm1--rhe6x86_64/buildbot/rhe6x86_64--aarch64-none-elf/build/src/newlib-cygwin/libgloss/aarch64/crt0.S:269: undefined reference to '__bss_start__' /usr/share/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin/../lib/gcc/aarch64-none-elf/9.2.1/../../../../aarch64-none-elf/bin/ld: /tmp/dgboter/bbs/rhev-vm1--rhe6x86_64/buildbot/rhe6x86_64--aarch64-none-elf/build/src/newlib-cygwin/libgloss/aarch64/crt0.S:269: undefined reference to '__bss_end__' collect2: error: ld returned 1 exit status Makefile:63: recipe for target 'uart.elf' failed make: *** [uart.elf] Error 1
Here is the link file (raspberrypi4.ld
):
ENTRY(_boot)
CODE_BASE = 0x20000000;
DATA_BASE = 0x20200000;
STACK_TOP = 0x20600000;
PT_BASE = 0x20600000;
SECTIONS
{
/* Starts at 0x20000000 (assuming ends at 0x208FFFFF, 9MB). */
. = CODE_BASE;
__start = .;
__text_start = .;
.text :
{
KEEP(*(.vectors))
KEEP(*(.text.boot))
*(.text)
}
__text_end = .;
. = ALIGN(4096); /* align to page size */
__data_start = DATA_BASE;
.data :
{
*(.data)
}
. = ALIGN(4096); /* align to page size */
__data_end = .;
__bss_start = .;
.bss :
{
bss = .;
*(.bss)
}
. = ALIGN(4096); /* align to page size */
__bss_end = .;
__end = .;
. = STACK_TOP; /* stack memory */
stack_top = .;
. = PT_BASE; /* Page tables */
.pt :
{
*(.pt)
}
}
__bss_size = (__bss_end -
__bss_start)>>3;
- I want to put
string.h
in a project subfolder with the original content, so that I don't need the standard libraries. But I can't find a correctstring.h
file on the internet (without errors in thestring.h
itself).
Does anybody have a solution or can point me in the direction?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论