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. This tutorial will 15walk you through utilizing bitbake to build OpenBMC firmware and boot it in 16[QEMU](https://www.qemu.org/). 17 18Bitbake is the build engine used by Yocto and OpenBMC to build its custom Linux 19distribution for a system. QEMU is a software emulator that can be used to run 20OpenBMC images. 21 22This doc walks through the recommended steps for setting up an OpenBMC 23development environment, building OpenBMC, and running that image in QEMU. 24 25For testing purposes, this guide uses the Romulus system as the default because 26this is the system tested for each CI job, which means it's the most stable. 27 28## Install Linux Environment 29 30If you are running Linux, and are ok with installing some additional packages, 31then you can skip to step 3. 32 33The recommended OpenBMC development environment is the latest Ubuntu LTS 34release. Other versions of Linux may work but you are using that at your own 35risk. If you have Windows or Mac OS then VirtualBox is the recommended 36virtualization tool to run the development environment. 37 381. Install a Virtual Machine 39 40 Install either [VirtualBox](https://www.virtualbox.org/wiki/Downloads) or 41 [VMware](https://www.vmware.com/products/workstation-player/workstation-player-evaluation.html) 42 onto your computer (Mac, Windows, Linux) 43 44 Both have free versions available for what you need. **Note:** If you want to 45 use this VM to BitBake a full OpenBMC image, you'll want to allocate as many 46 resources as possible. Ideal minimum resources are 8 threads, 16GB memory, 47 200GB hard drive. 48 49 OpenBMC continuous integration utilizes docker to build its images. This is 50 another possibility but not covered within this document. See 51 [build-setup.sh](https://github.com/openbmc/openbmc-build-scripts/blob/master/build-setup.sh) 52 for a reference on the script CI uses to build an appropriate docker 53 container and launch bitbake within it. This also works within a podman 54 environment. 55 562. Install the latest Ubuntu LTS release 57 58 The majority of OpenBMC development community uses Ubuntu. The qemu below is 59 built on the latest Ubuntu LTS release but whatever is most recent _should_ 60 work. The same goes for other Linux distributions like Fedora but again, 61 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 64 Host. To 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 72 Refer to 73 [Prerequisite](https://github.com/openbmc/openbmc/blob/master/README.md#1-prerequisite) 74 link. 75 76 **Note** - In Ubuntu, a "sudo apt-get update" will probably be needed before 77 installing the packages. 78 79## Building OpenBMC 80 81Note this section will take you through the process of building a Romulus 82OpenBMC image. Future tutorials will build on this by having you customize the 83image. If you would like to skip the building and just try out OpenBMC and QEMU 84then you can download the latest Romulus image from 85[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) 86and skip to the 87[Download and Start QEMU Session](#download-and-start-qemu-session) section. 88 891. Clone OpenBMC 90 91 ``` 92 git clone https://github.com/openbmc/openbmc.git 93 ``` 94 952. Build the Romulus OpenBMC Image (note this will take 30 - 120 minutes 96 depending on your hardware) 97 98 ``` 99 . setup romulus 100 bitbake obmc-phosphor-image 101 ``` 102 103The Romulus image is now located in 104`build/tmp/deploy/images/romulus/obmc-phosphor-image-romulus.static.mtd` 105relative to your current directory. 106 107## Download and Start QEMU Session 108 1091. Download latest openbmc/qemu fork of QEMU application 110 111 ``` 112 wget https://jenkins.openbmc.org/job/latest-qemu-x86/lastSuccessfulBuild/artifact/qemu/build/qemu-system-arm 113 114 chmod u+x qemu-system-arm 115 ``` 116 1172. Copy the image generated by the build to your current directory 118 119 ``` 120 cp ./tmp/deploy/images/romulus/obmc-phosphor-image-romulus.static.mtd ./ 121 ``` 122 1233. Start QEMU with the Romulus image 124 125 **Note** - For REST, SSH and IPMI to work into your QEMU session, you must 126 connect up some host ports to the REST, SSH and IPMI ports in your QEMU 127 session. In this example, it just uses 2222, 2443, 2623. You can use whatever 128 you prefer. 129 130 ``` 131 ./qemu-system-arm -m 256 -M romulus-bmc -nographic \ 132 -drive file=./obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \ 133 -net nic \ 134 -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 135 ``` 136 137 If you are running within a virtual environment where you can use the real 138 ports, then you would start QEMU with the following. 139 140 ``` 141 ./qemu-system-arm -m 256 -machine romulus-bmc -nographic \ 142 -drive file=./obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \ 143 -net nic \ 144 -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 145 ``` 146 1474. Wait for your QEMU-based BMC to boot 148 149 Login using default root/0penBmc login (Note the 0 is a zero). 150 1515. Check the system state 152 153 You'll see a lot of services starting in the console, you can start running 154 the obmcutil tool to check the state of the OpenBMC state services. When you 155 see the following then you have successfully booted to "Ready" state. 156 157 ``` 158 root@openbmc:~# obmcutil state 159 CurrentBMCState : xyz.openbmc_project.State.BMC.BMCState.Ready 160 CurrentPowerState : xyz.openbmc_project.State.Chassis.PowerState.Off 161 CurrentHostState : xyz.openbmc_project.State.Host.HostState.Off 162 ``` 163 164 **Note** To exit (and kill) your QEMU session run: `ctrl+a x` 165 1666. Test out the ssh network interface 167 168 Run these from the system you started QEMU on 169 170 ``` 171 ssh root@localhost -p 2222 172 ``` 173 174 Login is the same as what was used above for the default QEMU login. 175 176You've now built an OpenBMC distribution and booted it in QEMU! 177 178## Alternative yocto QEMU 179 180yocto has tools for building and running qemu. These tools avoid some of the 181configuration issues that come from downloading a prebuilt image, and modifying 182binaries. Using yocto qemu also uses the 183[TAP interface](https://www.kernel.org/doc/Documentation/networking/tuntap.txt) 184which some find be more stable. This is particularly useful when debugging at 185the application level. 186 187This is a more advanced section and may be useful to come back to once the 188basics are working for you. The next tutorial will focus on devtool and how to 189utilize it to customize your OpenBMC image. 190 191- set up a bmc build environment 192 193``` 194source setup romulus myBuild/build 195``` 196 197- add the qemu x86 open embedded machine for testing 198 199``` 200MACHINE ??= "qemux86" 201``` 202 203- Make the changes to the build (ie devtool modify bmcweb, devtool add gdb) 204 205``` 206devtool modify bmcweb myNewLocalbmcweb/ 207``` 208 209- build open bmc for the qemu x86 machine 210 211``` 212MACHINE=qemux86 bitbake obmc-phosphor-image 213``` 214 215- run qemu they way yocto provides 216 217``` 218runqemu myBuild/build/tmp/deploy/images/qemux86/ nographic \ 219 qemuparams="-m 2048" 220``` 221 222- after that the all the a TAP network interface is added, and protocol like 223 ssh, scp, http work well. 224