This post explains how to build an application using RTEMS with lwIP TCP/IP stack. At present lwIP is supported with BBB.

For building the application you need 4 things

1. Build the RTEMS BBB BSP
2. lwIP stack compiled as a static library archive to be linked with the
3. Driver for ethernet controller compatible/ported to lwIP stack compiled as a static library archive to be linked with the application.
4. The application that can use these libraries.

1. Build RTEMS BBB BSP

     We need to build the RTEMS BBB BSP first so that our application can link to it. For use with      lwIP, we need to disable the cache. Networking is working only with cache disabled (Still debugging).

1. Clone the RTEMS master
     git clone https://github.com/RTEMS/rtems.git

2. Disable the cache . Apply this patch to the BSP
     https://raw.githubusercontent.com/ragunath3252/cpsw-lwip/master/BBB-cache-disable.patch

3.  Build rtems-master for beagleboneblack bsp. It will create the necessary libraries we need.
Pls refer to older posts on how to build rtems-master for BBB. We need to give an extra option during configure to tell where to install the built files. So the sequence of steps would be

a. BBB_CACHE_DISABLE=1 ${HOME}/git-rtems/configure  --prefix=${HOME}/sandbox/install --       target=arm-rtems4.11 --enable-rtemsbsp=beagleboneblack
    Prefix can be any folder where you want to install the files. I am giving
    "/home/ragu/development/install"
b. make
c. make install

The prefix option is important because in the future commands we will use this path to specify where the libraries are stored   

2. Building the lwIP stack
The lwIP stack is integrated with RTEMS source builder(RSB). You can clone the RSB and repo & build the lib. The following are the steps

a. Clone the RTEMS source builder repo
     git clone https://github.com/RTEMS/rtems-source-builder.git

b. cd rtems

c. ../source-builder/sb-set-builder --log=logfile --with-tools=compiler-path
    --host=x86_64-linux-gnu 4.11/net/lwip --prefix=bsp-install-path --rtems-bsp=arm/beagleboneblack  --target=arm-rtems4.11

here
--with-tools ---> assign it to RTEMS compiler path
--prefix        ---> Path where corresponding BSP is installed
--host ----> your host info

This will build and install the lib & header files in the path $prefix/$bsp/lwip

For  Example, for the command

../source-builder/sb-set-builder --log=logile --with-tools=/home/ragu/build_tools/rtems/compiler/4.11 --host=x86_64-linux-gnu 4.11/rtems-beagle-lwip --prefix=/home/ragu/build_tools/rtems_latest --rtems-bsp=arm/beagleboneblack --target=arm-rtems4.11

@ragu-ubuntu:~/work/gsoc/lwip/patch/test/rsb-make/rtems-source-builder/rtems$ ls -l /home/ragu/build_tools/rtems_latest/arm-rtems4.11/beagleboneblack/lwip/lib/
total 1796
-rw-r--r-- 1 root root 1641832 Aug 14 18:39 liblwip.a


3. Build driver library

The driver files are not integrated with RTEMS

a. Download the patch from the following link
https://raw.githubusercontent.com/ragunath3252/rtems-rsb-lwip/master/0001-CPSW-lwIP-driver-library-build-files.patch

b. Apply the patch to RTEMS RSB

c.  Execute the following command
../source-builder/sb-set-builder --log=modem --with-tools=/home/ragu/build_tools/rtems/compiler/4.11 --host=x86_64-linux-gnu 4.11/net/cpsw --prefix=/home/ragu/build_tools/rtems_latest --rtems-bsp=arm/beagleboneblack --target=arm-rtems4.11

Change your command as explained for lwip.This will install the driver library & include files in the $prefix/bsp/lwip

For example

