xref: /openbmc/docs/development/dev-environment.md (revision f31c96dff3586cacfb1da6729a300cdef7c613ca)
11dc181c4SAndrew Geissler# OpenBMC Development Environment
21dc181c4SAndrew Geissler
31dc181c4SAndrew Geissler**Document Purpose:** How to set up an OpenBMC development environment
41dc181c4SAndrew Geissler
51dc181c4SAndrew Geissler**Audience:** Programmer familiar with Linux and BMCs
61dc181c4SAndrew Geissler
71dc181c4SAndrew Geissler**Prerequisites:** Current Linux, Mac, or Windows system
81dc181c4SAndrew Geissler
9c3790e34SAndrew Geissler## Overview
101dc181c4SAndrew Geissler
111dc181c4SAndrew GeisslerOpenBMC uses the [Yocto](https://www.yoctoproject.org/) Project as its
12f4febd00SPatrick Williamsunderlying building and distribution generation framework. The main OpenBMC
13f4febd00SPatrick Williams[README](https://github.com/openbmc/openbmc/blob/master/README.md) provides
14*f31c96dfSAndrew Geisslerinformation on getting up and going with Yocto and OpenBMC. This tutorial will
15*f31c96dfSAndrew Geisslerwalk you through utilizing bitbake to build OpenBMC firmware and boot it in
16f4febd00SPatrick Williams[QEMU](https://www.qemu.org/).
171dc181c4SAndrew Geissler
18*f31c96dfSAndrew GeisslerBitbake is the build engine used by Yocto and OpenBMC to build its custom Linux
19*f31c96dfSAndrew Geisslerdistribution for a system. QEMU is a software emulator that can be used to run
20*f31c96dfSAndrew GeisslerOpenBMC images.
211dc181c4SAndrew Geissler
221dc181c4SAndrew GeisslerThis doc walks through the recommended steps for setting up an OpenBMC
23*f31c96dfSAndrew Geisslerdevelopment environment, building OpenBMC, and running that image in QEMU.
241dc181c4SAndrew Geissler
251dc181c4SAndrew GeisslerFor testing purposes, this guide uses the Romulus system as the default because
261dc181c4SAndrew Geisslerthis is the system tested for each CI job, which means it's the most stable.
271dc181c4SAndrew Geissler
28c3790e34SAndrew Geissler## Install Linux Environment
291dc181c4SAndrew Geissler
301dc181c4SAndrew GeisslerIf you are running Linux, and are ok with installing some additional packages,
311dc181c4SAndrew Geisslerthen you can skip to step 3.
321dc181c4SAndrew Geissler
331dc181c4SAndrew GeisslerThe recommended OpenBMC development environment is the latest Ubuntu LTS
341dc181c4SAndrew Geisslerrelease. Other versions of Linux may work but you are using that at your own
351dc181c4SAndrew Geisslerrisk. If you have Windows or Mac OS then VirtualBox is the recommended
361dc181c4SAndrew Geisslervirtualization tool to run the development environment.
371dc181c4SAndrew Geissler
38*f31c96dfSAndrew Geissler1. Install a Virtual Machine
39*f31c96dfSAndrew Geissler
40*f31c96dfSAndrew Geissler   Install either [VirtualBox](https://www.virtualbox.org/wiki/Downloads) or
411dc181c4SAndrew Geissler   [VMware](https://www.vmware.com/products/workstation-player/workstation-player-evaluation.html)
421dc181c4SAndrew Geissler   onto your computer (Mac, Windows, Linux)
431dc181c4SAndrew Geissler
44*f31c96dfSAndrew Geissler   Both have free versions available for what you need. **Note:** If you want to
45*f31c96dfSAndrew Geissler   use this VM to BitBake a full OpenBMC image, you'll want to allocate as many
46*f31c96dfSAndrew Geissler   resources as possible. Ideal minimum resources are 8 threads, 16GB memory,
47*f31c96dfSAndrew Geissler   200GB hard drive.
48*f31c96dfSAndrew Geissler
49*f31c96dfSAndrew Geissler   OpenBMC continuous integration utilizes docker to build its images. This is
50*f31c96dfSAndrew Geissler   another possibility but not covered within this document. See
51*f31c96dfSAndrew Geissler   [build-setup.sh](https://github.com/openbmc/openbmc-build-scripts/blob/master/build-setup.sh)
52*f31c96dfSAndrew Geissler   for a reference on the script CI uses to build an appropriate docker
53*f31c96dfSAndrew Geissler   container and launch bitbake within it. This also works within a podman
54*f31c96dfSAndrew Geissler   environment.
551dc181c4SAndrew Geissler
561dc181c4SAndrew Geissler2. Install the latest Ubuntu LTS release
571dc181c4SAndrew Geissler
58f4febd00SPatrick Williams   The majority of OpenBMC development community uses Ubuntu. The qemu below is
59*f31c96dfSAndrew Geissler   built on the latest Ubuntu LTS release but whatever is most recent _should_
60*f31c96dfSAndrew Geissler   work. The same goes for other Linux distributions like Fedora but again,
61*f31c96dfSAndrew Geissler   these are not tested nearly as much by the core OpenBMC team as Ubuntu.
621dc181c4SAndrew Geissler
63*f31c96dfSAndrew Geissler   **VirtualBox Tips** - You'll want copy/paste working between your VM and
64*f31c96dfSAndrew Geissler   Host. To do that, once you have your VM up and running:
65f4febd00SPatrick Williams
661dc181c4SAndrew Geissler   - Devices -> Insert Guest Additions CD Image (install)
671dc181c4SAndrew Geissler   - Devices -> Shared Clipboard -> Bidirectional
681dc181c4SAndrew Geissler   - reboot (the VM)
691dc181c4SAndrew Geissler
701dc181c4SAndrew Geissler3. Install required packages
711dc181c4SAndrew Geissler
721dc181c4SAndrew Geissler   Refer to
731dc181c4SAndrew Geissler   [Prerequisite](https://github.com/openbmc/openbmc/blob/master/README.md#1-prerequisite)
741dc181c4SAndrew Geissler   link.
751dc181c4SAndrew Geissler
761dc181c4SAndrew Geissler   **Note** - In Ubuntu, a "sudo apt-get update" will probably be needed before
771dc181c4SAndrew Geissler   installing the packages.
781dc181c4SAndrew Geissler
79*f31c96dfSAndrew Geissler## Building OpenBMC
80859b579dSAndrew Jeffery
81*f31c96dfSAndrew GeisslerNote this section will take you through the process of building a Romulus
82*f31c96dfSAndrew GeisslerOpenBMC image. Future tutorials will build on this by having you customize the
83*f31c96dfSAndrew Geisslerimage. If you would like to skip the building and just try out OpenBMC and QEMU
84*f31c96dfSAndrew Geisslerthen you can download the latest Romulus image from
85*f31c96dfSAndrew Geissler[here](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)
86*f31c96dfSAndrew Geisslerand skip to the
87*f31c96dfSAndrew Geissler[Download and Start QEMU Session](#download-and-start-qemu-session) section.
88859b579dSAndrew Jeffery
89*f31c96dfSAndrew Geissler1. Clone OpenBMC
90859b579dSAndrew Jeffery
91859b579dSAndrew Jeffery   ```
92*f31c96dfSAndrew Geissler   git clone https://github.com/openbmc/openbmc.git
93859b579dSAndrew Jeffery   ```
94859b579dSAndrew Jeffery
95*f31c96dfSAndrew Geissler2. Build the Romulus OpenBMC Image (note this will take 30 - 120 minutes
96*f31c96dfSAndrew Geissler   depending on your hardware)
97859b579dSAndrew Jeffery
98859b579dSAndrew Jeffery   ```
99*f31c96dfSAndrew Geissler   . setup romulus
100*f31c96dfSAndrew Geissler   bitbake obmc-phosphor-image
101859b579dSAndrew Jeffery   ```
102859b579dSAndrew Jeffery
103*f31c96dfSAndrew GeisslerThe Romulus image is now located in
104*f31c96dfSAndrew Geissler`build/tmp/deploy/images/romulus/obmc-phosphor-image-romulus.static.mtd`
105*f31c96dfSAndrew Geisslerrelative to your current directory.
106859b579dSAndrew Jeffery
107c3790e34SAndrew Geissler## Download and Start QEMU Session
1081dc181c4SAndrew Geissler
1091dc181c4SAndrew Geissler1. Download latest openbmc/qemu fork of QEMU application
1101dc181c4SAndrew Geissler
1111dc181c4SAndrew Geissler   ```
112eea7decfSAndrew Geissler   wget https://jenkins.openbmc.org/job/latest-qemu-x86/lastSuccessfulBuild/artifact/qemu/build/qemu-system-arm
1131dc181c4SAndrew Geissler
1141dc181c4SAndrew Geissler   chmod u+x qemu-system-arm
1151dc181c4SAndrew Geissler   ```
1161dc181c4SAndrew Geissler
117*f31c96dfSAndrew Geissler2. Copy the image generated by the build to your current directory
1181dc181c4SAndrew Geissler
1191dc181c4SAndrew Geissler   ```
120*f31c96dfSAndrew Geissler   cp ./tmp/deploy/images/romulus/obmc-phosphor-image-romulus.static.mtd ./
1211dc181c4SAndrew Geissler   ```
1221dc181c4SAndrew Geissler
123*f31c96dfSAndrew Geissler3. Start QEMU with the Romulus image
1241dc181c4SAndrew Geissler
125f4febd00SPatrick Williams   **Note** - For REST, SSH and IPMI to work into your QEMU session, you must
126f4febd00SPatrick Williams   connect up some host ports to the REST, SSH and IPMI ports in your QEMU
127f4febd00SPatrick Williams   session. In this example, it just uses 2222, 2443, 2623. You can use whatever
128f4febd00SPatrick Williams   you prefer.
129f4febd00SPatrick Williams
1301dc181c4SAndrew Geissler   ```
131dd148e03SPatrick Williams   ./qemu-system-arm -m 256 -M romulus-bmc -nographic \
132dd148e03SPatrick Williams       -drive file=./obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \
133dd148e03SPatrick Williams       -net nic \
134dd148e03SPatrick Williams       -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
1351dc181c4SAndrew Geissler   ```
1361dc181c4SAndrew Geissler
137*f31c96dfSAndrew Geissler   If you are running within a virtual environment where you can use the real
138*f31c96dfSAndrew Geissler   ports, then you would start QEMU with the following.
139f4febd00SPatrick Williams
140eb9d9b47SMaksym   ```
141dd148e03SPatrick Williams   ./qemu-system-arm -m 256 -machine romulus-bmc -nographic \
142dd148e03SPatrick Williams       -drive file=./obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \
143dd148e03SPatrick Williams       -net nic \
144dd148e03SPatrick Williams       -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
145eb9d9b47SMaksym   ```
146eb9d9b47SMaksym
1471dc181c4SAndrew Geissler4. Wait for your QEMU-based BMC to boot
1481dc181c4SAndrew Geissler
1491dc181c4SAndrew Geissler   Login using default root/0penBmc login (Note the 0 is a zero).
1501dc181c4SAndrew Geissler
1511dc181c4SAndrew Geissler5. Check the system state
1521dc181c4SAndrew Geissler
153*f31c96dfSAndrew Geissler   You'll see a lot of services starting in the console, you can start running
154*f31c96dfSAndrew Geissler   the obmcutil tool to check the state of the OpenBMC state services. When you
155*f31c96dfSAndrew Geissler   see the following then you have successfully booted to "Ready" state.
1561dc181c4SAndrew Geissler
157395b2d03SAlexander Amelkin   ```
158395b2d03SAlexander Amelkin   root@openbmc:~# obmcutil state
159395b2d03SAlexander Amelkin   CurrentBMCState     : xyz.openbmc_project.State.BMC.BMCState.Ready
160395b2d03SAlexander Amelkin   CurrentPowerState   : xyz.openbmc_project.State.Chassis.PowerState.Off
161395b2d03SAlexander Amelkin   CurrentHostState    : xyz.openbmc_project.State.Host.HostState.Off
162395b2d03SAlexander Amelkin   ```
1631dc181c4SAndrew Geissler
1641dc181c4SAndrew Geissler   **Note** To exit (and kill) your QEMU session run: `ctrl+a x`
165da726aadSJohn Edward Broadbent
166*f31c96dfSAndrew Geissler6. Test out the ssh network interface
167*f31c96dfSAndrew Geissler
168*f31c96dfSAndrew Geissler   Run these from the system you started QEMU on
169*f31c96dfSAndrew Geissler
170*f31c96dfSAndrew Geissler   ```
171*f31c96dfSAndrew Geissler   ssh root@localhost -p 2222
172*f31c96dfSAndrew Geissler   ```
173*f31c96dfSAndrew Geissler
174*f31c96dfSAndrew Geissler   Login is the same as what was used above for the default QEMU login.
175*f31c96dfSAndrew Geissler
176*f31c96dfSAndrew GeisslerYou've now built an OpenBMC distribution and booted it in QEMU!
177*f31c96dfSAndrew Geissler
178da726aadSJohn Edward Broadbent## Alternative yocto QEMU
179da726aadSJohn Edward Broadbent
180da726aadSJohn Edward Broadbentyocto has tools for building and running qemu. These tools avoid some of the
181f4febd00SPatrick Williamsconfiguration issues that come from downloading a prebuilt image, and modifying
182f4febd00SPatrick Williamsbinaries. Using yocto qemu also uses the
183f4febd00SPatrick Williams[TAP interface](https://www.kernel.org/doc/Documentation/networking/tuntap.txt)
184f4febd00SPatrick Williamswhich some find be more stable. This is particularly useful when debugging at
185f4febd00SPatrick Williamsthe application level.
186da726aadSJohn Edward Broadbent
187*f31c96dfSAndrew GeisslerThis is a more advanced section and may be useful to come back to once the
188*f31c96dfSAndrew Geisslerbasics are working for you. The next tutorial will focus on devtool and how to
189*f31c96dfSAndrew Geisslerutilize it to customize your OpenBMC image.
190*f31c96dfSAndrew Geissler
191146f9098SGeorge Keishing- set up a bmc build environment
192f4febd00SPatrick Williams
193da726aadSJohn Edward Broadbent```
194da726aadSJohn Edward Broadbentsource setup romulus myBuild/build
195da726aadSJohn Edward Broadbent```
196f4febd00SPatrick Williams
197da726aadSJohn Edward Broadbent- add the qemu x86 open embedded machine for testing
198f4febd00SPatrick Williams
199da726aadSJohn Edward Broadbent```
200da726aadSJohn Edward BroadbentMACHINE ??= "qemux86"
201da726aadSJohn Edward Broadbent```
202f4febd00SPatrick Williams
203da726aadSJohn Edward Broadbent- Make the changes to the build (ie devtool modify bmcweb, devtool add gdb)
204f4febd00SPatrick Williams
205da726aadSJohn Edward Broadbent```
206da726aadSJohn Edward Broadbentdevtool modify bmcweb myNewLocalbmcweb/
207da726aadSJohn Edward Broadbent```
208f4febd00SPatrick Williams
209da726aadSJohn Edward Broadbent- build open bmc for the qemu x86 machine
210f4febd00SPatrick Williams
211da726aadSJohn Edward Broadbent```
212da726aadSJohn Edward BroadbentMACHINE=qemux86 bitbake obmc-phosphor-image
213da726aadSJohn Edward Broadbent```
214f4febd00SPatrick Williams
215da726aadSJohn Edward Broadbent- run qemu they way yocto provides
216f4febd00SPatrick Williams
217da726aadSJohn Edward Broadbent```
218da726aadSJohn Edward Broadbentrunqemu myBuild/build/tmp/deploy/images/qemux86/ nographic \
219da726aadSJohn Edward Broadbent    qemuparams="-m 2048"
220da726aadSJohn Edward Broadbent```
221f4febd00SPatrick Williams
222da726aadSJohn Edward Broadbent- after that the all the a TAP network interface is added, and protocol like
223da726aadSJohn Edward Broadbent  ssh, scp, http work well.
224