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