ragu@ragu-ubuntu:~/work/gsoc/lwip/lwip-patch/rtems-source-builder$ ls -l /home/ragu/build_tools/rtems_latest/arm-rtems4.11/beagleboneblack/lwip/
total 8
drwxr-xr-x 6 root root 4096 Aug 14 18:41 include
drwxr-xr-x 2 root root 4096 Aug 14 18:41 lib
ragu@ragu-ubuntu:~/work/gsoc/lwip/lwip-patch/rtems-source-builder$ ls -l /home/ragu/build_tools/rtems_latest/arm-rtems4.11/beagleboneblack/lwip/include/
total 72
drwxr-xr-x 2 root root 4096 Aug 14 18:39 arch
-rwxr-xr-x 1 root root 5278 Aug 14 22:31 beaglebone.h
-rwxr-xr-x 1 root root 3170 Aug 14 22:31 cache.h
drwxr-xr-x 2 root root 4096 Aug 14 18:39 lwip
-rw-r--r-- 1 root root 1066 Aug 14 22:31 lwip_bbb.h
-rwxr-xr-x 1 root root 9090 Aug 14 22:31 lwiplib.h
-rw-r--r-- 1 root root 7843 Aug 14 18:39 lwipopts.h
-rwxr-xr-x 1 root root 7325 Aug 14 22:31 mmu.h
drwxr-xr-x 3 root root 4096 Aug 14 18:39 netif
drwxr-xr-x 3 root root 4096 Aug 14 18:39 posix
-rwxr-xr-x 1 root root 9848 Aug 14 22:31 soc_AM335x.h
ragu@ragu-ubuntu:~/work/gsoc/lwip/lwip-patch/rtems-source-builder$ ls -l /home/ragu/build_tools/rtems_latest/arm-rtems4.11/beagleboneblack/lwip/lib/
total 1796
-rw-r--r-- 1 root root 1641832 Aug 14 18:39 liblwip.a

-rw-r--r-- 1 root root  194594 Aug 14 22:31 liblwipdrv.a

4. Build the application
a. Clone the repo
    git clone https://github.com/ragunath3252/lwip-app.git

b. export RTEMS_MAKEFILE_PATH=path-to-your-installed-bsp-directory
     We need to set this variable so that the app can see where the libraries and header files are installed.

c. make

d. It will create the lwip.exe in o-optimize/lwip.exe

e. This is a elf executable. You can use this to boot your BBB

Now this app is configured to use DHCP. So it will get an ip address using DHCP and stops.
You can ping to the ip address and see the response.









In this post I will explain the necessary steps needed to port a ethernet driver from FreeBSD to rtems-libbsd.  There are few changes we need to make to be able to compile the driver.

I will be using cpsw ethernet driver for BBB as reference.  Follow the below steps
Whenever we edit a header file or c file, we need to add the changes under #if defined  __rtems__.
The code on FreeBSD needs to go under the #else part.

STEPS


1. Copy the driver files from FreeBSD to appropriate destination in rtems-libbsd
     I copied it to "freebsd/sys/arm/ti/cpsw"

2.  Include the added files in Makefile
     "LIB_C_FILES += freebsd/sys/arm/ti/cpsw/if_cpsw.c"

3.  Add the following header file for any c file you are including
     "#include <machine/rtems-bsd-kernel-space.h>"

4. At this stage, your driver is included for compilation. start compilation
    "make clean && make"

5. You will get several errors. You will need to resolve the errors one by one. The errors that come
     are dependent on the driver. I will explain some of the common errors.

Common Issues

     a.   Sysctl
          The FreeBSD driver usually add sysctls to get stats and adjust variables.  RTEMS do not
          support these. We need to remove all functions and variables related to sysctl handling.

     b.  OFW/FDT
          Open Firmware(OFW)/ Flattened Device Tree (FDT) dependency. FreeBSD supports FDT
          involves supplying device tree information during boot time using a special configuration file.
          RTEMS do not have this support yet, we need to remove those dependencies. Commonly they
          are seen in probe and attach functions

     c. In attach functions, we may get the phy address from FDT. This phy address is used during
         mii_attach. We can give MII_PHY_ANY in mii_attach. It will loop through all the possible
         addresses and will find the correct phy.

     4. There may some other dependencies on other drivers or some other modules which is defined
          FreeBSD but not needed in RTEMS. You can define equivalent functions as per the
          requirement. I defined my own functions to read the mac address.

Simplebus vs nexus

         RTEMS has a well defined nexus bus support. It will be the one that will be attaching to root and other drivers will be attaching to this bus. Simplebus interface is not present in RTEMS. Simplebus is usually the bus related to OFW interface. So when we have to port a driver based on simplebus we have two options

1. Port simplebus interface to rtems-libbsd
2. Modify the driver to nexus bus

I took the option to modify the bus to use the nexus bus.  For this you need to make the following changes

