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