Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #375, Separate network logic in pc-rtems to support generic targets #376

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fsw/pc-rtems/make/build_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# This indicates where to install target binaries created during the build
# Note - this should be phased out in favor of the staging dir from OSAL BSP
set(INSTALL_SUBDIR "eeprom")
set(INSTALL_SUBDIR "nonvol")

# Some upper-level code may be gated on _RTEMS_OS_ being defined
# This is for compatibility with older build scripts which defined this symbol,
Expand Down
87 changes: 84 additions & 3 deletions fsw/pc-rtems/src/cfe_psp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
#include <errno.h>
#include <rtems.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/rtems_dhcp_failsafe.h>
#include <bsp.h>
/* TODO Only needed for network setup, move? */
//#include <rtems/rtems_dhcp_failsafe.h>
//#include <bsp.h>

extern int rtems_fxp_attach(struct rtems_bsdnet_ifconfig *config, int attaching);

Expand Down Expand Up @@ -63,6 +64,8 @@ extern int rtems_fxp_attach(struct rtems_bsdnet_ifconfig *config, int attaching)

rtems_id RtemsTimerId;

/* TODO in pc but not in generic... might be the only unique stuff? */
#if 0
static unsigned char ethernet_address[6] = {0x00, 0x04, 0x9F, 0x00, 0x27, 0x61};
static char net_name_str[] = "fxp1";
static char ip_addr_str[] = "10.0.2.17";
Expand All @@ -78,9 +81,72 @@ static struct rtems_bsdnet_ifconfig netdriver_config = {
/* more options can follow */
};


struct rtems_bsdnet_config rtems_bsdnet_config = {
.ifconfig = &netdriver_config, .bootp = rtems_bsdnet_do_dhcp_failsafe, /* fill if DHCP is used*/
};
#endif

#if RTEMS_INCLUDE_TARFS /* TODO Is there a better networking-related define we can use here? */

#include <grlib/network_interface_add.h>

/* TODO Remove these pragmas and fix warnings generated */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
#pragma GCC diagnostic ignored "-Woverflow"

/*
* Network configuration
*/
/* TODO move to a separate file */
#include <rtems.h>
#include <bsp.h>

#include "bsp_rtems_cfg.h"

#include <drvmgr/drvmgr.h>

/* Configure Driver manager */
#if defined(RTEMS_DRVMGR_STARTUP) && defined(LEON3) /* if --drvmgr was given to configure */
/* Add Timer and UART Driver for this example */
#ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER
#endif
#ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART
#endif
#endif
#define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRETH /* TODO make dependent on OSAL NETWORK config */

#include <drvmgr/drvmgr_confdefs.h>

/* Set default IP and MAC if not defined */
#ifndef CONFIG_ETH_IP
#define CONFIG_ETH_IP "192.168.1.67"
#endif
#ifndef CONFIG_ETH_MAC
#define CONFIG_ETH_MAC {0x00, 0x80, 0x7F, 0x22, 0x61, 0x7A}
#endif

/* Table used by network interfaces that register themselves using the
* network_interface_add routine. From this table the IP address, netmask
* and Ethernet MAC address of an interface is taken.
*
* The network_interface_add routine puts the interface into the
* rtems_bsnet_config.ifconfig list.
*
* Set IP Address and Netmask to NULL to select BOOTP.
*/
struct ethernet_config interface_configs[] =
{
{ CONFIG_ETH_IP, "255.255.255.0", CONFIG_ETH_MAC}
};
#define INTERFACE_CONFIG_CNT (sizeof(interface_configs)/sizeof(struct ethernet_config) - 1)

#pragma GCC diagnostic pop

#endif