1. In the DRIVER_MODULE definition, we use nexus instead of simplebus
     
    #ifndef __rtems__
    DRIVER_MODULE(cpsw, simplebus, cpsw_driver, cpsw_devclass, 0, 0);
    #else  
    DRIVER_MODULE(cpsw, nexus, cpsw_driver, cpsw_devclass, 0, 0);
    #endif

2. Next thing we need to define the resource structure which will inform the driver the base address
     to be used for bus handles and irq to be used for the device. The resource should have the  
     following details the memory map address and the  irq and their numbers to be used by the 
     driver. Cpsw driver starts at 0x4a100000 and have 4 irq's starting at 40.
     

    #elif defined(LIBBSP_ARM_BEAGLE_BSP_H)

     static const rtems_bsd_device_resource cpsw0_res[] = {
        {
                .type = RTEMS_BSD_RES_MEMORY,
                .start_request = 0,
                .start_actual = 0x4a100000 /*Memory map address of the ethernet*/
        }, {
                .type = RTEMS_BSD_RES_IRQ,
                .start_request = 0,
                .start_actual = 0x28
        },
           {
                .type = RTEMS_BSD_RES_IRQ,
                .start_request = 1,
                .start_actual = 0x29
        },
           {
                .type = RTEMS_BSD_RES_IRQ,
                .start_request = 2,
                .start_actual = 0x2a
        },
           {
                .type = RTEMS_BSD_RES_IRQ,
                .start_request = 3,
                .start_actual = 0x2b
        }
};

3. Define the following macro below the resource structure
     RTEMS_BSD_DEFINE_NEXUS_DEVICE(cpsw, 0, RTEMS_ARRAY_SIZE(cpsw0_res),
    &cpsw0_res[0]);
     This is needed because, we use SYSINIT feature of FreeBSD. With this definition, we will be 
      automatically loaded during boot time. For more details see libbsd.txt file.

With these changes we moved to nexus bus. 

4. You may need to port the phy driver also from FreeBSD. For me I needed smscphy. So I added smscphy.c to rtems-libbsd and included it in compilation.

5. We need to make sure  the phy device get attached to miibus. for this we define 
     SYSINIT_DRIVER_REFERENCE(smscphy, miibus) in the same nexus device file.

With this we should be able to form a proper device tree.

LOG

Below is the log I got. Ignore the Failed to read PHY messages. Since we gave MII_PHY_ANY during attach, it tries different address so we getting failed messages

## Transferring control to RTEMS (at address 80000000) ...

RTEMS Beagleboard: am335x-based
*** LIBBSD INIT 1 TEST ***

RTEMS Shell on /dev/console. Use 'help' to list commands.
[/] # nexus0: <RTEMS Nexus device>
cpsw0: <3-port Switch Ethernet Subsystem> on nexus0
00:00:00 cpsw_attach
cpsw0: device parent is present
cpsw0: CPSW SS Version 1.12 (0)
cpsw0: Initial queue size TX=128 RX=384
cpsw0: MAC HI ce04a578
cpsw0: MAC Low f531
devctl: !system=IFNET subsystem=cpsw0 type=ATTACH
cpsw0: Ethernet address: -2144597976
cpsw0: Failed to read from PHY.
cpsw0: Failed to read from PHY.
cpsw0: Failed to read from PHY.
cpsw0: Failed to read from PHY.
cpsw0: Failed to read from PHY.
cpsw0: Failed to read from PHY.

miibus0: <MII bus> on cpsw0
smscphy0: <SMC LAN8710A 10/100 interface> PHY 0 on miibus0
smscphy0:  10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
devctl: +smscphy0 at phyno=0 oui=0x800f model=0xf rev=0x1 on miibus0
devctl: +miibus0 at   on cpsw0
devctl: +cpsw0 at   on nexus0
devctl: +nexus0 at   on root0
devctl: !system=IFNET subsystem=lo0 type=ATTACH


IRQ defined can be seen using irq command

[/] #  irq
-------------------------------------------------------------------------------
                             INTERRUPT INFORMATION
--------+----------------------------------+---------+------------+------------
 VECTOR | INFO                             | OPTIONS | HANDLER    | ARGUMENT
