xref: /openbmc/docs/cheatsheet.md (revision c7c7c866)
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
183```
184
185## Cleaning up read-write file system changes
186
187You may want to investigate which file(s) are persisting through the overlay
188rwfs.  To do this, you can list this path and then remove those files which
189you'd prefer the originals or remove the deletion overlay to restore files.
190
191```
192/run/initramfs/rw/cow/
193```
194