# xRAN (FHI Library) Setup
###### tags: `ORAN`
---
###### tags: `CHT Technical Document`
:::success
**Outline:**
[TOC]
:::
## Background
:::info
- This guide will tell you how to clone the required FHI library needed for L1app in radio mode
- This will also tell you on how to setup the environment required for l1app
:::
## Clone
### phy folder
:::info
- phy folder contains FAPI, WLS, and FHI library
:::
```shell=
$ git clone "https://gerrit.o-ran-sc.org/r/o-du/phy"
```
### l1app
:::info
Download l1app
- l1app binary is a large file, if you `git clone` the FlexRAN l1app without installing **Git-LFS(Git-Large File Storage)**, the binary will be empty. Anyway, you need to install `Git-LFS` before you `git clone` it.
:::
:::success
#### 1. Download the Git-LFS
```shell=
$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
```
#### 2. Install Git-LFS
```shell=
$ sudo yum install git-lfs
```
#### 3. Set up Git LFS for your user account by running:
```shell=
$ git lfs install
```
>You will see the result same as the figure below if successful

#### 4. Download l1app
```shell=
$ git clone https://github.com/intel/FlexRAN.git
```
:::
## Set up the environment
:::info
- Remember to modify the path according to your own directory, this environtment is used in all O-DU-PHY installation.
- Make sure to use absolute path in the shell file
- make sure all variables are on yout setupenv.sh (an example is there below)
**- Important parameter to double check**
| Parameter | Filled with | Example |
| ----------------------- | ------------------------------------ | ----------------------------- |
| DIR_ROOT_L1_BIN | your FlexRAN folder path | /home/osc/FlexRAN |
| DIR_ROOT_PHY | your phy folder path | /home/osc/phy |
| DIR_ROOT_DPDK | your dpdk installation folder path | /home/osc/dpdk-stable-20.11.3 |
| DIR_ROOT_GTEST | your google test installation folder | /home/osc/gtest-1.7.0 |
| WIRELESS_SDK_TARGET_ISA | avx512 | avx512 |
:::
### 1. Set the environment variable
```shell=
## Edit the file and change the environtment variable to your own directory
$ sudo vim <Your_Directory>/phy/setupenv.sh
## Run the script
$ source <Your_Directory>/phy/setupenv.sh
```
:::spoiler setupenv.sh
```
#!/bin/bash
export HOME=/home/oran
export DIR_ROOT=$HOME/F_O-DU
#set the L1 binary root DIR
export DIR_ROOT_L1_BIN=$DIR_ROOT/FlexRAN
#set the phy root DIR
export DIR_ROOT_PHY=$DIR_ROOT/phy
#set the DPDK root DIR
export DIR_ROOT_DPDK=/$HOME/DPDK/dpdk-stable-20.11.3
#set the GTEST root DIR
export DIR_ROOT_GTEST=/home/oran/google_test/gtest-1.7.0
export WIRELESS_SDK_TARGET_ISA=avx512
export DIR_WIRELESS_TEST_5G=$DIR_ROOT_L1_BIN/testcase
export DIR_WIRELESS_SDK=$DIR_ROOT_L1_BIN/sdk/build-avx512-icc
export DIR_WIRELESS_TABLE_5G=$DIR_ROOT_L1_BIN/l1/bin/nr5g/gnb/l1/table
#source /opt/intel/system_studio_2019/bin/iccvars.sh intel64 -platform linux
export XRAN_DIR=$DIR_ROOT_PHY/fhi_lib
export XRAN_LIB_SO=true
export RTE_TARGET=x86_64-native-linuxapp-icx
export RTE_SDK=$DIR_ROOT_DPDK
#Uncomment, commented to build DPDK
#export DESTDIR=$DIR_ROOT_DPDK
#Uncomment to run tests - it's commented to make builds faster.
export GTEST_ROOT=$DIR_ROOT_GTEST
export ORAN_5G_FAPI=true
export DIR_WIRELESS_WLS=$DIR_ROOT_PHY/wls_lib
export DEBUG_MODE=true
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DIR_WIRELESS_WLS:$XRAN_DIR/lib/build
export DIR_WIRELESS=$DIR_ROOT_L1_BIN
export DIR_WIRELESS_ORAN_5G_FAPI=$DIR_ROOT_PHY/fapi_5g
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DIR_ROOT_L1_BIN/libs/cpa/bin:/opt/intel/oneapi/mkl/2022.1.0/lib/intel64:/home/oran/DPDK/dpdk-stable-20.11.3/build/lib
```
:::
### 2. Append the command into .bashrc file
Whenever you start a session, it will run the all commands in `.bashrc` file automatically.
```shell=
## Edit the .bashrc file
$ vim ~/.bashrc
## Append the command below into the file
source <Your_Directory>/phy/setupenv.sh
```
## Install the FHI Library
:::info
- Make sure environment variables are already correct first
:::
```shell=
## Softlink pkgconf from pkg-config
## Because the `build.sh` run the command "pkgconf", but in CentOS, this application is called "pkg-config". Hence, we need to link them together.
$ sudo ln -s /usr/bin/pkg-config /usr/bin/pkgconf
$ cd $XRAN_DIR
$ ./build.sh xclean
## Build the FHI library
$ cd $XRAN_DIR/lib
$ make
## Compile sample-app.c
$ cd $XRAN_DIR/app
$ make
## Install Octave
$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y
$ sudo yum install octave -y
$ sudo yum install -y expect
## Generate IQ Samples of Sample app
## This will be used by sample app
$ cd $XRAN_DIR/app
$ octave gen_test.m
```
:::danger
If you meet the following error:

Make sure that your pkg-config version is 0.29.2. You can follow [this reference](https://hackmd.io/@ferlinda/r1dHo4FI5#Update-pkg-config)
:::
<!--
```shell=
## Soft link pkg-config to pkgconf
$ sudo ln -s /usr/bin/pkg-config /usr/bin/pkgconf
$ cd $XRAN_DIR
## Change the permission
$ chmod 777 build.sh
## Start compiling
$ ./build.sh
```