RTEMS USB support for BBB document

RTEMS-libbsd USB Support For BBB


How to build RSB

Create new folder

sandbox="$PWD/sandbox"
mkdir sandbox
cd "$sandbox"

Get RSB source code

git clone git://git.rtems.org/rtems-source-builder.git

Check the environment

cd "$sandbox"
cd rtems-source-builder/source-builder
./sb-check

Configure and build RSB

cd ../rtems
../source-builder/sb-set-builder --prefix="$sandbox/rtems-4.12" 4.12/rtems-arm



How to build RTEMS

Get RTEMS source code

git clone git://git.rtems.org/rtems.git

Configure and build RTEMS for BBB BSP

cd "$sandbox"
cd rtems
PATH="$sandbox/rtems-4.12/bin:$PATH" ./bootstrap; ./bootstrap -p

cd "$sandbox"
mkdir BBB_install
cd BBB_install
PATH="$sandbox/rtems-4.12/bin:$PATH" "$sandbox/rtems/configure" \
  --target=arm-rtems4.12 --prefix="$sandbox/rtems-4.12" \
  --disable-networking --enable-rtemsbsp=beagleboneblack
PATH="$sandbox/rtems-4.12/bin:$PATH" make
PATH="$sandbox/rtems-4.12/bin:$PATH" make install





How to build RTEMS-libbsd

Get RTEMS-libbsd source code

git clone git://git.rtems.org/rtems-libbsd.git

Update FreeBSD submodule

cd "$sandbox"
cd rtems-libbsd
git submodule update

Configure and bulid libbsd for BBB BSP

git submodule init
git submodule update rtems_waf
waf configure --prefix="$sandbox/rtems-4.12" --rtems-bsps=arm/beagleboneblack
waf
waf install


How to Add USB support on Beaglebone Black

Import am335x musb driver file from FreeBSD

The musb driver files we need is show as below:
am335x_musb.c
am335x_prcm.c
am335x_usbss.c
ti_prcm.c
ti_scm.c
musb_otg.c
am335x_scm.h
ti_cpuid.h
ti_prcm.h
ti_scm.h
tivar.h
musb_otg.h

So we need import these file from FreeBSD-org

Add following code in libbsd.py

#
# BBB USB
#
def dev_usb_controller_bbb(mm):
    mod = builder.Module('dev_usb_controller_bbb')
    mod.addDependency(mm['dev_usb'])
    mod.addKernelSpaceHeaderFiles(
        [
            'sys/arm/ti/ti_cpuid.h',
            'sys/arm/ti/ti_prcm.h',
            'sys/arm/ti/ti_scm.h',
            'sys/arm/ti/tivar.h',
            'sys/arm/ti/am335x/am335x_scm.h',
            'sys/dev/usb/controller/musb_otg.h',
        ]
    )
    mod.addKernelSpaceSourceFiles(
        [
            'sys/arm/ti/ti_scm.c',
            'sys/arm/ti/am335x/am335x_prcm.c',
            'sys/arm/ti/am335x/am335x_usbss.c',
            'sys/arm/ti/ti_prcm.c',
            'sys/arm/ti/am335x/am335x_musb.c',
            'sys/dev/usb/controller/musb_otg.c',
        ],
        mm.generator['source']()
    )
    return mod
Add following code in sources(mm) part of libbsd.py

mm.addModule(dev_usb_controller_bbb(mm))


These code add an module in libbsd. Then using freebsd-to-rtems.py script to import files

./freebsd-to-rtems.py -R && ./freebsd-to-rtemsd.py

Port am335x musb driver file to libbsd

We need modify some files to adapt to libbsd

1.am335x_prcm.c

#ifndef __rtems__
#include <sys/timeet.h>
#endif /* __rtems__ */
#include <sys/timetc.h>
#ifndef __rtems__
#include <sys/watchdog.h>
#endif /* __rtems__ */
#include <machine/bus.h>
#include <machine/cpu.h>
#ifndef __rtems__
#include <machine/intr.h>
#endif /* __rtems__ */



am335x_prcm_sc = sc;
#ifndef __rtems__
ti_cpu_reset = am335x_prcm_reset;
#endif /* __rtems__ */

if (am335x_clk_get_sysclk_freq(NULL, &sysclk) != 0)


2.ti_cpuid.h

#ifdef __rtems__
#include <bsp.h>
#endif /* __rtems__ */

