1 2# OpenBMC cheatsheet 3 4This document is intended to provide a set of recipes for common OpenBMC 5customisation tasks, without having to know the full yocto build process. 6 7## Using a local kernel build 8 9The kernel recipe is in: 10 11``` 12 meta-phosphor/common/recipes-kernel/linux/linux-obmc_X.Y.bb 13``` 14 15To use a local git tree, change the `SRC_URI` to a git:// URL without 16a hostname, and remove the `protocol=git` parameter. For example: 17 18``` 19SRC_URI = "git:///home/jk/devel/linux;branch=${KBRANCH}" 20``` 21 22The `SRCREV` variable can be used to set an explicit git commit, or 23set to `"${AUTOREV}"` to use the latest commit in `KBRANCH`. 24 25## Building for Palmetto 26 27The Palmetto target is `palmetto`. 28 29``` 30$ cd openbmc 31$ . setup palmetto 32$ bitbake obmc-phosphor-image 33``` 34 35## Building for Zaius 36 37The Zaius target is `zaius`. 38 39``` 40$ cd openbmc 41$ . setup zaius 42$ bitbake obmc-phosphor-image 43``` 44 45## Building a specific machine configuration 46 47If the system you want to build contains different machine configurations: 48 49``` 50meta-<layer>/meta-<system>/conf/machine/machineA.conf 51meta-<layer>/meta-<system>/conf/machine/machineB.conf 52``` 53 54You can specify the machine configuration you want to build by passing the 55name to the `setup`. 56 57``` 58$ cd openbmc 59$ . setup machineB 60$ bitbake obmc-phosphor-image 61``` 62 63## Building the OpenBMC SDK 64Looking for a way to compile your programs for 'ARM' but you happen to be running on a 'PPC' or 'x86' system? You can build the sdk receive a fakeroot environment. 65``` 66$ bitbake -c populate_sdk obmc-phosphor-image 67$ ./tmp/deploy/sdk/openbmc-phosphor-glibc-x86_64-obmc-phosphor-image-armv5e-toolchain-2.1.sh 68``` 69Follow the prompts. After it has been installed the default to setup your env will be similar to this command 70``` 71. /opt/openbmc-phosphor/2.1/environment-setup-armv5e-openbmc-linux-gnueabi 72``` 73 74## Rebuilds & Reconfiguration 75 76You can reconfigure your build by removing the build/conf dir: 77``` 78rm -rf build/conf 79``` 80and running `setup` again. 81 82## Useful D-Bus CLI tools 83 84## `busctl` 85 86http://www.freedesktop.org/software/systemd/man/busctl.html 87 88Great tool to issue D-Bus commands via cli. That way you don't have to wait for 89the code to hit the path on the system. Great for running commands with QEMU 90too! 91 92Run as: 93 94``` 95busctl call <path> <interface> <object> <method> <parameters> 96``` 97 98* \<parameters\> example : sssay "t1" "t2" "t3" 2 2 3 99 100## Using QEMU 101 102QEMU has a palmetto-bmc machine (as of v2.6.0) which implements the core 103devices to boot a Linux kernel. OpenBMC also [maintains a 104tree](https://github.com/openbmc/qemu) with patches on their way upstream or 105temporary work-arounds that add to QEMU's capabilities where appropriate. 106 107``` 108qemu-system-arm -m 256 -M palmetto-bmc -nographic \ 109-drive file=<path>/flash-palmetto,format=raw,if=mtd \ 110-net nic \ 111-net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443,hostname=qemu 112``` 113If you get an error you likely need to build QEMU (see the section in this document). If no error and QEMU starts up just change the port when interacting with the BMC... 114 115``` 116curl -c cjar -b cjar -k -H "Content-Type: application/json" \ 117-X POST https://localhost:2443/login -d "{\"data\": [ \"root\", \"0penBmc\" ] }" 118``` 119or 120 121``` 122ssh -p 2222 root@localhost 123``` 124 125To quit, type `Ctrl-a c` to switch to the QEMU monitor, and then `quit` to exit. 126 127## Building QEMU 128 129``` 130git clone https://github.com/openbmc/qemu.git 131cd qemu 132git submodule update --init dtc 133mkdir build 134cd build 135../configure --target-list=arm-softmmu 136make 137``` 138Built file will be located at: ```arm-softmmu/qemu-system-arm``` 139 140### Use a bridge device 141Using a bridge device requires a bit of root access to set it up. The benefit 142is your qemu session runs in the bridges subnet so no port forwarding is needed. 143There are packages needed to yourself a virbr0 such as... 144 145``` 146apt-get install libvirt libvirt-bin bridge-utils uml-utilities qemu-system-common 147 148qemu-system-arm -m 256 -M palmetto-bmc -nographic \ 149-drive file=<path>/flash-palmetto,format=raw,if=mtd \ 150-net nic,macaddr=C0:FF:EE:00:00:02,model=ftgmac100 \ 151-net bridge,id=net0,helper=/usr/lib/qemu-bridge-helper,br=virbr0 152``` 153 154There are some other useful parms like that can redirect the console to another 155window. This results in having an easily accessible qemu command session. 156```-monitor stdio -serial pty -nodefaults``` 157 158 159## Booting the host 160 161Login: 162``` 163curl -c cjar -k -X POST -H "Content-Type: application/json" -d '{"data": [ "root", "0penBmc" ] }' https://${bmc}/login 164``` 165 166Connect to host console: 167``` 168ssh -p 2200 root@bmc 169``` 170 171Power on: 172``` 173curl -c cjar -b cjar -k -H "Content-Type: application/json" -X PUT \ 174 -d '{"data": "xyz.openbmc_project.State.Host.Transition.On"}' \ 175 https://${bmc}/xyz/openbmc_project/state/host0/attr/RequestedHostTransition 176``` 177 178## GDB 179 180[SDK build](#building-the-openbmc-sdk) provides GDB and debug symbols: 181 182* `$GDB` is available to use once SDK environment is setup 183* Debug symbols are located in `.debug/` directory of each executable 184 185To use GDB: 186 1871. Setup SDK environment; 1882. Run below GDB commands: 189 ``` 190 cd <sysroot_of_sdk_build> 191 $GDB <relative_path_to_exeutable> <path_to_core_file> 192 ``` 193 194## Coredump 195 196By default coredump is disabled in OpenBMC. To enable coredump: 197``` 198echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern 199ulimit -c unlimited 200``` 201 202## Cleaning up read-write file system changes 203 204You may want to investigate which file(s) are persisting through the overlay 205rwfs. To do this, you can list this path and then remove those files which 206you'd prefer the originals or remove the deletion overlay to restore files. 207 208``` 209/run/initramfs/rw/cow/ 210``` 211 212## Building 213 214### Share downloads directory 215It takes a long time for the first build of OpenBMC. It downloads various repos 216from the internet. 217 218Check `build/downloads` to see all the downloaded repos. 219 220* If a repo is a single archive, it usually looks like this: 221 * `zlib-1.2.11.tar.xz` - The repo itself 222 * `zlib-1.2.11.tar.xz.done` - A flag indicating the repo is downloaded 223* If a repo is managed by git, it usually looks like this: 224 * `git2/github.com.openbmc.linux` - The git bare clone 225 * `git2/github.com.openbmc.linux.done` - A flag indicating the repo is downloaded 226 227Bitbake will extract the code to the working directory during build, so the 228`downloads` directory could be shared by different builds on a system: 229 230* Set `DL_DIR` Bitbake environment variable to the location of your shared 231 downloads directory by editing the `build/conf/local.conf` file: 232 ``` 233 DL_DIR ?= "<path>/<to>/<existing>/downloads" 234 ``` 235* Or create a symbol link: 236 ``` 237 ln -sf <path>/<to>/<existing>/downloads build/downloads 238 ``` 239Then do the build. It will save a lot of time from downloading codes. 240 241## Using git proxy 242If you experience extremely slow download speed during code fetch (e.g. if you 243are in China), it is possible to use a git proxy to speed up the code fetch. 244 245Google `git-proxy-wrapper` will find various ways to setup the proxy for the 246git protocol. 247 248Below is an example wrapper in `~/bin` assuming a socks5 proxy at port 9054: 249``` 250#!/bin/sh 251## Use connect-proxy as git proxy wrapper which supports SOCKS5 252## Install with `apt-get install connect-proxy` 253## Use with `export GIT_PROXY_COMMAND=~/bin/git-proxy-wrapper` 254/usr/bin/connect -S localhost:9054 "$@" 255``` 256Then you can run `export GIT_PROXY_COMMAND=~/bin/git-proxy-wrapper` and you are 257now downloading git code through your proxy. 258 259## devtool 260 261`devtool` is a convenient utility in Yocto to make changes in the local 262directory. 263Typical usage is: 264``` 265# To create a local copy of recipe's code and build with it: 266devtool modify <recipe> 267cd build/workspace/sources/<recipe> # And make changes 268bitbake obmc-phosphor-image # Build with local changes 269 270# After you have finished, reset the recipe to ignore local changes: 271devtool reset <recipe> 272``` 273 274To use this tool, you need the build environment, e.g. `. oe-init-build-env`. 275The above script will add `<WORKDIR>/scripts/` to your `PATH` env and 276`devtool` is in the path. 277 278Below are real examples. 279 280 281### devtool on ipmi 282 283If you want to debug or add a new function in ipmi, you probably need to 284change the code in [phosphor-host-ipmid][1]. 285Checking the recipes, you know this repo is in [phosphor-ipmi-host.bb][2]. 286Below are the steps to use devtool to modify the code locally, build and test 287it. 2881. Use devtool to create a local repo: 289 ``` 290 devtool modify phosphor-ipmi-host 291 ``` 292 devtool clones the repo into `build/workspace/sources/phosphor-ipmi-host`, 293 creates and checkout branch `devtool`. 2942. Make changes in the repo, e.g. adding code to handle new ipmi commands or 295 simply adding trace logs. 2963. Now you can build the whole image or the ipmi recipe itself: 297 ``` 298 bitbake obmc-phosphor-image # Build the whole image 299 bitbake phosphor-ipmi-host # Build the recipe 300 ``` 3014. To test your change, either flash the whole image or replace the changed 302 binary. Note that the changed code is built into `libapphandler.so` and it 303 is used by both host and net ipmi daemon. 304 It is recommended that you copy the changed binary to BMC because it is 305 easier to test: 306 ``` 307 # Replace libapphandler.so.0.0.0 308 scp build/workspace/sources/phosphor-ipmi-host/oe-workdir/package/usr/lib/ipmid-providers/libapphandler.so.0.0.0 root@bmc:/usr/lib/ipmid-providers/ 309 systemctl restart phosphor-ipmi-host.service # Restart the inband ipmi daemon 310 # Or restart phosphor-ipmi-net.service if you want to test net ipmi. 311 ``` 3125. Now you can test your changes. 313 314 315## Develop linux kernel 316 317### devtool on linux kernel 318If you want to work on linux kernel, you can use devtool as well, with some 319differences from regular repos. 320 321**Note**: As of [ac72846][3] the linux kernel recipe name is changed to 322`linux-aspeed` for Aspeed based OpenBMC builds. 323In the following examples, replace `linux-obmc` with `linux-aspeed` if you are 324on a revision later than [ac72846][3]. 325 3261. devtool does not create the 'devtool' branch. Instead, it checkout the 327 branch specified in the recipe. 328 For example, on the OpenBMC v2.2 tag, `linux-obmc_4.13.bb` specifies 329 `dev-4.13` branch. 3302. If there are patches, `devtool` applies them directly on the branch. 3313. devtool copies the defconfig and machine-specific config into `oe-workdir`. 3324. devtool generates the `.config` file based on the above configs. 333 334You can modify the code and build the kernel as usual as follows: 335``` 336bitbake linux-obmc -c build 337``` 338 339### Modify config 340If you need to change the config and save it as defconfig for further use: 341``` 342bitbake linux-obmc -c menuconfig 343# Edit the configs and after save it generates 344# .config.new as the new kernel config 345 346bitbake linux-obmc -c savedefconfig 347# It will save the new defconfig at oe-workdir/linux-obmc-<version>/defconfig 348``` 349 350### Test linux kernel 351After build, you can flash the image to test the new kernel. 352However, it is always slow to flash an image to the chip. 353 354There is a faster way to load the kernel via network so you can easily test 355kernel builds. 356 357OpenBMC kernel build generates `fit` image, including `kernel`, `dtb` and 358`initramfs`. 359Typically we can load it via tftp, taking Romulus as an example: 3601. Put `build/tmp/deploy/images/romulus/fitImage-obmc-phosphor-initramfs-romulus.bin` 361 to a tftp server, name it to `fitImage` 3622. Reboot BMC and press keys to enter uboot shell; 3633. In uboot: 364 ``` 365 setenv ethaddr <mac:addr> # Set mac address if there it is unavailable 366 setenv ipaddr 192.168.0.80 # Set BMC IP 367 setenv serverip 192.168.0.11 # Set tftp server IP 368 tftp 0x83000000 fitImage # Load fit image to ram. Use 0x43000000 on AST2400 369 bootm 0x83000000 # Boot from fit image 370 ``` 371Then you are running an OpenBMC with your updated kernel. 372 373 374[1]: https://github.com/openbmc/phosphor-host-ipmid 375[2]: https://github.com/openbmc/openbmc/blob/c53f375a0f92f847d2aa50e19de54840e8472c8e/meta-phosphor/recipes-phosphor/ipmi/phosphor-ipmi-host_git.bb 376[3]: https://github.com/openbmc/openbmc/commit/ac7284629ea572cf27d69949dc4014b3b226f14f 377