Skip to content

Commit

Permalink
Fix nasa#1447 nasa#1349, Add TARFS functionality and finish generic R…
Browse files Browse the repository at this point in the history
…TEMS support
  • Loading branch information
skliper authored and pepepr08 committed Feb 29, 2024
1 parent 4ed8b18 commit 4833980
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 217 deletions.
55 changes: 40 additions & 15 deletions src/bsp/pc-rtems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@
# Basic set of files
set(OS_BSP_SRCLIST
src/bsp_console.c
src/bsp_init.c
src/bsp_start.c
)

# If dynamic loading but also using TARFS, we use our Init to untar and
# set up file system based on tarfile contents
if (RTEMS_DYNAMIC_LOAD AND RTEMS_INCLUDE_TARFS)
# Source select file system setup implementation
if (RTEMS_INCLUDE_TARFS)
list(APPEND OS_BSP_SRCLIST
src/bsp_init.c
src/bsp_setupfs.c # TODO move to only if enabled
src/bsp_tarfs_setupfs.c
)
endif ()

# If not dynamic loading, include Init and config
if (NOT RTEMS_DYNAMIC_LOAD)
else ()
# NOTE: rtems config needs to define supporting configuration (FILESYSTEM and DRIVERs)
list(APPEND OS_BSP_SRCLIST
src/bsp_init.c
src/bsp_setupfs.c # TODO move to only if enabled
src/bsp_mount_setupfs.c
)
endif ()

# TODO could add the two flags for FS support vs adding from include

# Link the RTEMS BSP with the "rtemscpu" system library
# Link rtemscpu to osal public api if not dynamic loading
if (NOT RTEMS_DYNAMIC_LOAD)
target_link_libraries(osal_public_api INTERFACE
rtemscpu
)
Expand All @@ -44,7 +40,15 @@ else ()
)
endif ()

# TODO add the cmdline if not RTEMS_NO_CMDLINE
if (RTEMS_NO_CMDLINE)
list(APPEND OS_BSP_SRCLIST
src/bsp_no_cmdline.c
)
else ()
list(APPEND OS_BSP_SRCLIST
src/bsp_cmdline.c
)
endif ()

add_library(osal_pc-rtems_impl OBJECT
${OS_BSP_SRCLIST}
Expand All @@ -58,3 +62,24 @@ target_compile_definitions(osal_public_api INTERFACE
)

set_property(TARGET osal_pc-rtems_impl PROPERTY OSAL_EXPECTED_OSTYPE "rtems")

# The list of header files that control configuration
set(BSP_RTEMS_CONFIG_FILE_LIST
bsp_rtems_cfg.h
)

# Create wrappers around all the config header files
# This makes them individually overridable by the missions, without modifying
# the distribution default copies
foreach(BSP_RTEMS_CFGFILE ${BSP_RTEMS_CONFIG_FILE_LIST})
get_filename_component(CFGKEY "${BSP_RTEMS_CFGFILE}" NAME_WE)
if (DEFINED BSP_RTEMS_CFGFILE_SRC_${CFGKEY})
set(DEFAULT_SOURCE GENERATED_FILE "${BSP_RTEMS_CFGFILE_SRC_${CFGKEY}}")
else()
set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${BSP_RTEMS_CFGFILE}")
endif()
generate_config_includefile(
FILE_NAME "${BSP_RTEMS_CFGFILE}"
${DEFAULT_SOURCE}
)
endforeach()
82 changes: 82 additions & 0 deletions src/bsp/pc-rtems/config/default_bsp_rtems_cfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/************************************************************************
* 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.
************************************************************************/

/**
* @file
* Default RTEMS OS Configuration definitions
*
* @note
* This file may be overridden/superseded by mission-provided definitions
* by overriding this header.
*/
#ifndef BSP_RTEMS_CFG_H
#define BSP_RTEMS_CFG_H

#include "osconfig.h"

#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 (20 * 1024)
#define CONFIGURE_INIT_TASK_PRIORITY 10

/*
* Note that these resources are shared with RTEMS itself (e.g. the init task, the shell)
* so they should be allocated slightly higher than the user limits in osconfig.h
*
* Many RTEMS services use tasks internally, including the idle task, BSWP, ATA driver,
* low level console I/O, the shell, TCP/IP network stack, and DHCP (if enabled).
* Many of these also use semaphores for synchronization.
*
* Budgeting for additional:
* 8 internal tasks
* 2 internal timers
* 4 internal queues
* 16 internal semaphores
*
*/
#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 8)
#define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2)
#define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 16)
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 4)
#define CONFIGURE_MAXIMUM_DRIVERS 10
#define CONFIGURE_MAXIMUM_POSIX_KEYS 4
#ifdef OS_RTEMS_4_DEPRECATED
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8)
#else
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8)
#endif

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_FILESYSTEM_RFS
#define CONFIGURE_FILESYSTEM_IMFS
#define CONFIGURE_FILESYSTEM_DOSFS
#define CONFIGURE_FILESYSTEM_DEVFS
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER

#define CONFIGURE_EXECUTIVE_RAM_SIZE (8 * 1024 * 1024)
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 9

