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 - Devices -> Insert Guest Additions CD Image (install) 66 - Devices -> Shared Clipboard -> Bidirectional 67 - reboot (the VM) 68 693. Install required packages 70 71 Refer to 72 [Prerequisite](https://github.com/openbmc/openbmc/blob/master/README.md#1-prerequisite) 73 link. 74 75 **Note** - In Ubuntu, a "sudo apt-get update" will probably be needed before 76 installing the packages. 77 78## Building OpenBMC 79 80Note this section will take you through the process of building a Romulus 81OpenBMC image. Future tutorials will build on this by having you customize the 82image. If you would like to skip the building and just try out OpenBMC and QEMU 83then you can download the latest Romulus image from the 84[OpenBMC Jenkins](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) 85and skip to the 86[Download and Start QEMU Session](#download-and-start-qemu-session) section. 87 881. Clone OpenBMC 89 90 ```bash 91 git clone https://github.com/openbmc/openbmc.git 92 ``` 93 942. Build the Romulus OpenBMC Image (note this will take 30 - 120 minutes 95 depending on your hardware) 96 97 ```bash 98 . setup romulus 99 bitbake obmc-phosphor-image 100 ``` 101 102The Romulus image is now located in 103`build/tmp/deploy/images/romulus/obmc-phosphor-image-romulus.static.mtd` 104relative to your current directory. 105 106## Download and Start QEMU Session 107 1081. Download latest openbmc/qemu fork of QEMU application 109 110 ```bash 111 wget https://jenkins.openbmc.org/job/latest-qemu-x86/lastSuccessfulBuild/artifact/qemu/build/qemu-system-arm 112 113 chmod u+x qemu-system-arm 114 ``` 115 1162. Copy the image generated by the build to your current directory 117 118 ```bash 119 cp ./tmp/deploy/images/romulus/obmc-phosphor-image-romulus.static.mtd ./ 120 ``` 121 1223. Start QEMU with the Romulus image 123 124 **Note** - For REST, SSH and IPMI to work into your QEMU session, you must 125 connect up some host ports to the REST, SSH and IPMI ports in your QEMU 126 session. In this example, it just uses 2222, 2443, 2623. You can use whatever 127 you prefer. 128 129 ```bash 130 ./qemu-system-arm -m 256 -M romulus-bmc -nographic \ 131 -drive file=./obmc-phosphor-image-romulus.static.mtd,format=raw,if=mtd \ 132 -net nic \ 133 -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 134 ``` 135 136 If you are running within a virtual environment where you can use the real 137 ports, then you would start QEMU with the following. 138 139 ```bash 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 145 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 146 147 ``` 148 1494. Wait for your QEMU-based BMC to boot 150 151 Login using default root/0penBmc login (Note the 0 is a zero). 152 1535. Check the system state 154 155 You'll see a lot of services starting in the console, you can start running 156 the obmcutil tool to check the state of the OpenBMC state services. When you 157 see the following then you have successfully booted to "Ready" state. 158 159 ```bash 160 root@openbmc:~# obmcutil state 161 CurrentBMCState : xyz.openbmc_project.State.BMC.BMCState.Ready 162 CurrentPowerState : xyz.openbmc_project.State.Chassis.PowerState.Off 163 CurrentHostState : xyz.openbmc_project.State.Host.HostState.Off 164 ``` 165 166 **Note** To exit (and kill) your QEMU session run: `ctrl+a x` 167 1686. Test out the ssh network interface 169 170 Run these from the system you started QEMU on 171 172 ```bash 173 ssh root@localhost -p 2222 174 ``` 175 176 Login is the same as what was used above for the default QEMU login. 177 178You've now built an OpenBMC distribution and booted it in QEMU! 179 180## Alternative yocto QEMU 181 182yocto has tools for building and running qemu. These tools avoid some of the 183configuration issues that come from downloading a prebuilt image, and modifying 184binaries. Using yocto qemu also uses the 185[TAP interface](https://www.kernel.org/doc/Documentation/networking/tuntap.txt) 186which some find be more stable. This is particularly useful when debugging at 187the application level. 188 189This is a more advanced section and may be useful to come back to once the 190basics are working for you. The next tutorial will focus on devtool and how to 191utilize it to customize your OpenBMC image. 192 193- set up a bmc build environment 194 195```bash 196source setup romulus myBuild/build 197``` 198 199- add the qemu x86 open embedded machine for testing 200 201```bash 202MACHINE ??= "qemux86" 203``` 204 205- Make the changes to the build (ie devtool modify bmcweb, devtool add gdb) 206 207```bash 208devtool modify bmcweb myNewLocalbmcweb/ 209``` 210 211- build open bmc for the qemu x86 machine 212 213```bash 214MACHINE=qemux86 bitbake obmc-phosphor-image 215``` 216 217- run qemu they way yocto provides 218 219```bash 220runqemu myBuild/build/tmp/deploy/images/qemux86/ nographic \ 221 qemuparams="-m 2048" 222``` 223 224- after that the all the a TAP network interface is added, and protocol like 225 ssh, scp, http work well. 226