--------+----------------------------------+---------+------------+------------
     40 | cpsw0                            |  UNIQUE | 0x800d8788 | 0x802c5428
     41 | cpsw0                            |  UNIQUE | 0x800d8788 | 0x802c5460
     43 | cpsw0                            |  UNIQUE | 0x800d8788 | 0x802c5498
     67 | Clock                             |  UNIQUE | 0x800d7684 | 0x00000000
     72 | NS16550                       |  SHARED | 0x800d945c | 0x00000000
--------+----------------------------------+---------+------------+------------



     
In this post I will explain how to build rtems-libbsd for BeagleBoneBlack(BBB).

STEP 1:
Build rtems-master for beagleboneblack bsp. It will create the necessary libraries we need.
Pls refer to older posts on how to build rtems-master for BBB. We need to give an extra option during configure to tell where to install the built files. So the sequence of steps would be

1. ${HOME}/git-rtems/configure  --prefix=${HOME}/sandbox/install --target=arm-rtems4.11
        --enable-rtemsbsp=beagleboneblack
    Prefix can be any folder where you want to install the files. I am giving
    "/home/ragu/development/install"
2. make
3. make install

STEP 2:
1. Clone the rtems-libbsd repo
    https://github.com/RTEMS/rtems-libbsd
2.  Edit the config.inc file
     
# Mandatory: Select your BSP and installation prefix
TARGET = arm-rtems4.11
BSP = beagleboneblack
PREFIX = /home/ragu/development/install (The one we gave during rtems-master build)

# Optional: Separate installation base directory
INSTALL_BASE = $(PREFIX)/$(TARGET)/$(BSP)

# Optional: Network test configuration
TEST_RUNNER = $(BSP)
NET_CFG_SELF_IP = 10.117.83.42
NET_CFG_NETMASK = 255.255.255.0
NET_CFG_PEER_IP = 10.117.83.2
NET_CFG_GATEWAY_IP = 10.117.83.2
NET_TAP_INTERFACE = tap0

3. make clean

4. make

The built libraries can be found at testsuite directory.

RTEMS has a well defined networking support. In this post, I will give a overview of the networking in RTEMS and relevance to GSoC 2015

RTEMS users have two options for networking

1. libnetworking present in the RTEMS master
2.  libbsd based on FreeBSD network stack

Native Libnetworking:


           RTEMS master supports networking using libnetworking library. It can be enabled by "--enable-networking=yes" during configure. There are few config structures we need to define which will enable the network interface. More details are available in the RTEMS network supplement document

rtems-libbsd:


           RTEMS also supports a port of FreeBSD network stack known as "rtems-libbsd". It contains network stack based on FreeBSD 9.3. Applications use rtems base libraries and libbsd network stack.
It is present on a separate repo though it depends on rtems-master for bsp specific code. We can build applications by cloning this repo rtems-libbsd git 

How it works:

1. First we need to build rtems master to get the base libraries.
2. Then we need to install the built files in a directory which is used later. Required files and libraries      like librtemsbsp.a, librtemscpu.a etc are copied
3. We mention this path to rtems-libbsd 
4. Building rtems-libbsd will produce a libbsd.a that contains the object files of the network stack
5. Then applications are built using these libraries which can be found in testsuite directory

With this setup, there is no need to develop new drivers. We can easily port the drivers from FreeBSD. 

More details about rtems-libbsd can be obtained from libbsd.txt
GSoC 2015 Updates. In this post I will  keep updating the latest posts I make during the GSoC program.

1. About GSoC 2015, RTEMS, BBB

2. Project overview

3.  RTEMS Networking

4.  Rtems libbsd for Beaglebone Black

For GSoC 2015, I will be working to improve the Beagle BSP support in RTEMS. 

RTEMS Beagle BSP current scenario:

 RTEMS has a BSP that supports beagleboard, beagleboard xm, beaglebone (original, white) and beaglebone black targets.  Basic starup code, drivers  are up. We can boot almost all of the sample tests. During proposal time, I tested quite a few tests and all ran successfully. So basic support is up and running thanks to Ben Gras @ http://www.shrike-systems.com/ . He is the one who did the bringup of the board. He is also a mentor for this project. 

Building and Testing:


                     Pls follow the article from build steps. With the help of this article, we can build the rtems image and boot it. 

1. RTEMS has a good arm compiler which can be used for our project
2. RTEMS mainline has the beagle bsp. So we can easily build our bsp from this
3. Ben's repo has qemu tools which can be used to run beagleboard-xm images.
4. The repo also has tools to build MLO, uboot images
5. It also has a script that can program rtems image to a SD card so that we can boot from it