#endif
19 changes: 8 additions & 11 deletions src/bsp/pc-rtems/src/bsp_cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,25 @@
/*
** Include Files
*/
/* TODO clean these */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <bsp.h>
#include <rtems.h>
#include <rtems/bdbuf.h>
#include <rtems/blkdev.h>
#include <rtems/diskdevs.h>
#include <rtems/bdpart.h>
#include <rtems/error.h>
#include <rtems/ramdisk.h>
#include <rtems/dosfs.h>
#include <rtems/fsmount.h>

/* TODO remove or refactor? Still needs global */
#include "pcrtems_bsp_internal.h"

/*
* BSP compile-time tuning
*/
#define RTEMS_MAX_USER_OPTIONS 4
#define RTEMS_MAX_CMDLINE 256

void OS_BSP_CmdLine(void)
{
char userargbuffer[RTEMS_MAX_CMDLINE];
const char *cmdlinestr;
const char *cmdp;
char * cmdi, *cmdo;
Expand Down Expand Up @@ -91,7 +88,7 @@ void OS_BSP_CmdLine(void)
{
if (cmdo == NULL)
{
cmdo = OS_BSP_PcRtemsGlobal.UserArgBuffer;
cmdo = userargbuffer;
}
else
{
Expand Down
31 changes: 31 additions & 0 deletions src/bsp/pc-rtems/src/bsp_cmdline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/************************************************************************
* 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.
************************************************************************/

/**
* \file
*
* Purpose:
* Header file for bsp cmdline
*/

#ifndef BSP_CMDLINE_H
#define BSP_CMDLINE_H

void OS_BSP_CmdLine(void);

#endif
123 changes: 5 additions & 118 deletions src/bsp/pc-rtems/src/bsp_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,131 +22,18 @@
* RTEMS main entry point
* Configures RTEMS and wraps OS_BSPMain for use in a stand alone executable
*/

/*
** Include Files
*/
#include "bsp_start.h"
#include "bsp-impl.h"
#include <rtems.h>

#ifdef RTEMS_INCLUDE_TARFS

#include <rtems/untar.h>
/*
** Tar file symbols
*/
extern int _binary_tarfile_start;
extern int _binary_tarfile_size;
#define TARFILE_START _binary_tarfile_start
#define TARFILE_SIZE _binary_tarfile_size

#endif
/* BSP RTEMS configuration, must be in this order */
#include <rtems.h>
#include "bsp_rtems_cfg.h"
#include <rtems/confdefs.h>

/*
** A simple entry point to start from the loader
* A simple entry point to start from the loader
*/
rtems_task Init(rtems_task_argument ignored)
{

#ifdef RTEMS_INCLUDE_TARFS
/*
** Initialize the file system
*/
printf("Populating Root file system from TAR file.\n");
int status = Untar_FromMemory(
(unsigned char *)(&TARFILE_START),
(unsigned long)&TARFILE_SIZE);
if (status != RTEMS_SUCCESSFUL)
{
printf("Error while untaring from memory\n");
}

#endif

OS_BSPMain();
}

/* configuration information */

/*
** RTEMS OS Configuration definitions
*/
#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 (20 * 1024)
#define CONFIGURE_INIT_TASK_PRIORITY 10

/*
* Note that these resources are shared with RTEMS itself (e.g. the init task, the shell)
* so they should be allocated slightly higher than the user limits in osconfig.h
*
* Many RTEMS services use tasks internally, including the idle task, BSWP, ATA driver,
* low level console I/O, the shell, TCP/IP network stack, and DHCP (if enabled).
* Many of these also use semaphores for synchronization.
*
* Budgeting for additional:
* 8 internal tasks
* 2 internal timers
* 4 internal queues
* 16 internal semaphores
*
*/
#define CONFIGURE_MAXIMUM_TASKS (OS_MAX_TASKS + 8)
#define CONFIGURE_MAXIMUM_TIMERS (OS_MAX_TIMERS + 2)
#define CONFIGURE_MAXIMUM_SEMAPHORES (OS_MAX_BIN_SEMAPHORES + OS_MAX_COUNT_SEMAPHORES + OS_MAX_MUTEXES + 16)
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES (OS_MAX_QUEUES + 4)
#define CONFIGURE_MAXIMUM_DRIVERS 10
#define CONFIGURE_MAXIMUM_POSIX_KEYS 4
#ifdef OS_RTEMS_4_DEPRECATED
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8)
#else
#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS (OS_MAX_NUM_OPEN_FILES + 8)
#endif

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_FILESYSTEM_RFS
#define CONFIGURE_FILESYSTEM_IMFS
#define CONFIGURE_FILESYSTEM_DOSFS
#define CONFIGURE_FILESYSTEM_DEVFS
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK

/* TODO figure out how to switch these if needed
#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER */

#define CONFIGURE_EXECUTIVE_RAM_SIZE (8 * 1024 * 1024)
#define CONFIGURE_MICROSECONDS_PER_TICK 10000
#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY 9

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

/* TODO Enablibg the GRETH driver is a platform specific setting. This is supposed to be a "generic" rtems psp. */
#ifdef RTEMS_INCLUDE_TARFS /* TODO Is there a better networking-related define? */

#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

#include <drvmgr/drvmgr_confdefs.h>

#endif
Loading

0 comments on commit 4833980

Please sign in to comment.