#define CHIP_OMAP_4 0
#define CHIP_AM335X 1

#ifdef __rtems__
#ifdef IS_AM335X
#define SOC_TI_AM335X
#else
#warning Unknown SOC.
#endif

#if defined(SOC_TI_AM335X)
#define _ti_chip CHIP_AM335X
#elif defined(SOC_OMAP4)
#define _ti_chip CHIP_OMAP_4
#else
#define _ti_chip -1
#endif
#else /* __rtems__ */
extern int _ti_chip;
#endif /* __rtems__ */


3.ti_prcm.c

#include <machine/bus.h>
#include <machine/resource.h>
#ifndef __rtems__
#include <machine/intr.h>
#endif /* __rtems__ */

#include <arm/ti/ti_cpuid.h>
#include <arm/ti/ti_prcm.h>


4.ti_scm.c

#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#ifndef __rtems__
#include <dev/fdt/fdt_pinctrl.h>
#endif /* __rtems__ */

Add FDT support for am335x USB driver in RTEMS

RTEMS need get device information from U-Boot via FDT. So we need add FDT support on RTEMS for BBB BSP. The following files need to be modified

1.beagle/configure.ac

RTEMS_BSPOPTS_SET([BSP_START_COPY_FDT_FROM_U_BOOT],[beaglebone*],[1])
RTEMS_BSPOPTS_HELP([BSP_START_COPY_FDT_FROM_U_BOOT],[enables U-Boot support using FDT])

RTEMS_BSPOPTS_SET([BSP_FDT_BLOB_SIZE_MAX],[beaglebone*],[262144])
RTEMS_BSPOPTS_HELP([BSP_FDT_BLOB_SIZE_MAX],[maximum size of the FDT blob in bytes])

RTEMS_BSPOPTS_SET([BSP_FDT_BLOB_READ_ONLY],[beaglebone*],[1])
RTEMS_BSPOPTS_HELP([BSP_FDT_BLOB_READ_ONLY],[place the FDT blob into the read-only data area]

2.beagle/include/bsp.h

#if BSP_START_COPY_FDT_FROM_U_BOOT
#define BSP_FDT_IS_SUPPORTED
#endif

3.beagle/startup/bspstart.c

uint32_t bsp_fdt_map_intr(uint32_t intr)
{
  return intr;
}

4.arm/shared/start/start.S

#ifdef BSP_START_COPY_FDT_FROM_U_BOOT
mov r0, r6
bl bsp_fdt_copy
#endif

Add FDT support for am335x USB driver in RTEMS-libbsd

We need add FDT support to get device information from U-Boot via FDT. So We need modify nexus-devices.h

nexus-devices.h

#elif defined(LIBBSP_ARM_BEAGLE_BSP_H)

#include <bsp/irq.h>

RTEMS_BSD_DEFINE_NEXUS_DEVICE(ofwbus, 0, 0, NULL);
SYSINIT_DRIVER_REFERENCE(simplebus, ofwbus);
SYSINIT_DRIVER_REFERENCE(ti_scm, simplebus);
SYSINIT_DRIVER_REFERENCE(am335x_prcm, simplebus);
SYSINIT_DRIVER_REFERENCE(usbss, simplebus);
SYSINIT_DRIVER_REFERENCE(musbotg, usbss);

RTEMS_BSD_DRIVER_USB;

#elif defined(LIBBSP_ARM_LPC32XX_BSP_H)




How to add USB mass support

We need add umass code to support USB storage device such as USB disks. the umass.c is already ported to libbsd. So we need add the device reference in nexus-devices.h

nexus-devices.h

RTEMS_BSD_DRIVER_USB;
RTEMS_BSD_DRIVER_USB_MASS;




Compiling and Testing

Compile the RTEMS modified code via the following ccommand

cd "$sandbox"
cd rtems
PATH="$sandbox/rtems-4.12/bin:$PATH" ./bootstrap; ./bootstrap -p
PATH="$sandbox/rtems-4.12/bin:$PATH" make
PATH="$sandbox/rtems-4.12/bin:$PATH" make install

Compile the libbsd modified code via "waf". Then using "waf install"
The generated media01.exe which in the build folder can be used to testing.
We can test the USB via USB disk, USB hub, USB keyboard and USB dongle, etc.

评论

此博客中的热门博文

RTEMS Network Transplantation - rtems system initialization process analysis

Work Product Submission