Drivers needed:

                    
                      RTEMS BSP have rudimentary hardware support. It does not have the following peripheral support

1. Networking
2. I2c
3. GPIO
4. USB
5. MMC

Work Items:


                     I will be adding networking support to beagle BSP in this project. I also will be adding lwIP to rtems package collection. Based on the time availability, I also will be adding some other driver. There is also another selected for the same project. So we will be working paralelly adding needed drivers. During the initial phase, I will be working on adding networking support to RTEMS.




I followed http://wiki.osdev.org/ARM_Beagleboard to create a simple startup program for my beaglebone. In that tutorial, we copy the file to a address using tftp and use "go" command to transfer the control.

But, normally we use a uboot compatible format to boot the images using "bootm" command. To make our image in this format, we use "mkimage" command. You need to download uboot source and build this mkimage

The command we are going to use is

mkimage -A arm -O myARM -T kernel -C none -a 0x80200000 -e 0x80200040 -n kernel -d boot.bin os_uImage

-A -- architecture type

-O -- os type

-T -- type of image

-C -- compression used

-a -- load address

-e -- entry point

-d -- data file to be booted

os_uImage -- resultant uboot compatible image

To boot the image follow the following commands


U-Boot# setenv ipaddr 10.117.83.43
U-Boot# setenv serverip 10.117.83.34
U-Boot# tftp 0x80200000 os_uImage
link up on port 0, speed 100, full duplex
Using cpsw device
TFTP from server 10.117.83.34; our IP address is 10.117.83.43
Filename 'os_uImage'.
Load address: 0x80200000
Loading: #
         44.9 KiB/s
done
Bytes transferred = 92 (5c hex)
U-Boot# bootm
## Booting kernel from Legacy Image at 80200000 ...
   Image Name:   kernel
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    28 Bytes = 28 Bytes
   Load Address: 80200000
   Entry Point:  80200040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK

Starting kernel ...

@@@



I made the image to hang so that we can see the output.

The advantage is we can specify image name and we can do compression on our command. If we use go command it needs to be raw data file. By using bootm command we can use all the facilities provided by uboot.

Initially, my tries failed because I gave load address and entry point to be the same. Then I changed the entry point to load_addr+ 0x40 and boot succeeded.
 This is just a trial and error since the my data file started at that address in the resulting uImage. 0x40 bytes for uboot header I guess. I must check this and confirm if it is okay.
In this post, I will explain how to setup beaglebone black to boot from tftp. This  saves us time in programming the SDcard every time we need to change the image. For baremetal programming, we may need to change the image frequently and this method will be of real help. For this method you need serial console access.

I found a very good article on the same topic in the following website
http://wiki.beyondlogic.org/index.php/BeagleBoneBlack_Building_Kernel
This article provides some extra points.

1. How to compile latest mainline kernel for beaglebone black
2. NFS root issues while booting

All the steps mentioned are for UBUNTU. Seriously, your life will be easier , if you use ubuntu.

This is what we are going to do

1. Build an image
2. start tftp server
3. Stop in uboot prompt.
4. Set up environment variables
5. Use NFS file system for ramdisk

BUILD THE IMAGE:
               In many of the articles available in the net, they will ask you to use a arch linux based kernel. We need to download it , compile and boot it. But we need the latest linux kernel and not a distro. This is important beacuse, we need the mainline kernel which has all the latest changes to the linux kernel. Secondly, if you want to  learn Linux system/driver programming it is always better to have the latest version. For instance, the kernel mentioned in beagleboard website, the version is 3.12. The  latest version as i write this blog is 3.18.

1. Download the latest kernel from kernel.org and unzip it.
https://www.kernel.org/

2. We are going to use a cross compiler to compile our image. I am using ubuntu 14.04LTS OS. You need to install arm-linux-gnueabi tools for cross compilation.
apt-get utility can help you.

3. After installing we are ready for compilation.
    We need to use a default config file. For this use, arch/arm/configs/omap2plus_defconfig

4. compilation steps
    
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-  omap2plus_defconfig -j4
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage dtbs LOADADDR=0x80008000 -j4
 
5. For setting up the tftp server and nfs root follow the link 
provided.

6. While setting up the server, you need to give dhcp command 
in uboot prompt. It will tell you an available ip address.
 
