1# OpenBMC Development Environment
2
3**Document Purpose:** How to set up an OpenBMC development environment
4
5**Audience:** Programmer familiar with Linux and BMCs
6
7**Prerequisites:** Current Linux, Mac, or Windows system
8
9## Overview
10
11OpenBMC uses the [Yocto](https://www.yoctoproject.org/) Project as its
12underlying building and distribution generation framework. The main OpenBMC
13[README](https://github.com/openbmc/openbmc/blob/master/README.md) provides
14information on getting up and going with Yocto and OpenBMC. There are mechanisms
15to use this process to build your changes but it can be slow and cumbersome for
16initial debug and validation of your software. This guide focuses on how to test
17new changes quickly using the OpenBMC Software Development Kit (SDK) and
18[QEMU](https://www.qemu.org/).
19
20The SDK is a group of packages that are built during a BitBake operation.
21BitBake is the tool used to build Yocto based distributions. The SDK provides
22all required libraries and cross compilers to build OpenBMC applications. The
23SDK is not used to build entire OpenBMC flash images, it provides a mechanism to
24compile OpenBMC applications and libraries that you can then copy onto a running
25system for testing.
26
27QEMU is a software emulator that can be used to run OpenBMC images.
28
29This doc walks through the recommended steps for setting up an OpenBMC
30development environment and installing the needed SDK.
31
32For testing purposes, this guide uses the Romulus system as the default because
33this is the system tested for each CI job, which means it's the most stable.
34
35## Install Linux Environment
36
37If you are running Linux, and are ok with installing some additional packages,
38then you can skip to step 3.
39
40The recommended OpenBMC development environment is the latest Ubuntu LTS
41release. Other versions of Linux may work but you are using that at your own
42risk. If you have Windows or Mac OS then VirtualBox is the recommended
43virtualization tool to run the development environment.
44
451. Install either [VirtualBox](https://www.virtualbox.org/wiki/Downloads) or
46   [VMware](https://www.vmware.com/products/workstation-player/workstation-player-evaluation.html)
47   onto your computer (Mac, Windows, Linux)
48
49Both have free versions available for what you need. VirtualBox is what the
50majority of core OpenBMC development is using. **Note:** If you want to use this
51VM to BitBake a full OpenBMC image, you'll want to allocate as many resources as
52possible. Ideal minimum resources are 8 threads, 16GB memory, 200GB hard drive.
53Just using for SDK builds and QEMU should work fine with the normal defaults on
54a VM.
55
562. Install the latest Ubuntu LTS release
57
58The majority of OpenBMC development community uses Ubuntu. The qemu below is
59built on [18.04](http://releases.ubuntu.com/18.04/) but whatever is most recent
60_should_ work. The same goes for other Linux distributions like Fedora but
61again, these are not tested nearly as much by the core OpenBMC team as Ubuntu.
62
63**VirtualBox Tips** - You'll want copy/paste working between your VM and Host.
64To do that, once you have your VM up and running:
65
66- Devices -> Insert Guest Additions CD Image (install)
67- Devices -> Shared Clipboard -> Bidirectional
68- reboot (the VM)
69
703. Install required packages
71
72Refer to
73[Prerequisite](https://github.com/openbmc/openbmc/blob/master/README.md#1-prerequisite)
74link.
75
76**Note** - In Ubuntu, a "sudo apt-get update" will probably be needed before
77installing the packages.
78
79## Download and Install SDK
80
81The OpenBMC Software Development Kit (SDK) contains a cross-toolchain and a set
82libraries for working on OpenBMC applications. The SDK is installed on the
83machine you will use to develop applications for OpenBMC and not on the BMC
84itself.
85
86Generally, SDKs for one BMC cannot be used for developing software for other
87BMCs. This can be due to platform ABI, libc or kernel differences, or any other
88number of choices made in the configuration of the firmware.
89
90Romulus is the BMC platform used for the purpose of this walk-through.
91
92To begin working with the SDK:
93
941. Download the latest SDK to your system. It's recommended that you create a
95   directory to store your SDK scripts and installation directories to keep your
96   workspace organised.
97
98```
99mkdir -p ~/sdk
100cd ~/sdk
101
102wget https://jenkins.openbmc.org/job/latest-master-sdk/label=docker-builder,target=romulus/lastSuccessfulBuild/artifact/deploy/sdk/oecore-x86_64-arm1176jzs-toolchain-nodistro.0.sh
103chmod u+x oecore-x86_64-arm1176jzs-toolchain-nodistro.0.sh
104```
105
1062. Install the SDK
107
108Choose an appropriate location and name. It's a good idea to include the date
109and system supported by that SDK in the directory name. For example:
110
111```
112mkdir -p ~/sdk/romulus-`date +%F`
113```
114
115Run the following command to install the SDK. When command asks you to "Enter
116target directory for SDK", enter the directory you created in the previous step.
117
118```
119./oecore-x86_64-arm1176jzs-toolchain-nodistro.0.sh
120```
121
122The installation script will indicate progress and give completion messages like
123this:
124
125```
126SDK has been successfully set up and is ready to be used.
127Each time you wish to use the SDK in a new shell session, you need to source
128the environment setup script e.g. $ . /...path-to-sdk.../environment-setup-arm1176jzs-openbmc-linux-gnueabi
129```
130
1313. Source yourself into the SDK
132
133Ensure no errors. The command to do this will be provided at the end of
134installation. To make your shell use the new SDK environment, you must source
135its `environment-setup` script which was created in the previous step. You may
136wish to save the required command, for example, cut/paste the text above into a
137README.
138
139That's it, you now have a working development environment for OpenBMC!
140
141## Download and Start QEMU Session
142
1431. Download latest openbmc/qemu fork of QEMU application
144
145```
146wget https://jenkins.openbmc.org/job/latest-qemu-x86/lastSuccessfulBuild/artifact/qemu/build/qemu-system-arm
147
148chmod u+x qemu-system-arm
149```
150
1512. Download the Romulus image.
152
153```
154wget https://jenkins.openbmc.org/job/latest-master/label=docker-builder,target=romulus/lastSuccessfulBuild/artifact/openbmc/build/tmp/deploy/images/romulus/obmc-phosphor-image-romulus.static.mtd
155```
156
1573. Start QEMU with downloaded Romulus image
158
159   **Note** - For REST, SSH and IPMI to work into your QEMU session, you must
160   connect up some host ports to the REST, SSH and IPMI ports in your QEMU
161   session. In this example, it just uses 2222, 2443, 2623. You can use whatever
162   you prefer.
163
164```
165./qemu-system-arm -m 256 -M romulus-bmc -nographic \
166    -drive file=./obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \
167    -net nic \
168    -net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443,hostfwd=udp:127.0.0.1:2623-:623,hostname=qemu
169```
170
171**Note** - By default, Jenkins and openbmc-test-automation use SSH and HTTPS
172ports 22 and 443, respectively. For the IPMI port 623 is used. SSH connection to
173use a user-defined port 2222 might not be successful. To use SSH port 22, HTTPS
174port 443 and IPMI port 623:
175
176```
177./qemu-system-arm -m 256 -machine romulus-bmc -nographic \
178    -drive file=./obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \
179    -net nic \
180    -net user,hostfwd=:127.0.0.1:22-:22,hostfwd=:127.0.0.1:443-:443,hostfwd=tcp:127.0.0.1:80-:80,hostfwd=tcp:127.0.0.1:2200-:2200,hostfwd=udp:127.0.0.1:623-:623,hostfwd=udp:127.0.0.1:664-:664,hostname=qemu
181```
182
1834. Wait for your QEMU-based BMC to boot
184
185Login using default root/0penBmc login (Note the 0 is a zero).
186
1875. Check the system state
188
189You'll see a lot of services starting in the console, you can start running the
190obmcutil tool to check the state of the OpenBMC state services. When you see the
191following then you have successfully booted to "Ready" state.
192
193```
194root@openbmc:~# obmcutil state
195CurrentBMCState     : xyz.openbmc_project.State.BMC.BMCState.Ready
196CurrentPowerState   : xyz.openbmc_project.State.Chassis.PowerState.Off
197CurrentHostState    : xyz.openbmc_project.State.Host.HostState.Off
198```
199
200**Note** To exit (and kill) your QEMU session run: `ctrl+a x`
201
202## Alternative yocto QEMU
203
204yocto has tools for building and running qemu. These tools avoid some of the
205configuration issues that come from downloading a prebuilt image, and modifying
206binaries. Using yocto qemu also uses the
207[TAP interface](https://www.kernel.org/doc/Documentation/networking/tuntap.txt)
208which some find be more stable. This is particularly useful when debugging at
209the application level.
210
211- set up a bmc build environment
212
213```
214source setup romulus myBuild/build
215```
216
217- add the qemu x86 open embedded machine for testing
218
219```
220MACHINE ??= "qemux86"
221```
222
223- Make the changes to the build (ie devtool modify bmcweb, devtool add gdb)
224
225```
226devtool modify bmcweb myNewLocalbmcweb/
227```
228
229- build open bmc for the qemu x86 machine
230
231```
232MACHINE=qemux86 bitbake obmc-phosphor-image
233```
234
235- run qemu they way yocto provides
236
237```
238runqemu myBuild/build/tmp/deploy/images/qemux86/ nographic \
239    qemuparams="-m 2048"
240```
241
242- after that the all the a TAP network interface is added, and protocol like
243  ssh, scp, http work well.
244