/*
** 1 HZ Timer "ISR"
Expand Down Expand Up @@ -112,6 +178,10 @@ int timer_count = 0;
*/
int CFE_PSP_Setup(void)
{

/* Only initialize the network if not using the rki2 */
#if RTEMS_INCLUDE_TARFS /* TODO Is there a better networking-related define? */

rtems_status_code status;

/*
Expand All @@ -123,6 +193,15 @@ int CFE_PSP_Setup(void)
{
printf("Network init not successful: %s / %s (continuing)\n", rtems_status_text(status), strerror(errno));
}
else
{
printf("Network initialized\n\n");
}
rtems_bsdnet_show_inet_routes();
printf("\n");
rtems_bsdnet_show_if_stats();
printf("\n");
#endif

return RTEMS_SUCCESSFUL;
}
Expand Down Expand Up @@ -200,7 +279,9 @@ void CFE_PSP_Main(void)
/*
** Set up the virtual FS mapping for the "/cf" directory
*/
Status = OS_FileSysAddFixedMap(&fs_id, "/mnt/eeprom", "/cf");
/* TODO maybe make this into a config... or just switch to nonvol */
// Status = OS_FileSysAddFixedMap(&fs_id, "/mnt/eeprom", "/cf");
Status = OS_FileSysAddFixedMap(&fs_id, "/nonvol", "/cf");
if (Status != OS_SUCCESS)
{
/* Print for informational purposes --
Expand Down
3 changes: 1 addition & 2 deletions unit-test-coverage/pc-rtems/src/coveragetest-cfe-psp-start.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void Test_CFE_PSP_Setup(void)
/* Test for printf due to error from rtems_bsdnet_initialize_network (function still returns RTEMS_SUCCESSFUL) */
UT_SetDefaultReturnValue(UT_KEY(PCS_rtems_bsdnet_initialize_network), -1);
UtAssert_INT32_EQ(CFE_PSP_Setup(), PCS_RTEMS_SUCCESSFUL);
UtAssert_STUB_COUNT(PCS_printf, 1);
}

void Test_OS_Application_Startup(void)
Expand Down Expand Up @@ -82,4 +81,4 @@ void Test_CFE_PSP_Main(void)
* failure of OS_FileSysAddFixedMap, and 1 from CFE_PSP_InitProcessorReservedMemory */
UtAssert_STUB_COUNT(OS_printf, 5);
UT_ResetState(UT_KEY(OS_printf)); /* Reset so cleared for future tests */
}
}
2 changes: 2 additions & 0 deletions unit-test-coverage/ut-stubs/inc/PCS_bsdnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ extern int PCS_rtems_fxp_attach(struct PCS_rtems_bsdnet_ifconfig *, int)
extern void PCS_rtems_bsdnet_do_dhcp_failsafe(void);
extern int PCS_rtems_bsdnet_initialize_network(void);
extern const char *PCS_rtems_status_text(PCS_rtems_status_code);
extern void PCS_rtems_bsdnet_show_inet_routes(void);
extern void PCS_rtems_bsdnet_show_if_stats(void);

#endif
23 changes: 23 additions & 0 deletions unit-test-coverage/ut-stubs/override_inc/drvmgr/drvmgr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed 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.
************************************************************************/

/* PSP coverage stub replacement for drvmgr.h */
#ifndef OVERRIDE_DRVMGR_H
#define OVERRIDE_DRVMGR_H

#endif
23 changes: 23 additions & 0 deletions unit-test-coverage/ut-stubs/override_inc/drvmgr/drvmgr_confdefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed 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.
************************************************************************/

/* PSP coverage stub replacement for drvmgr_confdefs.h */
#ifndef OVERRIDE_DRVMGR_CONFDEFS_H
#define OVERRIDE_DRVMGR_CONFDEFS_H

#endif
23 changes: 23 additions & 0 deletions unit-test-coverage/ut-stubs/override_inc/rtems/confdefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed 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.
************************************************************************/

/* PSP coverage stub replacement for confdefs.h */
#ifndef OVERRIDE_CONFDEFS_H
#define OVERRIDE_CONFDEFS_H

#endif
2 changes: 2 additions & 0 deletions unit-test-coverage/ut-stubs/override_inc/rtems/rtems_bsdnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
#define rtems_bsdnet_do_dhcp_failsafe PCS_rtems_bsdnet_do_dhcp_failsafe
#define rtems_bsdnet_initialize_network PCS_rtems_bsdnet_initialize_network
#define rtems_fxp_attach PCS_rtems_fxp_attach
#define rtems_bsdnet_show_inet_routes PCS_rtems_bsdnet_show_inet_routes
#define rtems_bsdnet_show_if_stats PCS_rtems_bsdnet_show_if_stats

#endif
12 changes: 11 additions & 1 deletion unit-test-coverage/ut-stubs/src/rtems-bsdnet-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ int PCS_rtems_bsdnet_initialize_network(void)
int PCS_rtems_fxp_attach(struct PCS_rtems_bsdnet_ifconfig *config, int attaching)
{
return UT_DEFAULT_IMPL(PCS_rtems_fxp_attach);
}
}

void PCS_rtems_bsdnet_show_inet_routes(void)
{
UT_DEFAULT_IMPL(PCS_rtems_bsdnet_show_inet_routes);
}

void PCS_rtems_bsdnet_show_if_stats(void)
{
UT_DEFAULT_IMPL(PCS_rtems_bsdnet_show_if_stats);
}
Loading