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``` 12cdfa8079SJeremy Kerr meta-phosphor/common/recipes-kernel/linux/linux-obmc_4.2.bb 13cdfa8079SJeremy Kerr``` 14cdfa8079SJeremy Kerr 15cdfa8079SJeremy KerrTo use a local git tree, change the `SRC_URI` to a git:// URL without 16cdfa8079SJeremy Kerra hostname. For example: 17cdfa8079SJeremy Kerr 18cdfa8079SJeremy Kerr``` 19cdfa8079SJeremy KerrSRC_URI = "git:///home/jk/devel/linux;protocol=git;branch=${KBRANCH}" 20cdfa8079SJeremy Kerr``` 21cdfa8079SJeremy Kerr 22cdfa8079SJeremy KerrThe `SRCREV` variable can be used to set an explicit git commit. The 23cdfa8079SJeremy Kerrdefault (`${AUTOREV}`) will use the latest commit in `KBRANCH`. 24cdfa8079SJeremy Kerr 257b22067aSJoel Stanley## Building for Palmetto 26cdfa8079SJeremy Kerr 277b22067aSJoel StanleyThe Palmetto target is `palmetto`. 287b22067aSJoel Stanley 297b22067aSJoel StanleyIf you are starting from scratch without a `build/conf` directory you can just: 307b22067aSJoel Stanley``` 317b22067aSJoel Stanley$ cd openbmc 32f6b9fe0eSAdriana Kobylak$ TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-ibm/meta-palmetto/conf . openbmc-env 3335abff5fSJeremy Kerr$ bitbake obmc-phosphor-image 347b22067aSJoel Stanley``` 357b22067aSJoel Stanley 3657812c89SAdi Gangidi## Building for Barreleye 3757812c89SAdi Gangidi 3857812c89SAdi GangidiThe Barreleye target is `barreleye`. 3957812c89SAdi Gangidi 4057812c89SAdi GangidiIf you are starting from scratch without a `build/conf` directory you can just: 4157812c89SAdi Gangidi``` 4257812c89SAdi Gangidi$ cd openbmc 43f6b9fe0eSAdriana Kobylak$ TEMPLATECONF=meta-openbmc-machines/meta-openpower/meta-rackspace/meta-barreleye/conf . openbmc-env 4457812c89SAdi Gangidi$ bitbake obmc-phosphor-image 4557812c89SAdi Gangidi``` 4657812c89SAdi Gangidi 470ea78f3aSChris Austen## Building the OpenBMC SDK 480ea78f3aSChris 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. 490ea78f3aSChris Austen``` 500ea78f3aSChris Austen$ bitbake -c populate_sdk obmc-phosphor-image 51155192f5Scausten$ ./tmp/deploy/sdk/openbmc-phosphor-glibc-x86_64-obmc-phosphor-image-armv5e-toolchain-2.1.sh 520ea78f3aSChris Austen``` 530ea78f3aSChris AustenFollow the prompts. After it has been installed the default to setup your env will be similar to this command 540ea78f3aSChris Austen``` 55155192f5Scausten. /opt/openbmc-phosphor/2.1/environment-setup-armv5e-openbmc-linux-gnueabi 560ea78f3aSChris Austen``` 570ea78f3aSChris Austen 587b22067aSJoel Stanley## Rebuilds & Reconfiguration 597b22067aSJoel Stanley 607b22067aSJoel StanleyYou can reconfigure your build by removing the build/conf dir: 617b22067aSJoel Stanley``` 627b22067aSJoel Stanleyrm -rf build/conf 637b22067aSJoel Stanley``` 64f6b9fe0eSAdriana Kobylakand running `openbmc-env` again (possibly with `TEMPLATECONF` set). 658196be3eSJeremy Kerr 66924bc9c1SGunnar Mills## Useful D-Bus CLI tools 678196be3eSJeremy Kerr 688196be3eSJeremy Kerr## `busctl` 698196be3eSJeremy Kerr 708196be3eSJeremy Kerrhttp://www.freedesktop.org/software/systemd/man/busctl.html 718196be3eSJeremy Kerr 72924bc9c1SGunnar MillsGreat tool to issue D-Bus commands via cli. That way you don't have to wait for 738196be3eSJeremy Kerrthe code to hit the path on the system. Great for running commands with QEMU 748196be3eSJeremy Kerrtoo! 758196be3eSJeremy Kerr 768196be3eSJeremy KerrRun as: 778196be3eSJeremy Kerr 788196be3eSJeremy Kerr``` 798196be3eSJeremy Kerrbusctl call <path> <interface> <object> <method> <parameters> 808196be3eSJeremy Kerr``` 818196be3eSJeremy Kerr 828196be3eSJeremy Kerr* \<parameters\> example : sssay "t1" "t2" "t3" 2 2 3 83dd7e9997SAndrew Jeffery 84dd7e9997SAndrew Jeffery## Using QEMU 85dd7e9997SAndrew Jeffery 86dd7e9997SAndrew JefferyQEMU has a palmetto-bmc machine (as of v2.6.0) which implements the core 87dd7e9997SAndrew Jefferydevices to boot a Linux kernel. OpenBMC also [maintains a 88dd7e9997SAndrew Jefferytree](https://github.com/openbmc/qemu) with patches on their way upstream or 89dd7e9997SAndrew Jefferytemporary work-arounds that add to QEMU's capabilities where appropriate. 90dd7e9997SAndrew Jeffery 9181db7dbaSChris Austen``` 9281db7dbaSChris Austenqemu-system-arm -m 256 -M palmetto-bmc -nographic \ 9381db7dbaSChris Austen-drive file=<path>/flash-palmetto,format=raw,if=mtd \ 9481db7dbaSChris Austen-net nic \ 9581db7dbaSChris Austen-net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443,hostname=qemu \ 9681db7dbaSChris Austen``` 9781db7dbaSChris 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... 98dd7e9997SAndrew Jeffery 99dd7e9997SAndrew Jeffery``` 10081db7dbaSChris Austencurl -c cjar -b cjar -k -H "Content-Type: application/json" \ 10181db7dbaSChris Austen-X POST https://localhost:2443/login -d "{\"data\": [ \"root\", \"0penBmc\" ] }" 10281db7dbaSChris Austen``` 10381db7dbaSChris Austenor 10481db7dbaSChris Austen 10581db7dbaSChris Austen``` 10681db7dbaSChris Austenssh -p 2222 root@localhost 107dd7e9997SAndrew Jeffery``` 108dd7e9997SAndrew Jeffery 109dd7e9997SAndrew JefferyTo quit, type `Ctrl-a c` to switch to the QEMU monitor, and then `quit` to exit. 110ae88254cSJoel Stanley 11181db7dbaSChris Austen## Building QEMU 11281db7dbaSChris Austen 11381db7dbaSChris Austen``` 11481db7dbaSChris Austengit clone https://github.com/openbmc/qemu.git 11581db7dbaSChris Austencd qemu 11681db7dbaSChris Austengit submodule update --init dtc 11781db7dbaSChris Austenmkdir build 11881db7dbaSChris Austencd build 11981db7dbaSChris Austen../configure --target-list=arm-softmmu 12081db7dbaSChris Austenmake 12181db7dbaSChris Austen``` 12281db7dbaSChris AustenBuilt file will be located at: ```arm-softmmu/qemu-system-arm``` 12381db7dbaSChris Austen 12481db7dbaSChris Austen### Use a bridge device 12581db7dbaSChris AustenUsing a bridge device requires a bit of root access to set it up. The benefit 12681db7dbaSChris Austenis your qemu session runs in the bridges subnet so no port forwarding is needed. 12781db7dbaSChris AustenThere are packages needed to yourself a virbr0 such as... 12881db7dbaSChris Austen 12981db7dbaSChris Austen``` 13081db7dbaSChris Austenapt-get install libvirt libvirt-bin bridge-utils uml-utilities qemu-system-common 13181db7dbaSChris Austen 13281db7dbaSChris Austenqemu-system-arm -m 256 -M palmetto-bmc -nographic \ 13381db7dbaSChris Austen-drive file=<path>/flash-palmetto,format=raw,if=mtd \ 13481db7dbaSChris Austen-net nic,macaddr=C0:FF:EE:00:00:02,model=ftgmac100 \ 13581db7dbaSChris Austen-net bridge,id=net0,helper=/usr/lib/qemu-bridge-helper,br=virbr0 13681db7dbaSChris Austen``` 13781db7dbaSChris Austen 13881db7dbaSChris AustenThere are some other useful parms like that can redirect the console to another 13981db7dbaSChris Austenwindow. This results in having an easily accessible qemu command session. 14081db7dbaSChris Austen```-monitor stdio -serial pty -nodefaults``` 14181db7dbaSChris Austen 14281db7dbaSChris Austen 143ae88254cSJoel Stanley## Booting the host 144ae88254cSJoel Stanley 145ae88254cSJoel StanleyLogin: 146ae88254cSJoel Stanley``` 147*b56bec0dSGunnar Millscurl -c cjar -k -X POST -H "Content-Type: application/json" -d '{"data": [ "root", "0penBmc" ] }' https://bmc/login 148ae88254cSJoel Stanley``` 149ae88254cSJoel Stanley 150ae88254cSJoel StanleyConnect to host console: 151ae88254cSJoel Stanley``` 152ae88254cSJoel Stanleyssh -p 2200 root@bmc 153ae88254cSJoel Stanley``` 154ae88254cSJoel Stanley 155ae88254cSJoel StanleyPower on: 156ae88254cSJoel Stanley``` 157*b56bec0dSGunnar Millscurl -c cjar -b cjar -k -H "Content-Type: application/json" -X PUT \ 158*b56bec0dSGunnar Mills -d '{"data": "xyz.openbmc_project.State.Host.Transition.On"}' \ 159*b56bec0dSGunnar Mills https://bmc/xyz/openbmc_project/state/host0/attr/RequestedHostTransition 160ae88254cSJoel Stanley``` 161246fc994SLei YU 162246fc994SLei YU## GDB 163246fc994SLei YU 164246fc994SLei YU[SDK build](#building-the-openbmc-sdk) provides GDB and debug symbols: 165246fc994SLei YU 166246fc994SLei YU* `$GDB` is available to use once SDK environment is setup 167246fc994SLei YU* Debug symbols are located in `.debug/` directory of each executable 168246fc994SLei YU 169246fc994SLei YUTo use GDB: 170246fc994SLei YU 171246fc994SLei YU1. Setup SDK environment; 172246fc994SLei YU2. Run below GDB commands: 173246fc994SLei YU ``` 174246fc994SLei YU cd <sysroot_of_sdk_build> 175246fc994SLei YU $GDB <relative_path_to_exeutable> <path_to_core_file> 176246fc994SLei YU ``` 177246fc994SLei YU 178246fc994SLei YU## Coredump 179246fc994SLei YU 180246fc994SLei YUBy default coredump is disabled in OpenBMC. To enable coredump: 181246fc994SLei YU``` 182246fc994SLei YUecho '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern 183246fc994SLei YU``` 184246fc994SLei YU 1854635bf2fSPatrick Venture## Cleaning up read-write file system changes 1864635bf2fSPatrick Venture 1874635bf2fSPatrick VentureYou may want to investigate which file(s) are persisting through the overlay 1884635bf2fSPatrick Venturerwfs. To do this, you can list this path and then remove those files which 1894635bf2fSPatrick Ventureyou'd prefer the originals or remove the deletion overlay to restore files. 1904635bf2fSPatrick Venture 1914635bf2fSPatrick Venture``` 1924635bf2fSPatrick Venture/run/initramfs/rw/cow/ 1934635bf2fSPatrick Venture``` 194