Cross Compile
To cross-compile on OpenBMC, follow these steps:
Source the setup
script
Start by sourcing the setup
script for your target hardware. You can find the script on the OpenBMC GitHub repository. Execute the following command in your terminal:
1 | . setup romulus |
Build the SDK
Next, build the Software Development Kit (SDK) using the bitbake
command. Specify your target as an argument. For example:
1 | albertlin@thinkbook:$ bitbake -c populate_sdk obmc-phosphor-image |
Install the SDK
Once the SDK is built, you need to install it. Follow these steps:
Create a folder where you want to install the SDK. For instance, let’s use
/usr/local/openbmc
.1
albertlin@thinkbook:$ sudo mkdir /usr/local/openbmc
Navigate to the directory containing the SDK installation files.
1
albertlin@thinkbook:$ cd ./tmp/deploy/sdk/
Run the SDK installation script using the following command:
1
2
3albertlin@thinkbook:$ ./oecore-x86_64-armv7ahf-vfpv4d16-toolchain-nodistro.0.sh
Phosphor OpenBMC (Phosphor OpenBMC Project Reference Distro) SDK installer version nodistro.0
=============================================================================================The installation script will prompt you to enter the target directory for the SDK. Specify
/usr/local/openbmc
when prompted:1
Enter target directory for SDK (default: /usr/local/oecore-x86_64): /usr/local/openbmc
Confirm the installation by typing ‘y’ when asked if you want to proceed:
1
2
3
4
5You are about to install the SDK to "/usr/local/openbmc". Proceed [Y/n]? y
Extracting SDK....................................................................................................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.The SDK will be extracted and set up in the specified directory.
Verify that the installation was successful by checking the contents of the installation directory:
1
albertlin@thinkbook:$ ls -al /usr/local/openbmc/
Using the SDK
Before compiling your code, you need to set up the SDK environment. Execute the following command to source the environment setup script:
1 | albertlin@thinkbook:$ . /usr/local/openbmc/environment-setup-armv7ahf-vfpv4d16-openbmc-linux-gnueabi |
Compile
Now you’re ready to compile your code. Here’s an example of compiling a simple “hello” program:
Create a directory for your project and navigate into it.
1
2albertlin@thinkbook:$ mkdir hello
albertlin@thinkbook:$ cd helloCreate a C source file named
hello.c
and a Meson build file namedmeson.build
with the following content:hello.c
:1
2
3
4
5
6
int main(void) {
printf("Hello OpenBMC\n");
return 0;
}meson.build
:1
2
3project('hello', 'c')
executable('hello', 'hello.c')Generate the build files using Meson:
1
albertlin@thinkbook:hello$ meson build
Build the project using Ninja:
1
albertlin@thinkbook:hello$ ninja -C build
Once the build is complete, you can find the compiled binary in the
build
directory. You can copy it to your OpenBMC target for execution using thescp
command:1
albertlin@thinkbook:hello$ scp build/hello root@192.168.0.196:/tmp
Run built program in BMC
To execute the binary on your BMC target, follow these steps:
Connect to your BMC target using SSH.
1
ssh root@192.168.0.196
Navigate to the directory where you copied the binary.
1
root@romulus:/tmp# cd /tmp
Run the binary.
1
2root@romulus:/tmp# ./hello
Hello OpenBMC
That’s it! You have successfully cross-compiled and executed a program on OpenBMC.
Native Build
Source the setup
script
Start by sourcing the setup
script for your target hardware. You can find the script on the OpenBMC GitHub repository. Execute the following command in your terminal:
1 | . setup romulus |
Environment Setup and Checking
- Check if the required packages listed by sdbusplus are installed:
1 | sudo apt install git meson libtool pkg-config g++ libsystemd-dev \ |
Check the Boost version used by OpenBMC:
1
2
3albertlin@thinkbook:$ bitbake-layers show-recipes | grep -i meson -A 1
boost:
boost 1.82.0Ensure that the Boost version matches what OpenBMC currently use.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31albertlin@albertlin:boost$ wget https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/boost_1_82_0.tar.gz
--2023-06-17 03:30:56--
...
2023-06-17 03:31:52 (2.52 MB/s) - ‘boost_1_82_0.tar.gz’ saved [142580547/142580547]
albertlin@albertlin:boost$ ls
boost_1_82_0.tar.gz
albertlin@albertlin:boost_1_82_0$ ./bootstrap.sh --prefix=/usr
Building B2 engine..
...
Further information:
- Command line help:
./b2 --help
- Getting started guide:
http://www.boost.org/more/getting_started/unix-variants.html
- B2 documentation:
http://www.boost.org/build/
albertlin@albertlin:boost_1_82_0$ sudo ./b2 --install
Performing configuration checks
...
The following directory should be added to linker library paths:
/home/albertlin/hypnoslin/openbmc/boost/boost_1_82_0/stage/lib
albertlin@albertlin:sdbusplus$ cat /usr/include/boost/version.hpp | grep "BOOST_LIB_VERSION"
// BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#define BOOST_LIB_VERSION "1_82"Check the Meson version used by OpenBMC:
1 | albertlin@thinkbook:$ bitbake-layers show-recipes | grep -i meson -A 1 |
- Ensure that the Meson version matches what OpenBMC currently uses. It’s recommended to have an upgraded version:
1 | albertlin@albertlin:sdbusplus$ meson -v |
- If there are missing packages reported by Meson while building, install them:
1 | sudo apt-get install -y libi2c-dev libarchive-dev libfmt-dev libsystemd-dev |
- Verify that the GCC/G++ version matches what OpenBMC currently uses.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20albertlin@thinkbook:$ bitbake-layers show-recipes | grep gcc -A 1
gcc:
meta 12.2.0
gcc-cross-arm:
meta 12.2.0
gcc-cross-canadian-arm:
meta 12.2.0
gcc-crosssdk-x86_64-oesdk-linux:
meta 12.2.0
gcc-runtime:
meta 12.2.0
gcc-sanitizers:
meta 12.2.0
gcc-source-12.2.0:
meta 12.2.0
–
libgcc:
meta 12.2.0
libgcc-initial:
meta 12.2.01
2
3
4
5albertlin@thinkbook:$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
...
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04.1) - Ensure that the g++ version matches what OpenBMC currently uses.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18albertlin@albertlin:~$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
...
gcc version 9.5.0 (Ubuntu 9.5.0-1ubuntu1~22.04)
albertlin@albertlin:~$ sudo apt install g++-12
Reading package lists... Done
...
Processing triggers for man-db (2.10.2-1) ...
albertlin@albertlin:~$ ls -al /usr/bin/g++
lrwxrwxrwx 1 root root 5 Mar 20 2020 /usr/bin/g++ -> g++-9
albertlin@albertlin:~$ sudo rm /usr/bin/g++
albertlin@albertlin:~$ sudo ln /usr/bin/g++-12 /usr/bin/g++
albertlin@albertlin:~$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
...
gcc version 12.1.0 (Ubuntu 12.1.0-2ubuntu1~22.04)
Building and Executing
Clone the sdbusplus repository. Run the following command:
1
2git clone https://github.com/openbmc/sdbusplus.git
cd sdbusplusConfigure the build using Meson. Run the following command:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32albertlin@albertlin:sdbusplus$ meson build -Dtests=disabled -Dexamples=disabled
The Meson build system
Version: 1.1.1
Source dir: /home/albertlin/hypnoslin/openbmc/sdbusplus
Build dir: /home/albertlin/hypnoslin/openbmc/sdbusplus/build
Build type: native build
Project name: sdbusplus
Project version: 1.0.0
C compiler for the host machine: cc (gcc 11.3.0 "cc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0")
C linker for the host machine: cc ld.bfd 2.38
C++ compiler for the host machine: c++ (gcc 12.1.0 "c++ (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0")
C++ linker for the host machine: c++ ld.bfd 2.38
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (0.29.2)
Run-time dependency libsystemd found: YES 249
Program python3 (inflection, yaml, mako) found: YES (/usr/bin/python3) modules: inflection, yaml, mako
Run-time dependency Boost found: YES 1.82.0 (/usr/include)
Program sdbus++ found: YES (/home/albertlin/hypnoslin/openbmc/sdbusplus/tools/sdbus++)
Program sdbus++ found: YES (overridden)
Program sdbus++-gen-meson found: YES (/home/albertlin/hypnoslin/openbmc/sdbusplus/tools/sdbus++-gen-meson)
Program sdbus++-gen-meson found: YES (overridden)
Build targets in project: 1
sdbusplus 1.0.0
User defined options
examples: disabled
tests : disabled
Found ninja-1.10.1 at /usr/bin/ninja
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.Build the project using Ninja. Run the following command:
1
2
3albertlin@albertlin:sdbusplus$ ninja -C build
ninja: Entering directory `build'
[11/11] Linking target libsdbusplus.so.1.0.0