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