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