7. You need to mention this in your /etc/exports file in the 
following format. Otherwise, nfs mount will fail
/home/ragu/work/linux/busybox/src/busybox-1.21.0/arm_install/ 10.117.83.172(rw,sync,no_root_squash,no_subtree_check)
/home/ragu/work/linux/busybox/src/busybox-1.21.0/arm_install/ 10.117.83.175(rw,sync,no_root_squash,no_subtree_check) 

Follow the instructions mentioned in the reference article for
booting.

We use busybox for ramdisk. Thats all i wanted and it is good enough for me.



 

  


Hi . In this post I will explain how to get started with beaglebone black.

Beaglebone black is a dev board from Texas Instruments. It consists of

1. ARM processor
2. Ethernet Port
3. USB port
4. External 5V power supply
5. USB to Serial ports
6. USB console
7. Inbuilt storage of 4GB
8. External sdMMC storage support

This is mainly aimed at those who, want to do some baremetal programming with beaglebone black.

Out of the support:
1. It will have the board.
2. A linux distro image is written to internal storage and you will be able to boot from it
3. A USB console.

You can connect the USB console to your system and start working with it at the go. For Linux, you need to set some udev rules and you are good to go. For windows, you need to install some drivers. They can be found here
http://beagleboard.org/getting-started

A network interface is created for the usb console and you can ssh to it.
This is sufficient for baremetal programming

For baremetal programming, we need

1. A serial console so that we can see what is going on while booting
2. Access to uboot prompt so that we can change images frequently

For this buy a USB to serial 4 pin connector. I found this in eBay and has to come from Trivandrum. It took 25 days for me to get one. So better to order at the earliest
http://www.ebay.in/itm/USB-To-RS232-TTL-UART-PL2303HX-Auto-Converter-USB-to-COM-Cable-Adapter-Module-/261685009055?pt=LH_DefaultDomain_203&hash=item3ceda45a9f

Drivers are already present in ubuntu. It works seemlessly and very good.

This solves our problem of serial console. In the next blog, I will explain how to boot beaglebone from tftp server and nfs root.


OPENRISC toolchain for FreeBSD

Exact steps.

1. Download gcc and other utils  zip files from openrisc git page

2. Unzip the scr file. It has binutils and other required files

3. run configure
./configure --target=$TARGET --prefix=$PREFIX --with-sysroot --enable-maintainermode --enable-shared --enable-ld

4. configure will succeed. Then run make command

5.
the make failed ld
 
10. adding the option to ld
 
added this, line ld/configure.tgt
or1k-*-freebsd* | or1knd-*-freebsd*)        targ_emul=elf32or1k ;;

other bsd targets had _fbsd extension. It throwed some error when configured like that.
so leaving as elf as used by rtems. need to revisit
 
6. Next gdb compilation will fail , because -lsim is not added.
    Added it in the gdb/Makefile after -ls lm. It succeeded
 
7. rda compilation failed. You need to compile rda in or1k-freebsd* directory. Otherwise it will fail
You may need to maunually edit acinclude.m4 file for correct path 
   It will say gcc cannot compile binaries. ZTo fix you need to manualyy compile 
rda. for this go rda directorr

./configure -- target=$TARGET --prefix=$PREFIX

it may fail at some libtool version mismatch error (LT__INIT). To fix this you follow

http://www.howtodoityourself.org/how-to-fix-libtool-version-mismatch-error.html

after this make and make install
 
 

8.  this makes binutils and complete
 
9/ Now compile GCC
 
gcc we need to edit gcc/config.gcc and libgcc/config.host and add the corresponding entries
 
10. after that there is in libatomic library. I removed its compilation --disable-libatomic
 
11. after compilation succeeded
 
12. make install installed file 



I am writing this blog for my own reference. I am novice to open source development and this is a learning process for me. My documentation   may be wrong/stupid/complete BS. If u find any mistakes, pls post it. I will correct it.
I dont know whether I will complete this or not. Lets see.....


Found this  project on Freebsd ideas page.  This involves porting Freebsd to openrisc platform. First step is to build toolchain for Freebsd.

This document explains how to add a new OS to GNU toolchain
http://wiki.osdev.org/OS_Specific_Toolchain#Binutils

This page contains details on OPENRISC toolchain building steps
http://openrisc.net/toolchain-build.html

