xref: /openbmc/docs/cheatsheet.md (revision 22319395)
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```
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```
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```
29$ cd openbmc
30$ . setup palmetto
31$ bitbake obmc-phosphor-image
32```
33
34## Building for Zaius
35
36The Zaius target is `zaius`.
37
38```
39$ cd openbmc
40$ . setup zaius
41$ bitbake 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```
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```
57$ cd openbmc
58$ . setup machineB
59$ bitbake 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```
69$ bitbake -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```
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```
85rm -rf build/conf
86```
87
88and running `setup` again.
89
90## Useful D-Bus CLI tools
91
92## `busctl`
93
94http://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```
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```
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```
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```
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```
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```
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```
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```
184ssh -p 2200 root@bmc
185```
186
187Power on:
188
189```
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   cd <sysroot_of_sdk_build>
208   $GDB <relative_path_to_exeutable> <path_to_core_file>
209   ```
210
211## Coredump
212
213By default coredump is disabled in OpenBMC. To enable coredump:
214
215```
216echo '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
217ulimit -c unlimited
218```
219
220## Cleaning up read-write file system changes
221
222You may want to investigate which file(s) are persisting through the overlay
223rwfs. To do this, you can list this path and then remove those files which you'd
224prefer the originals or remove the deletion overlay to restore files.
225
226```
227/run/initramfs/rw/cow/
228```
229
230## Building
231
232### Share downloads directory
233
234It takes a long time for the first build of OpenBMC. It downloads various repos
235from the internet.
236
237Check `build/downloads` to see all the downloaded repos.
238
239- If a repo is a single archive, it usually looks like this:
240  - `zlib-1.2.11.tar.xz` - The repo itself
241  - `zlib-1.2.11.tar.xz.done` - A flag indicating the repo is downloaded
242- If a repo is managed by git, it usually looks like this:
243  - `git2/github.com.openbmc.linux` - The git bare clone
244  - `git2/github.com.openbmc.linux.done` - A flag indicating the repo is
245    downloaded
246
247Bitbake will extract the code to the working directory during build, so the
248`downloads` directory could be shared by different builds on a system:
249
250- Set `DL_DIR` Bitbake environment variable to the location of your shared
251  downloads directory by editing the `build/conf/local.conf` file:
252  ```
253  DL_DIR ?= "<path>/<to>/<existing>/downloads"
254  ```
255- Or create a symbol link:
256  ```
257  ln -sf <path>/<to>/<existing>/downloads build/downloads
258  ```
259  Then do the build. It will save a lot of time from downloading codes.
260
261## Using git proxy
262
263If you experience extremely slow download speed during code fetch (e.g. if you
264are in China), it is possible to use a git proxy to speed up the code fetch.
265
266Google `git-proxy-wrapper` will find various ways to setup the proxy for the git
267protocol.
268
269Below is an example wrapper in `~/bin` assuming a socks5 proxy at port 9054:
270
271```
272#!/bin/sh
273## Use connect-proxy as git proxy wrapper which supports SOCKS5
274## Install with `apt-get install connect-proxy`
275## Use with `export GIT_PROXY_COMMAND=~/bin/git-proxy-wrapper`
276/usr/bin/connect -S localhost:9054 "$@"
277```
278
279Then you can run `export GIT_PROXY_COMMAND=~/bin/git-proxy-wrapper` and you are
280now downloading git code through your proxy.
281
282## devtool
283
284`devtool` is a convenient utility in Yocto to make changes in the local
285directory. Typical usage is:
286
287```
288# To create a local copy of recipe's code and build with it:
289devtool modify <recipe>
290cd build/workspace/sources/<recipe>  # And make changes
291bitbake obmc-phosphor-image  # Build with local changes
292
293# After you have finished, reset the recipe to ignore local changes:
294devtool reset <recipe>
295```
296
297To use this tool, you need the build environment, e.g. `. oe-init-build-env`.
298The above script will add `<WORKDIR>/scripts/` to your `PATH` env and `devtool`
299is in the path.
300
301Below are real examples.
302
303### devtool on ipmi
304
305If you want to debug or add a new function in ipmi, you probably need to change
306the code in [phosphor-host-ipmid][1]. Checking the recipes, you know this repo
307is in [phosphor-ipmi-host.bb][2]. Below are the steps to use devtool to modify
308the code locally, build and test it.
309
3101. Use devtool to create a local repo:
311   ```
312   devtool modify phosphor-ipmi-host
313   ```
314   devtool clones the repo into `build/workspace/sources/phosphor-ipmi-host`,
315   creates and checkout branch `devtool`.
3162. Make changes in the repo, e.g. adding code to handle new ipmi commands or
317   simply adding trace logs.
3183. Now you can build the whole image or the ipmi recipe itself:
319   ```
320   bitbake obmc-phosphor-image  # Build the whole image
321   bitbake phosphor-ipmi-host  # Build the recipe
322   ```
3234. To test your change, either flash the whole image or replace the changed
324   binary. Note that the changed code is built into `libapphandler.so` and it is
325   used by both host and net ipmi daemon. It is recommended that you copy the
326   changed binary to BMC because it is easier to test:
327   ```
328   # Replace libapphandler.so.0.0.0
329   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/
330   systemctl restart phosphor-ipmi-host.service  # Restart the inband ipmi daemon
331   # Or restart phosphor-ipmi-net.service if you want to test net ipmi.
332   ```
3335. Now you can test your changes.
334
335## Develop linux kernel
336
337### devtool on linux kernel
338
339If you want to work on linux kernel, you can use devtool as well, with some
340differences from regular repos.
341
342**Note**: As of [ac72846][3] the linux kernel recipe name is changed to
343`linux-aspeed` for Aspeed based OpenBMC builds. In the following examples,
344replace `linux-obmc` with `linux-aspeed` if you are on a revision later than
345[ac72846][3].
346
3471. devtool does not create the 'devtool' branch. Instead, it checkout the branch
348   specified in the recipe. For example, on the OpenBMC v2.2 tag,
349   `linux-obmc_4.13.bb` specifies `dev-4.13` branch.
3502. If there are patches, `devtool` applies them directly on the branch.
3513. devtool copies the defconfig and machine-specific config into `oe-workdir`.
3524. devtool generates the `.config` file based on the above configs.
353
354You can modify the code and build the kernel as usual as follows:
355
356```
357bitbake linux-obmc -c build
358```
359
360### Modify config
361
362If you need to change the config and save it as defconfig for further use:
363
364```
365bitbake linux-obmc -c menuconfig
366# Edit the configs and after save it generates
367# .config.new as the new kernel config
368
369bitbake linux-obmc -c savedefconfig
370# It will save the new defconfig at oe-workdir/linux-obmc-<version>/defconfig
371```
372
373### Test linux kernel
374
375After build, you can flash the image to test the new kernel. However, it is
376always slow to flash an image to the chip.
377
378There is a faster way to load the kernel via network so you can easily test
379kernel builds.
380
381OpenBMC kernel build generates `fit` image, including `kernel`, `dtb` and
382`initramfs`. Typically we can load it via tftp, taking Romulus as an example:
383
3841. Put
385   `build/tmp/deploy/images/romulus/fitImage-obmc-phosphor-initramfs-romulus.bin`
386   to a tftp server, name it to `fitImage`
3872. Reboot BMC and press keys to enter uboot shell;
3883. In uboot:
389   ```
390   setenv ethaddr <mac:addr>  # Set mac address if there it is unavailable
391   setenv ipaddr 192.168.0.80  # Set BMC IP
392   setenv serverip 192.168.0.11  # Set tftp server IP
393   tftp 0x83000000 fitImage  # Load fit image to ram. Use 0x43000000 on AST2400
394   bootm 0x83000000  # Boot from fit image
395   ```
396   Then you are running an OpenBMC with your updated kernel.
397
398[1]: https://github.com/openbmc/phosphor-host-ipmid
399[2]:
400  https://github.com/openbmc/openbmc/blob/c53f375a0f92f847d2aa50e19de54840e8472c8e/meta-phosphor/recipes-phosphor/ipmi/phosphor-ipmi-host_git.bb
401[3]:
402  https://github.com/openbmc/openbmc/commit/ac7284629ea572cf27d69949dc4014b3b226f14f
403