本文档是本博主这段时间工作的一个小总结,主要针对RTEMS for BBB BSP 的USB支持。由于要和RTEMS公司进行交流,因此文档大部分使用英文进行撰写。
转载请说明出处。
1. 如何build RSB(RTEMS source builder)
1. 新建文件夹
sandbox="$PWD/sandbox"
mkdir sandbox
cd "$sandbox"
2. 获得RSB
git clone git://git.rtems.org/rtems-source-builder.git
3.检测环境
cd "$sandbox"
cd rtems-source-builder/source-builder
./sb-check
2.配置并安装RSB
cd ../rtems
../source-builder/sb-set-builder --prefix="$sandbox/rtems-4.12" 4.12/rtems-arm
3.如何编译RTEMS
1.获得RTEMS源码
git clone git://git.rtems.org/rtems.git
2.配置和编译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
4. 如何build RTEMS-libbsd
1.获得RTEMS-libbsd源码
git clone git://git.rtems.org/rtems-libbsd.git
2.Update FreeBSD submodule
cd "$sandbox"
cd rtems-libbsd
git submodule update
3.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
5. 如何实现USB support on BBB
1.Import am335x musb driver file from FreeBSD
下面所列的文件就是USB所需的源文件:
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
因此我们需要从FreeBSD-org中import这些文件
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
2.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__ */
6.添加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
7.添加 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)
8.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;
9.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