Building Binutils:
             I got the source from github and started building binutils which is the first step

1. No need to edit config.sub since Freebsd is already added

2. Next bfd/config.bfd says there is no support for this TARGET
    So I edited the file and added the following lines after or1k-linux

or1k-*-elf | or1k-*-freebsd*)
    targ_defvec=bfd_elf32_or1k_vec
    ;;

  or1knd-*-elf | or1knd-*-freebsd*)
    targ_defvec=bfd_elf32_or1k_vec
    ;;

3. ran configure and got the error that some file in doc folder (binutils.tex)is missing
    found the solution to run with "--enable-maintainer-mode" option in configure script

4. configure succeeded

5. Now running make command

6. make failed with following error
configure.in:21: error: Please use exactly Autoconf 2.64 instead of 2.69.
../config/override.m4:12: _GCC_AUTOCONF_VERSION_CHECK is expanded from...
configure.in:21: the top level

to fix this i edited override.m4 file and change version 2.64 to 2.69
 
7. struck at Makefile.am (bfdver.h): Substitute report_bugs_to.  Also
 create doc/bfdver.texi. in make
 
apparently there is rule to create this file in Makefile.am. Unfortunately it is not run.
 
8. found that it is enough to run configure script in the src directory directly.
 
9. ran ./configure --target=or1k-freebsd
it completed
the make failed ld
 
10. adding the option to ld
 
added this, line ld/configure.tgt
or1k-*-freebsd* | or1knd-*-freebsd*)        targ_emul=elf32or1k ;;

other bsd targets had _fbsd extension. It throwed some error when configured like that.
so leaving as elf as used by rtems. need to revisit
 
 
11. ld compiled and faced error with libiberty apparrently lacking -fPIC flag.
 
Error is relocation R_X86_64_32S against `ro_data' can not be used when making a 
shared object; recompile with -fPIC
 
to fix this I manually added -fPIC to PICFLAG if libiberty/Makefile.
libiberty is newly created in pic directory
 
after this I manually executed "make command" that  created the binaries

12. Then running make, continued for some time

13 Now struck at 

relocation R_X86_64_32S against `_sch_istable' 
can not be used when making a shared object; recompile with -fPIC
 
Its 1 AM in the night. I will carry on tomo 
 
14. I recompiled with -fPIC. Added it in the makefile.am
 
15. After that struck at, or1ksim.h not found. Apparently you need to build the simulator 
library (-lsim) before building toolchain. I did not do this. If you compile or1ksim,
you will get this file and -lsim library. 
 
source is found at https://github.com/openrisc/or1ksim 
 
16. after building or1ksim, build succeeded. But it is not linked properly and got undefined
      reference errors  (or1ksim_init). to fix this I added the installed library path to 
     makefile. Make clean is needed. Lets see hwo it goes
 
17. You need to install or1ksim in this specific directory otherwise gdb compilation failed
     "/opt/or1ksim". this can be done when u give configure just add the prefix to 
      this directory
 
18. After this too gdb failed. Apparently because -lsim is not included.
    To fix this, I edit the make file to include -lsim later 
 
19. After this compiling rda directory failed saying c compiler not working. This seems
to be because it expects gcc for freebsd already exists. I copied the rda directory to 
or1k-freebsd directory and ran the following commands
 
cd or1k-freebsd/rda/
 1584  ./configure --prefix=$PREFIX --target=$TARGET
 1585  make
 1586  make install
 
20. after this make succeeded
 
21. make install installed binaries on the path specified by PREFIX
 
next step is to compile GCC 
 
GCC compilation steps
 
1. Follow the osdev wiki on adding new target os to add the required platform
in specific files. ex, edit gcc/config.gcc and libgcc/config.guess and add your platform
 
2. Apparently you need to give freebsd9 or freebsd10 while mentioning target because this 
is must or else build will fail complaining that "FBSD_MAJOR" is not define
 
3. It is better to follow linux implementation and add whatever is needed
 
4. Now it says SYSROOT directory is not present
I mkdir the directory, after this build proceeded.
 
5. Now it says freebsd-unwind.h is not present 
   This error came because I added "md_unwind_header" to or1k-freebsd target.
   This is not needed and default "no-unwind.h" will be used
 
6. Now fatal error: sys/_types.h: No such file or directory
 error is seen