rtems网络移植-网络shell命令介绍和使能

rtems对于BBB板的bsp默认是不包含网络驱动部分的,而TCP/IP协议栈也是默认没有启用的。因此要移植整个网络到bbb板上,首先要做的就是启用tcp/ip协议栈。然后使能这些网络命令。


第一步:使能tcp/ip协议栈

rtems在编译源码时,默认是不带网络协议栈的,但是在实际应用中,网络是必备的,当然rtems的维护公司也考虑到这一点,提供了简单的添加协议栈的方法

查看rtems源码文件夹下的configure文件:

其中有一段如下:

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-maintainer-mode
                          enable make rules and dependencies not useful (and
                          sometimes confusing) to the casual installer
  --enable-multiprocessing
                          enable multiprocessing interface; the
                          multiprocessing interface is a communication
                          interface between different RTEMS instances and
                          allows synchronization of objects via message
                          passing
  --enable-posix          enable posix interface
  --enable-networking     enable TCP/IP stack
  --enable-cxx            enable C++ support
  --enable-tests          enable tests (default:samples)
  --enable-rtems-debug    enable RTEMS_DEBUG
  --enable-rtemsbsp="bsp1 bsp2 .."
                          BSPs to include in build
  --enable-multilib       build many library versions (default=no)
  --enable-paravirt       enable support for paravirtualization (default=no)
  --enable-drvmgr         enable Driver Manager at Startup
  --enable-docs           enable building documentation (default:disabled)

因此只要在源码编译时,在configure命令后,加上--enable networking --enable posix即可。如图所示:


第二步:使能网络有关的shell命令:

这一步本人研究了半个多月,网上百度和谷歌都找了很多资料,基本没有提及如何使能这些命令。

要注意的是,rtems的shell命令中是有网络相关的命令比如ping、ifconfig、netstats等,只是没有使能,因此当进入系统shell,输入help all时,会出现已经使能的shell命令,在里面找不到ping、ifconfig等。而在源码中,可以搜索到这些网络的命令的源码和实现,如下图所示:


因此如何使能网络命令就是关键了,首先要明确的是,命令的实现和底层的驱动有关,但是命令的使能是独立的,与网路驱动无关,顶多在输入命令回车,会提示某个底层驱动函数缺失。

接下来本人尝试了修改源码中的shell的config文件,发现没有用。

接着在官网下载了shell的说明文档,里面关于network的描述是这样的:

The command set available to the application is user configurable. It is configured using a
mechanism similar to the confdefs.h mechanism used to specify application configuration.
In the simplest case, if the user wishes to configure a command set with all commands avail-
able that are neither filesystem management (e.g. mounting, formating, etc.) or network
related, then the following is all that is required:
#define CONFIGURE_SHELL_COMMANDS_INIT
#define CONFIGURE_SHELL_COMMANDS_ALL
#include <rtems/shellconfig.h>
In a slightly more complex example, if the user wishes to include all networking commands
as well as support for mounting MS-DOS and NFS filesystems, then the following is all that
is required:
#define CONFIGURE_SHELL_COMMANDS_INIT
#define CONFIGURE_SHELL_COMMANDS_ALL
#define CONFIGURE_SHELL_MOUNT_MSDOS
#define CONFIGURE_SHELL_MOUNT_NFS

#include <rtems/shellconfig.h>

这段的意思是,如果要求实现网络的命令要定义这四个变量,并且要包含shellconfig.h头文件,但是并没有说明应该将这些放在哪些文件中。


接下来的一段说明让这些疑问得到解答:

1.2.1 Customizing the Command Set
The user can configure specific command sets by either building up the set from individ-
ual commands or starting with a complete set and disabling individual commands. Each
command has two configuration macros associated with it.
CONFIGURE_SHELL_COMMAND_XXX
Each command has a constant of this form which is defined when
building a command set by individually enabling specific commands.
CONFIGURE_SHELL_NO_COMMAND_XXX
In contrast, each command has a similar command which is defined
when the application is configuring a command set by disabling spe-
cific commands in the set.

这段话的意思就是,如果使用者要配置命令,要定义对应的命令。

