1cdfa8079SJeremy Kerr 2cdfa8079SJeremy Kerr# OpenBMC cheatsheet 3cdfa8079SJeremy Kerr 4cdfa8079SJeremy KerrThis document is intended to provide a set of recipes for common OpenBMC 5cdfa8079SJeremy Kerrcustomisation tasks, without having to know the full yocto build process. 6cdfa8079SJeremy Kerr 7cdfa8079SJeremy Kerr## Using a local kernel build 8cdfa8079SJeremy Kerr 9cdfa8079SJeremy KerrThe kernel recipe is in: 10cdfa8079SJeremy Kerr 11cdfa8079SJeremy Kerr``` 12ba2abfa4SYong Li meta-phosphor/common/recipes-kernel/linux/linux-obmc_X.Y.bb 13cdfa8079SJeremy Kerr``` 14cdfa8079SJeremy Kerr 15cdfa8079SJeremy KerrTo use a local git tree, change the `SRC_URI` to a git:// URL without 16267a0d68SZev Weissa hostname, and remove the `protocol=git` parameter. For example: 17cdfa8079SJeremy Kerr 18cdfa8079SJeremy Kerr``` 19267a0d68SZev WeissSRC_URI = "git:///home/jk/devel/linux;branch=${KBRANCH}" 20cdfa8079SJeremy Kerr``` 21cdfa8079SJeremy Kerr 22267a0d68SZev WeissThe `SRCREV` variable can be used to set an explicit git commit, or 23267a0d68SZev Weissset to `"${AUTOREV}"` to use the latest commit in `KBRANCH`. 24cdfa8079SJeremy Kerr 257b22067aSJoel Stanley## Building for Palmetto 26cdfa8079SJeremy Kerr 277b22067aSJoel StanleyThe Palmetto target is `palmetto`. 287b22067aSJoel Stanley 297b22067aSJoel Stanley``` 307b22067aSJoel Stanley$ cd openbmc 31*c1768568SPatrick Williams$ . setup palmetto 3235abff5fSJeremy Kerr$ bitbake obmc-phosphor-image 337b22067aSJoel Stanley``` 347b22067aSJoel Stanley 3567850dd8SGunnar Mills## Building for Zaius 3657812c89SAdi Gangidi 3767850dd8SGunnar MillsThe Zaius target is `zaius`. 3857812c89SAdi Gangidi 3957812c89SAdi Gangidi``` 4057812c89SAdi Gangidi$ cd openbmc 41*c1768568SPatrick Williams$ . setup zaius 4257812c89SAdi Gangidi$ bitbake obmc-phosphor-image 4357812c89SAdi Gangidi``` 4457812c89SAdi Gangidi 45d5afde33SAdriana Kobylak## Building a specific machine configuration 46d5afde33SAdriana Kobylak 47d5afde33SAdriana KobylakIf the system you want to build contains different machine configurations: 48d5afde33SAdriana Kobylak 49*c1768568SPatrick Williams``` 50d5afde33SAdriana Kobylakmeta-<layer>/meta-<system>/conf/machine/machineA.conf 51d5afde33SAdriana Kobylakmeta-<layer>/meta-<system>/conf/machine/machineB.conf 52*c1768568SPatrick Williams``` 53d5afde33SAdriana Kobylak 54*c1768568SPatrick WilliamsYou can specify the machine configuration you want to build by passing the 55*c1768568SPatrick Williamsname to the `setup`. 56d5afde33SAdriana Kobylak 57*c1768568SPatrick Williams``` 58d5afde33SAdriana Kobylak$ cd openbmc 59*c1768568SPatrick Williams$ . setup machineB 60d5afde33SAdriana Kobylak$ bitbake obmc-phosphor-image 61*c1768568SPatrick Williams``` 62d5afde33SAdriana Kobylak 630ea78f3aSChris Austen## Building the OpenBMC SDK 640ea78f3aSChris AustenLooking 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. 650ea78f3aSChris Austen``` 660ea78f3aSChris Austen$ bitbake -c populate_sdk obmc-phosphor-image 67155192f5Scausten$ ./tmp/deploy/sdk/openbmc-phosphor-glibc-x86_64-obmc-phosphor-image-armv5e-toolchain-2.1.sh 680ea78f3aSChris Austen``` 690ea78f3aSChris AustenFollow the prompts. After it has been installed the default to setup your env will be similar to this command 700ea78f3aSChris Austen``` 71155192f5Scausten. /opt/openbmc-phosphor/2.1/environment-setup-armv5e-openbmc-linux-gnueabi 720ea78f3aSChris Austen``` 730ea78f3aSChris Austen 747b22067aSJoel Stanley## Rebuilds & Reconfiguration 757b22067aSJoel Stanley 767b22067aSJoel StanleyYou can reconfigure your build by removing the build/conf dir: 777b22067aSJoel Stanley``` 787b22067aSJoel Stanleyrm -rf build/conf 797b22067aSJoel Stanley``` 80*c1768568SPatrick Williamsand running `setup` again. 818196be3eSJeremy Kerr 82924bc9c1SGunnar Mills## Useful D-Bus CLI tools 838196be3eSJeremy Kerr 848196be3eSJeremy Kerr## `busctl` 858196be3eSJeremy Kerr 868196be3eSJeremy Kerrhttp://www.freedesktop.org/software/systemd/man/busctl.html 878196be3eSJeremy Kerr 88924bc9c1SGunnar MillsGreat tool to issue D-Bus commands via cli. That way you don't have to wait for 898196be3eSJeremy Kerrthe code to hit the path on the system. Great for running commands with QEMU 908196be3eSJeremy Kerrtoo! 918196be3eSJeremy Kerr 928196be3eSJeremy KerrRun as: 938196be3eSJeremy Kerr 948196be3eSJeremy Kerr``` 958196be3eSJeremy Kerrbusctl call <path> <interface> <object> <method> <parameters> 968196be3eSJeremy Kerr``` 978196be3eSJeremy Kerr 988196be3eSJeremy Kerr* \<parameters\> example : sssay "t1" "t2" "t3" 2 2 3 99dd7e9997SAndrew Jeffery 100dd7e9997SAndrew Jeffery## Using QEMU 101dd7e9997SAndrew Jeffery 102dd7e9997SAndrew JefferyQEMU has a palmetto-bmc machine (as of v2.6.0) which implements the core 103dd7e9997SAndrew Jefferydevices to boot a Linux kernel. OpenBMC also [maintains a 104dd7e9997SAndrew Jefferytree](https://github.com/openbmc/qemu) with patches on their way upstream or 105dd7e9997SAndrew Jefferytemporary work-arounds that add to QEMU's capabilities where appropriate. 106dd7e9997SAndrew Jeffery 10781db7dbaSChris Austen``` 10881db7dbaSChris Austenqemu-system-arm -m 256 -M palmetto-bmc -nographic \ 10981db7dbaSChris Austen-drive file=<path>/flash-palmetto,format=raw,if=mtd \ 11081db7dbaSChris Austen-net nic \ 1116d0fb8f8SAndrew Jeffery-net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443,hostname=qemu 11281db7dbaSChris Austen``` 11381db7dbaSChris AustenIf 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... 114dd7e9997SAndrew Jeffery 115dd7e9997SAndrew Jeffery``` 11681db7dbaSChris Austencurl -c cjar -b cjar -k -H "Content-Type: application/json" \ 11781db7dbaSChris Austen-X POST https://localhost:2443/login -d "{\"data\": [ \"root\", \"0penBmc\" ] }" 11881db7dbaSChris Austen``` 11981db7dbaSChris Austenor 12081db7dbaSChris Austen 12181db7dbaSChris Austen``` 12281db7dbaSChris Austenssh -p 2222 root@localhost 123dd7e9997SAndrew Jeffery``` 124dd7e9997SAndrew Jeffery 125dd7e9997SAndrew JefferyTo quit, type `Ctrl-a c` to switch to the QEMU monitor, and then `quit` to exit. 126ae88254cSJoel Stanley 12781db7dbaSChris Austen## Building QEMU 12881db7dbaSChris Austen 12981db7dbaSChris Austen``` 13081db7dbaSChris Austengit clone https://github.com/openbmc/qemu.git 13181db7dbaSChris Austencd qemu 13281db7dbaSChris Austengit submodule update --init dtc 13381db7dbaSChris Austenmkdir build 13481db7dbaSChris Austencd build 13581db7dbaSChris Austen../configure --target-list=arm-softmmu 13681db7dbaSChris Austenmake 13781db7dbaSChris Austen``` 13881db7dbaSChris AustenBuilt file will be located at: ```arm-softmmu/qemu-system-arm``` 13981db7dbaSChris Austen 14081db7dbaSChris Austen### Use a bridge device 14181db7dbaSChris AustenUsing a bridge device requires a bit of root access to set it up. The benefit 14281db7dbaSChris Austenis your qemu session runs in the bridges subnet so no port forwarding is needed. 14381db7dbaSChris AustenThere are packages needed to yourself a virbr0 such as... 14481db7dbaSChris Austen 14581db7dbaSChris Austen``` 14681db7dbaSChris Austenapt-get install libvirt libvirt-bin bridge-utils uml-utilities qemu-system-common 14781db7dbaSChris Austen 14881db7dbaSChris Austenqemu-system-arm -m 256 -M palmetto-bmc -nographic \ 14981db7dbaSChris Austen-drive file=<path>/flash-palmetto,format=raw,if=mtd \ 15081db7dbaSChris Austen-net nic,macaddr=C0:FF:EE:00:00:02,model=ftgmac100 \ 15181db7dbaSChris Austen-net bridge,id=net0,helper=/usr/lib/qemu-bridge-helper,br=virbr0 15281db7dbaSChris Austen``` 15381db7dbaSChris Austen 15481db7dbaSChris AustenThere are some other useful parms like that can redirect the console to another 15581db7dbaSChris Austenwindow. This results in having an easily accessible qemu command session. 15681db7dbaSChris Austen```-monitor stdio -serial pty -nodefaults``` 15781db7dbaSChris Austen 15881db7dbaSChris Austen 159ae88254cSJoel Stanley## Booting the host 160ae88254cSJoel Stanley 161ae88254cSJoel StanleyLogin: 162ae88254cSJoel Stanley``` 16303504a95SGunnar Millscurl -c cjar -k -X POST -H "Content-Type: application/json" -d '{"data": [ "root", "0penBmc" ] }' https://${bmc}/login 164ae88254cSJoel Stanley``` 165ae88254cSJoel Stanley 166ae88254cSJoel StanleyConnect to host console: 167ae88254cSJoel Stanley``` 168ae88254cSJoel Stanleyssh -p 2200 root@bmc 169ae88254cSJoel Stanley``` 170ae88254cSJoel Stanley 171ae88254cSJoel StanleyPower on: 172ae88254cSJoel Stanley``` 173b56bec0dSGunnar Millscurl -c cjar -b cjar -k -H "Content-Type: application/json" -X PUT \ 174b56bec0dSGunnar Mills -d '{"data": "xyz.openbmc_project.State.Host.Transition.On"}' \ 17503504a95SGunnar Mills https://${bmc}/xyz/openbmc_project/state/host0/attr/RequestedHostTransition 176ae88254cSJoel Stanley``` 177246fc994SLei YU 178246fc994SLei YU## GDB 179246fc994SLei YU 180246fc994SLei YU[SDK build](#building-the-openbmc-sdk) provides GDB and debug symbols: 181246fc994SLei YU 182246fc994SLei YU* `$GDB` is available to use once SDK environment is setup 183246fc994SLei YU* Debug symbols are located in `.debug/` directory of each executable 184246fc994SLei YU 185246fc994SLei YUTo use GDB: 186246fc994SLei YU 187246fc994SLei YU1. Setup SDK environment; 188246fc994SLei YU2. Run below GDB commands: 189246fc994SLei YU ``` 190246fc994SLei YU cd <sysroot_of_sdk_build> 191246fc994SLei YU $GDB <relative_path_to_exeutable> <path_to_core_file> 192246fc994SLei YU ``` 193246fc994SLei YU 194246fc994SLei YU## Coredump 195246fc994SLei YU 196246fc994SLei YUBy default coredump is disabled in OpenBMC. To enable coredump: 197246fc994SLei YU``` 198246fc994SLei YUecho '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern 19948ec067cSLei YUulimit -c unlimited 200246fc994SLei YU``` 201246fc994SLei YU 2024635bf2fSPatrick Venture## Cleaning up read-write file system changes 2034635bf2fSPatrick Venture 2044635bf2fSPatrick VentureYou may want to investigate which file(s) are persisting through the overlay 2054635bf2fSPatrick Venturerwfs. To do this, you can list this path and then remove those files which 2064635bf2fSPatrick Ventureyou'd prefer the originals or remove the deletion overlay to restore files. 2074635bf2fSPatrick Venture 2084635bf2fSPatrick Venture``` 2094635bf2fSPatrick Venture/run/initramfs/rw/cow/ 2104635bf2fSPatrick Venture``` 211e94a168cSLei YU 212e94a168cSLei YU## Building 213e94a168cSLei YU 214e94a168cSLei YU### Share downloads directory 215e94a168cSLei YUIt takes a long time for the first build of OpenBMC. It downloads various repos 216e94a168cSLei YUfrom the internet. 217e94a168cSLei YU 218e94a168cSLei YUCheck `build/downloads` to see all the downloaded repos. 219e94a168cSLei YU 220e94a168cSLei YU* If a repo is a single archive, it usually looks like this: 221e94a168cSLei YU * `zlib-1.2.11.tar.xz` - The repo itself 222e94a168cSLei YU * `zlib-1.2.11.tar.xz.done` - A flag indicating the repo is downloaded 223e94a168cSLei YU* If a repo is managed by git, it usually looks like this: 224e94a168cSLei YU * `git2/github.com.openbmc.linux` - The git bare clone 225e94a168cSLei YU * `git2/github.com.openbmc.linux.done` - A flag indicating the repo is downloaded 226e94a168cSLei YU 227e94a168cSLei YUBitbake will extract the code to the working directory during build, so the 228e94a168cSLei YU`downloads` directory could be shared by different builds on a system: 229e94a168cSLei YU 230e94a168cSLei YU* Set `DL_DIR` Bitbake environment variable to the location of your shared 231e94a168cSLei YU downloads directory by editing the `build/conf/local.conf` file: 232e94a168cSLei YU ``` 233e94a168cSLei YU DL_DIR ?= "<path>/<to>/<existing>/downloads" 234e94a168cSLei YU ``` 235e94a168cSLei YU* Or create a symbol link: 236e94a168cSLei YU ``` 237e94a168cSLei YU ln -sf <path>/<to>/<existing>/downloads build/downloads 238e94a168cSLei YU ``` 239e94a168cSLei YUThen do the build. It will save a lot of time from downloading codes. 240e94a168cSLei YU 241e94a168cSLei YU## Using git proxy 242e94a168cSLei YUIf you experience extremely slow download speed during code fetch (e.g. if you 243e94a168cSLei YUare in China), it is possible to use a git proxy to speed up the code fetch. 244e94a168cSLei YU 245e94a168cSLei YUGoogle `git-proxy-wrapper` will find various ways to setup the proxy for the 246e94a168cSLei YUgit protocol. 247e94a168cSLei YU 248e94a168cSLei YUBelow is an example wrapper in `~/bin` assuming a socks5 proxy at port 9054: 249e94a168cSLei YU``` 250e94a168cSLei YU#!/bin/sh 251e94a168cSLei YU## Use connect-proxy as git proxy wrapper which supports SOCKS5 252e94a168cSLei YU## Install with `apt-get install connect-proxy` 253e94a168cSLei YU## Use with `export GIT_PROXY_COMMAND=~/bin/git-proxy-wrapper` 254e94a168cSLei YU/usr/bin/connect -S localhost:9054 "$@" 255e94a168cSLei YU``` 256e94a168cSLei YUThen you can run `export GIT_PROXY_COMMAND=~/bin/git-proxy-wrapper` and you are 257e94a168cSLei YUnow downloading git code through your proxy. 258e94a168cSLei YU 259e94a168cSLei YU## devtool 260e94a168cSLei YU 261e94a168cSLei YU`devtool` is a convenient utility in Yocto to make changes in the local 262e94a168cSLei YUdirectory. 263e94a168cSLei YUTypical usage is: 264e94a168cSLei YU``` 265e94a168cSLei YU# To create a local copy of recipe's code and build with it: 266e94a168cSLei YUdevtool modify <recipe> 267e94a168cSLei YUcd build/workspace/sources/<recipe> # And make changes 268e94a168cSLei YUbitbake obmc-phosphor-image # Build with local changes 269e94a168cSLei YU 270e94a168cSLei YU# After you have finished, reset the recipe to ignore local changes: 271e94a168cSLei YUdevtool reset <recipe> 272e94a168cSLei YU``` 273e94a168cSLei YU 274e94a168cSLei YUTo use this tool, you need the build environment, e.g. `. oe-init-build-env`. 275e94a168cSLei YUThe above script will add `<WORKDIR>/scripts/` to your `PATH` env and 276e94a168cSLei YU`devtool` is in the path. 277e94a168cSLei YU 278e94a168cSLei YUBelow are real examples. 279e94a168cSLei YU 280e94a168cSLei YU 281e94a168cSLei YU### devtool on ipmi 282e94a168cSLei YU 283e94a168cSLei YUIf you want to debug or add a new function in ipmi, you probably need to 284e94a168cSLei YUchange the code in [phosphor-host-ipmid][1]. 285e94a168cSLei YUChecking the recipes, you know this repo is in [phosphor-ipmi-host.bb][2]. 286e94a168cSLei YUBelow are the steps to use devtool to modify the code locally, build and test 287e94a168cSLei YUit. 288e94a168cSLei YU1. Use devtool to create a local repo: 289e94a168cSLei YU ``` 290e94a168cSLei YU devtool modify phosphor-ipmi-host 291e94a168cSLei YU ``` 292e94a168cSLei YU devtool clones the repo into `build/workspace/sources/phosphor-ipmi-host`, 293e94a168cSLei YU creates and checkout branch `devtool`. 294e94a168cSLei YU2. Make changes in the repo, e.g. adding code to handle new ipmi commands or 295e94a168cSLei YU simply adding trace logs. 296e94a168cSLei YU3. Now you can build the whole image or the ipmi recipe itself: 297e94a168cSLei YU ``` 298e94a168cSLei YU bitbake obmc-phosphor-image # Build the whole image 299e94a168cSLei YU bitbake phosphor-ipmi-host # Build the recipe 300e94a168cSLei YU ``` 301e94a168cSLei YU4. To test your change, either flash the whole image or replace the changed 302e94a168cSLei YU binary. Note that the changed code is built into `libapphandler.so` and it 303e94a168cSLei YU is used by both host and net ipmi daemon. 304e94a168cSLei YU It is recommended that you copy the changed binary to BMC because it is 305e94a168cSLei YU easier to test: 306e94a168cSLei YU ``` 307e94a168cSLei YU # Replace libapphandler.so.0.0.0 308e94a168cSLei YU 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/ 309e94a168cSLei YU systemctl restart phosphor-ipmi-host.service # Restart the inband ipmi daemon 310e94a168cSLei YU # Or restart phosphor-ipmi-net.service if you want to test net ipmi. 311e94a168cSLei YU ``` 312e94a168cSLei YU5. Now you can test your changes. 313e94a168cSLei YU 314e94a168cSLei YU 315e94a168cSLei YU## Develop linux kernel 316e94a168cSLei YU 317e94a168cSLei YU### devtool on linux kernel 318e94a168cSLei YUIf you want to work on linux kernel, you can use devtool as well, with some 319e94a168cSLei YUdifferences from regular repos. 320e94a168cSLei YU 321e94a168cSLei YU**Note**: As of [ac72846][3] the linux kernel recipe name is changed to 322e94a168cSLei YU`linux-aspeed` for Aspeed based OpenBMC builds. 323e94a168cSLei YUIn the following examples, replace `linux-obmc` with `linux-aspeed` if you are 324e94a168cSLei YUon a revision later than [ac72846][3]. 325e94a168cSLei YU 326e94a168cSLei YU1. devtool does not create the 'devtool' branch. Instead, it checkout the 327e94a168cSLei YU branch specified in the recipe. 328e94a168cSLei YU For example, on the OpenBMC v2.2 tag, `linux-obmc_4.13.bb` specifies 329e94a168cSLei YU `dev-4.13` branch. 330e94a168cSLei YU2. If there are patches, `devtool` applies them directly on the branch. 331e94a168cSLei YU3. devtool copies the defconfig and machine-specific config into `oe-workdir`. 332e94a168cSLei YU4. devtool generates the `.config` file based on the above configs. 333e94a168cSLei YU 334e94a168cSLei YUYou can modify the code and build the kernel as usual as follows: 335e94a168cSLei YU``` 336e94a168cSLei YUbitbake linux-obmc -c build 337e94a168cSLei YU``` 338e94a168cSLei YU 339e94a168cSLei YU### Modify config 340e94a168cSLei YUIf you need to change the config and save it as defconfig for further use: 341e94a168cSLei YU``` 342e94a168cSLei YUbitbake linux-obmc -c menuconfig 343e94a168cSLei YU# Edit the configs and after save it generates 344e94a168cSLei YU# .config.new as the new kernel config 345e94a168cSLei YU 346e94a168cSLei YUbitbake linux-obmc -c savedefconfig 347e94a168cSLei YU# It will save the new defconfig at oe-workdir/linux-obmc-<version>/defconfig 348e94a168cSLei YU``` 349e94a168cSLei YU 350e94a168cSLei YU### Test linux kernel 351e94a168cSLei YUAfter build, you can flash the image to test the new kernel. 352e94a168cSLei YUHowever, it is always slow to flash an image to the chip. 353e94a168cSLei YU 354e94a168cSLei YUThere is a faster way to load the kernel via network so you can easily test 355e94a168cSLei YUkernel builds. 356e94a168cSLei YU 357e94a168cSLei YUOpenBMC kernel build generates `fit` image, including `kernel`, `dtb` and 358e94a168cSLei YU`initramfs`. 359e94a168cSLei YUTypically we can load it via tftp, taking Romulus as an example: 360e94a168cSLei YU1. Put `build/tmp/deploy/images/romulus/fitImage-obmc-phosphor-initramfs-romulus.bin` 361e94a168cSLei YU to a tftp server, name it to `fitImage` 362e94a168cSLei YU2. Reboot BMC and press keys to enter uboot shell; 363e94a168cSLei YU3. In uboot: 364e94a168cSLei YU ``` 365e94a168cSLei YU setenv ethaddr <mac:addr> # Set mac address if there it is unavailable 366e94a168cSLei YU setenv ipaddr 192.168.0.80 # Set BMC IP 367e94a168cSLei YU setenv serverip 192.168.0.11 # Set tftp server IP 368e94a168cSLei YU tftp 0x83000000 fitImage # Load fit image to ram. Use 0x43000000 on AST2400 369e94a168cSLei YU bootm 0x83000000 # Boot from fit image 370e94a168cSLei YU ``` 371e94a168cSLei YUThen you are running an OpenBMC with your updated kernel. 372e94a168cSLei YU 373e94a168cSLei YU 374e94a168cSLei YU[1]: https://github.com/openbmc/phosphor-host-ipmid 375e94a168cSLei YU[2]: https://github.com/openbmc/openbmc/blob/c53f375a0f92f847d2aa50e19de54840e8472c8e/meta-phosphor/recipes-phosphor/ipmi/phosphor-ipmi-host_git.bb 376e94a168cSLei YU[3]: https://github.com/openbmc/openbmc/commit/ac7284629ea572cf27d69949dc4014b3b226f14f 377