看到这里就比较明朗了,就是说如果要配置ping命令,就要在配置文件中,定义如下:

#define CONFIGURE_SHELL_COMMAND_PING

那么这些定义应该在custom的command文件中实现。

也就是说,在rki文件夹中,include头文件中,文件rtems_config.h中添加如下命令即可:

#define CONFIGURE_SHELL_COMMANDS_INIT
#define CONFIGURE_SHELL_COMMANDS_ALL
#define CONFIGURE_SHELL_MOUNT_RFS
#define CONFIGURE_SHELL_MOUNT_MSDOS
#define CONFIGURE_SHELL_MOUNT_NFS //c add
#define CONFIGURE_SHELL_COMMAND_IFCONFIG
#define CONFIGURE_SHELL_COMMAND_ROUTE
#define CONFIGURE_SHELL_COMMAND_PING
#define CONFIGURE_SHELL_COMMAND_NETSTATS

#include <rtems/shellconfig.h>


下面贴出本人的rtems_config.h文件内容:

/*
** rtems_config.h
**
**  Author:  Alan Cudmore
**
**  This contains the configuration settings for an RTEMS Application
**
*/

/*
** RTEMS Includes
*/
#include <rtems.h>

#include <bsp.h>

#ifdef RKI_INCLUDE_MONITOR
   #include <rtems/monitor.h>
#endif

#ifdef RKI_INCLUDE_TARFS
   #include <rtems/untar.h>
#endif

#include <rtems/mkrootfs.h>


/*
** RTEMS OS Configuration defintions
*/
#define TASK_INTLEVEL 0
#define CONFIGURE_INIT
#define CONFIGURE_INIT_TASK_ATTRIBUTES	(RTEMS_FLOATING_POINT | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(TASK_INTLEVEL))
#define CONFIGURE_INIT_TASK_STACK_SIZE	(32*1024)
#define CONFIGURE_INIT_TASK_PRIORITY	120

#define CONFIGURE_MAXIMUM_TASKS                       128
#define CONFIGURE_MAXIMUM_TIMERS                        5
#define CONFIGURE_MAXIMUM_SEMAPHORES                  512
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES              128

/* POSIX Keys are needed for the Shell */
#define CONFIGURE_MAXIMUM_POSIX_KEYS                   32
#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS        64

#define CONFIGURE_MAXIMUM_PARTITIONS                   2

#define CONFIGURE_EXECUTIVE_RAM_SIZE	( 1024 * 1024 )

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_DRIVERS                     10
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS     200
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_SWAPOUT_TASK_PRIORITY               10



#define CONFIGURE_SHELL_COMMANDS_INIT
#define CONFIGURE_SHELL_COMMANDS_ALL
#define CONFIGURE_SHELL_MOUNT_RFS
#define CONFIGURE_SHELL_MOUNT_MSDOS
#define CONFIGURE_SHELL_MOUNT_NFS //c add
#define CONFIGURE_SHELL_COMMAND_IFCONFIG
#define CONFIGURE_SHELL_COMMAND_ROUTE
#define CONFIGURE_SHELL_COMMAND_PING
#define CONFIGURE_SHELL_COMMAND_NETSTATS

#include <rtems/shellconfig.h>

#define CONFIGURE_MICROSECONDS_PER_TICK              10000

#define CONFIGURE_STACK_CHECKER_ENABLED

#define CONFIGURE_MAXIMUM_USER_EXTENSIONS     1


/*
** Filesystems needed
*/
/* IMFS and RFS will always be used */
#define CONFIGURE_FILESYSTEM_IMFS
#define CONFIGURE_FILESYSTEM_RFS
#define CONFIGURE_FILESYSTEM_TFTPFS
#define CONFIGURE_FILESYSTEM_MSDOS

/*
** Init task prototype
*/
rtems_task Init (rtems_task_argument argument);

/*
** This include file must be AFTER the
** configuration data.
*/
#include <rtems/confdefs.h>



然后编译后烧进sd卡启动即可。命令运行如图所示:









以上就是本人实现的网络命令,耗费了本人大量的心血,转载请说明出处。


转载于:https://www.cnblogs.com/sichenzhao/p/9320310.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值