xref: /openbmc/docs/cheatsheet.md (revision 6d0fb8f853c8d6d546c249c46cab9f1805cc2425)
1cdfa8079SJeremy Kerr
2cdfa8079SJeremy Kerr# OpenBMC cheatsheet
3cdfa8079SJeremy Kerr
4cdfa8079SJeremy KerrThis document is intended to provide a set of recipes for common OpenBMC
5cdfa8079SJeremy Kerrcustomisation tasks, without having to know the full yocto build process.
6cdfa8079SJeremy Kerr
7cdfa8079SJeremy Kerr## Using a local kernel build
8cdfa8079SJeremy Kerr
9cdfa8079SJeremy KerrThe kernel recipe is in:
10cdfa8079SJeremy Kerr
11cdfa8079SJeremy Kerr```
12ba2abfa4SYong Li meta-phosphor/common/recipes-kernel/linux/linux-obmc_X.Y.bb
13cdfa8079SJeremy Kerr```
14cdfa8079SJeremy Kerr
15cdfa8079SJeremy KerrTo use a local git tree, change the `SRC_URI` to a git:// URL without
16267a0d68SZev Weissa hostname, and remove the `protocol=git` parameter. For example:
17cdfa8079SJeremy Kerr
18cdfa8079SJeremy Kerr```
19267a0d68SZev WeissSRC_URI = "git:///home/jk/devel/linux;branch=${KBRANCH}"
20cdfa8079SJeremy Kerr```
21cdfa8079SJeremy Kerr
22267a0d68SZev WeissThe `SRCREV` variable can be used to set an explicit git commit, or
23267a0d68SZev Weissset to `"${AUTOREV}"` to use the latest commit in `KBRANCH`.
24cdfa8079SJeremy Kerr
257b22067aSJoel Stanley## Building for Palmetto
26cdfa8079SJeremy Kerr
277b22067aSJoel StanleyThe Palmetto target is `palmetto`.
287b22067aSJoel Stanley
297b22067aSJoel StanleyIf you are starting from scratch without a `build/conf` directory you can just:
307b22067aSJoel Stanley```
317b22067aSJoel Stanley$ cd openbmc
32873a0495SAdriana Kobylak$ TEMPLATECONF=meta-ibm/meta-palmetto/conf . openbmc-env
3335abff5fSJeremy Kerr$ bitbake obmc-phosphor-image
347b22067aSJoel Stanley```
357b22067aSJoel Stanley
3667850dd8SGunnar Mills## Building for Zaius
3757812c89SAdi Gangidi
3867850dd8SGunnar MillsThe Zaius target is `zaius`.
3957812c89SAdi Gangidi
4057812c89SAdi GangidiIf you are starting from scratch without a `build/conf` directory you can just:
4157812c89SAdi Gangidi```
4257812c89SAdi Gangidi$ cd openbmc
43873a0495SAdriana Kobylak$ TEMPLATECONF=meta-ingrasys/meta-zaius/conf . openbmc-env
4457812c89SAdi Gangidi$ bitbake obmc-phosphor-image
4557812c89SAdi Gangidi```
4657812c89SAdi Gangidi
47d5afde33SAdriana Kobylak## Building a specific machine configuration
48d5afde33SAdriana Kobylak
49d5afde33SAdriana KobylakIf the system you want to build contains different machine configurations:
50d5afde33SAdriana Kobylak
51d5afde33SAdriana Kobylak    meta-<layer>/meta-<system>/conf/machine/machineA.conf
52d5afde33SAdriana Kobylak    meta-<layer>/meta-<system>/conf/machine/machineB.conf
53d5afde33SAdriana Kobylak
54d5afde33SAdriana KobylakYou can specify the machine configuration you want to build by setting the
55fc72bba5SPatrick VentureMACHINE environment variable.
56d5afde33SAdriana Kobylak
57d5afde33SAdriana Kobylak    $ cd openbmc
58d5afde33SAdriana Kobylak    $ TEMPLATECONF=meta-<layer>/meta-<system>/conf . openbmc-env
59d5afde33SAdriana Kobylak    $ export MACHINE="machineB"
60d5afde33SAdriana Kobylak    $ bitbake obmc-phosphor-image
61d5afde33SAdriana Kobylak
620ea78f3aSChris Austen## Building the OpenBMC SDK
630ea78f3aSChris AustenLooking 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.
640ea78f3aSChris Austen```
650ea78f3aSChris Austen$ bitbake -c populate_sdk obmc-phosphor-image
66155192f5Scausten$ ./tmp/deploy/sdk/openbmc-phosphor-glibc-x86_64-obmc-phosphor-image-armv5e-toolchain-2.1.sh
670ea78f3aSChris Austen```
680ea78f3aSChris AustenFollow the prompts.  After it has been installed the default to setup your env will be similar to this command
690ea78f3aSChris Austen```
70155192f5Scausten. /opt/openbmc-phosphor/2.1/environment-setup-armv5e-openbmc-linux-gnueabi
710ea78f3aSChris Austen```
720ea78f3aSChris Austen
737b22067aSJoel Stanley## Rebuilds & Reconfiguration
747b22067aSJoel Stanley
757b22067aSJoel StanleyYou can reconfigure your build by removing the build/conf dir:
767b22067aSJoel Stanley```
777b22067aSJoel Stanleyrm -rf build/conf
787b22067aSJoel Stanley```
79f6b9fe0eSAdriana Kobylakand running `openbmc-env` again (possibly with `TEMPLATECONF` set).
808196be3eSJeremy Kerr
81924bc9c1SGunnar Mills## Useful D-Bus CLI tools
828196be3eSJeremy Kerr
838196be3eSJeremy Kerr## `busctl`
848196be3eSJeremy Kerr
858196be3eSJeremy Kerrhttp://www.freedesktop.org/software/systemd/man/busctl.html
868196be3eSJeremy Kerr
87924bc9c1SGunnar MillsGreat tool to issue D-Bus commands via cli. That way you don't have to wait for
888196be3eSJeremy Kerrthe code to hit the path on the system. Great for running commands with QEMU
898196be3eSJeremy Kerrtoo!
908196be3eSJeremy Kerr
918196be3eSJeremy KerrRun as:
928196be3eSJeremy Kerr
938196be3eSJeremy Kerr```
948196be3eSJeremy Kerrbusctl call <path> <interface> <object> <method> <parameters>
958196be3eSJeremy Kerr```
968196be3eSJeremy Kerr
978196be3eSJeremy Kerr* \<parameters\> example : sssay "t1" "t2" "t3" 2 2 3
98dd7e9997SAndrew Jeffery
99dd7e9997SAndrew Jeffery## Using QEMU
100dd7e9997SAndrew Jeffery
101dd7e9997SAndrew JefferyQEMU has a palmetto-bmc machine (as of v2.6.0) which implements the core
102dd7e9997SAndrew Jefferydevices to boot a Linux kernel. OpenBMC also [maintains a
103dd7e9997SAndrew Jefferytree](https://github.com/openbmc/qemu) with patches on their way upstream or
104dd7e9997SAndrew Jefferytemporary work-arounds that add to QEMU's capabilities where appropriate.
105dd7e9997SAndrew Jeffery
10681db7dbaSChris Austen```
10781db7dbaSChris Austenqemu-system-arm -m 256 -M palmetto-bmc -nographic \
10881db7dbaSChris Austen-drive file=<path>/flash-palmetto,format=raw,if=mtd \
10981db7dbaSChris Austen-net nic \
110*6d0fb8f8SAndrew Jeffery-net user,hostfwd=:127.0.0.1:2222-:22,hostfwd=:127.0.0.1:2443-:443,hostname=qemu
11181db7dbaSChris Austen```
11281db7dbaSChris AustenIf 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...
113dd7e9997SAndrew Jeffery
114dd7e9997SAndrew Jeffery```
11581db7dbaSChris Austencurl -c cjar -b cjar -k -H "Content-Type: application/json" \
11681db7dbaSChris Austen-X POST https://localhost:2443/login -d "{\"data\": [ \"root\", \"0penBmc\" ] }"
11781db7dbaSChris Austen```
11881db7dbaSChris Austenor
11981db7dbaSChris Austen
12081db7dbaSChris Austen```
12181db7dbaSChris Austenssh -p 2222 root@localhost
122dd7e9997SAndrew Jeffery```
123dd7e9997SAndrew Jeffery
124dd7e9997SAndrew JefferyTo quit, type `Ctrl-a c` to switch to the QEMU monitor, and then `quit` to exit.
125ae88254cSJoel Stanley
12681db7dbaSChris Austen## Building QEMU
12781db7dbaSChris Austen
12881db7dbaSChris Austen```
12981db7dbaSChris Austengit clone https://github.com/openbmc/qemu.git
13081db7dbaSChris Austencd qemu
13181db7dbaSChris Austengit submodule update --init dtc
13281db7dbaSChris Austenmkdir build
13381db7dbaSChris Austencd build
13481db7dbaSChris Austen../configure --target-list=arm-softmmu
13581db7dbaSChris Austenmake
13681db7dbaSChris Austen```
13781db7dbaSChris AustenBuilt file will be located at: ```arm-softmmu/qemu-system-arm```
13881db7dbaSChris Austen
13981db7dbaSChris Austen### Use a bridge device
14081db7dbaSChris AustenUsing a bridge device requires a bit of root access to set it up.  The benefit
14181db7dbaSChris Austenis your qemu session runs in the bridges subnet so no port forwarding is needed.
14281db7dbaSChris AustenThere are packages needed to yourself a virbr0 such as...
14381db7dbaSChris Austen
14481db7dbaSChris Austen```
14581db7dbaSChris Austenapt-get install libvirt libvirt-bin bridge-utils uml-utilities qemu-system-common
14681db7dbaSChris Austen
14781db7dbaSChris Austenqemu-system-arm -m 256 -M palmetto-bmc -nographic \
14881db7dbaSChris Austen-drive file=<path>/flash-palmetto,format=raw,if=mtd \
14981db7dbaSChris Austen-net nic,macaddr=C0:FF:EE:00:00:02,model=ftgmac100  \
15081db7dbaSChris Austen-net bridge,id=net0,helper=/usr/lib/qemu-bridge-helper,br=virbr0
15181db7dbaSChris Austen```
15281db7dbaSChris Austen
15381db7dbaSChris AustenThere are some other useful parms like that can redirect the console to another
15481db7dbaSChris Austenwindow.  This results in having an easily accessible qemu command session.
15581db7dbaSChris Austen```-monitor stdio -serial pty -nodefaults```
15681db7dbaSChris Austen
15781db7dbaSChris Austen
158ae88254cSJoel Stanley## Booting the host
159ae88254cSJoel Stanley
160ae88254cSJoel StanleyLogin:
161ae88254cSJoel Stanley```
16203504a95SGunnar Millscurl -c cjar -k -X POST -H "Content-Type: application/json" -d '{"data": [ "root", "0penBmc" ] }' https://${bmc}/login
163ae88254cSJoel Stanley```
164ae88254cSJoel Stanley
165ae88254cSJoel StanleyConnect to host console:
166ae88254cSJoel Stanley```
167ae88254cSJoel Stanleyssh -p 2200 root@bmc
168ae88254cSJoel Stanley```
169ae88254cSJoel Stanley
170ae88254cSJoel StanleyPower on:
171ae88254cSJoel Stanley```
172b56bec0dSGunnar Millscurl -c cjar -b cjar -k -H "Content-Type: application/json" -X PUT \
173b56bec0dSGunnar Mills  -d '{"data": "xyz.openbmc_project.State.Host.Transition.On"}' \
17403504a95SGunnar Mills  https://${bmc}/xyz/openbmc_project/state/host0/attr/RequestedHostTransition
175ae88254cSJoel Stanley```
176246fc994SLei YU
177246fc994SLei YU## GDB
178246fc994SLei YU
179246fc994SLei YU[SDK build](#building-the-openbmc-sdk) provides GDB and debug symbols:
180246fc994SLei YU
181246fc994SLei YU* `$GDB` is available to use once SDK environment is setup
182246fc994SLei YU* Debug symbols are located in `.debug/` directory of each executable
183246fc994SLei YU
184246fc994SLei YUTo use GDB:
185246fc994SLei YU
186246fc994SLei YU1. Setup SDK environment;
187246fc994SLei YU2. Run below GDB commands:
188246fc994SLei YU   ```
189246fc994SLei YU   cd <sysroot_of_sdk_build>
190246fc994SLei YU   $GDB <relative_path_to_exeutable> <path_to_core_file>
191246fc994SLei YU   ```
192246fc994SLei YU
193246fc994SLei YU## Coredump
194246fc994SLei YU
195246fc994SLei YUBy default coredump is disabled in OpenBMC. To enable coredump:
196246fc994SLei YU```
197246fc994SLei YUecho '/tmp/core_%e.%p' | tee /proc/sys/kernel/core_pattern
19848ec067cSLei YUulimit -c unlimited
199246fc994SLei YU```
200246fc994SLei YU
2014635bf2fSPatrick Venture## Cleaning up read-write file system changes
2024635bf2fSPatrick Venture
2034635bf2fSPatrick VentureYou may want to investigate which file(s) are persisting through the overlay
2044635bf2fSPatrick Venturerwfs.  To do this, you can list this path and then remove those files which
2054635bf2fSPatrick Ventureyou'd prefer the originals or remove the deletion overlay to restore files.
2064635bf2fSPatrick Venture
2074635bf2fSPatrick Venture```
2084635bf2fSPatrick Venture/run/initramfs/rw/cow/
2094635bf2fSPatrick Venture```
210e94a168cSLei YU
211e94a168cSLei YU## Building
212e94a168cSLei YU
213e94a168cSLei YU### Share downloads directory
214e94a168cSLei YUIt takes a long time for the first build of OpenBMC. It downloads various repos
215e94a168cSLei YUfrom the internet.
216e94a168cSLei YU
217e94a168cSLei YUCheck `build/downloads` to see all the downloaded repos.
218e94a168cSLei YU
219e94a168cSLei YU* If a repo is a single archive, it usually looks like this:
220e94a168cSLei YU   * `zlib-1.2.11.tar.xz` - The repo itself
221e94a168cSLei YU   * `zlib-1.2.11.tar.xz.done` - A flag indicating the repo is downloaded
222e94a168cSLei YU* If a repo is managed by git, it usually looks like this:
223e94a168cSLei YU   * `git2/github.com.openbmc.linux` - The git bare clone
224e94a168cSLei YU   * `git2/github.com.openbmc.linux.done` - A flag indicating the repo is downloaded
225e94a168cSLei YU
226e94a168cSLei YUBitbake will extract the code to the working directory during build, so the
227e94a168cSLei YU`downloads` directory could be shared by different builds on a system:
228e94a168cSLei YU
229e94a168cSLei YU* Set `DL_DIR` Bitbake environment variable to the location of your shared
230e94a168cSLei YU   downloads directory by editing the `build/conf/local.conf` file:
231e94a168cSLei YU   ```
232e94a168cSLei YU   DL_DIR ?= "<path>/<to>/<existing>/downloads"
233e94a168cSLei YU   ```
234e94a168cSLei YU* Or create a symbol link:
235e94a168cSLei YU   ```
236e94a168cSLei YU   ln -sf <path>/<to>/<existing>/downloads build/downloads
237e94a168cSLei YU   ```
238e94a168cSLei YUThen do the build.  It will save a lot of time from downloading codes.
239e94a168cSLei YU
240e94a168cSLei YU## Using git proxy
241e94a168cSLei YUIf you experience extremely slow download speed during code fetch (e.g. if you
242e94a168cSLei YUare in China), it is possible to use a git proxy to speed up the code fetch.
243e94a168cSLei YU
244e94a168cSLei YUGoogle `git-proxy-wrapper` will find various ways to setup the proxy for the
245e94a168cSLei YUgit protocol.
246e94a168cSLei YU
247e94a168cSLei YUBelow is an example wrapper in `~/bin` assuming a socks5 proxy at port 9054:
248e94a168cSLei YU```
249e94a168cSLei YU#!/bin/sh
250e94a168cSLei YU## Use connect-proxy as git proxy wrapper which supports SOCKS5
251e94a168cSLei YU## Install with `apt-get install connect-proxy`
252e94a168cSLei YU## Use with `export GIT_PROXY_COMMAND=~/bin/git-proxy-wrapper`
253e94a168cSLei YU/usr/bin/connect -S localhost:9054 "$@"
254e94a168cSLei YU```
255e94a168cSLei YUThen you can run `export GIT_PROXY_COMMAND=~/bin/git-proxy-wrapper` and you are
256e94a168cSLei YUnow downloading git code through your proxy.
257e94a168cSLei YU
258e94a168cSLei YU## devtool
259e94a168cSLei YU
260e94a168cSLei YU`devtool` is a convenient utility in Yocto to make changes in the local
261e94a168cSLei YUdirectory.
262e94a168cSLei YUTypical usage is:
263e94a168cSLei YU```
264e94a168cSLei YU# To create a local copy of recipe's code and build with it:
265e94a168cSLei YUdevtool modify <recipe>
266e94a168cSLei YUcd build/workspace/sources/<recipe>  # And make changes
267e94a168cSLei YUbitbake obmc-phosphor-image  # Build with local changes
268e94a168cSLei YU
269e94a168cSLei YU# After you have finished, reset the recipe to ignore local changes:
270e94a168cSLei YUdevtool reset <recipe>
271e94a168cSLei YU```
272e94a168cSLei YU
273e94a168cSLei YUTo use this tool, you need the build environment, e.g. `. oe-init-build-env`.
274e94a168cSLei YUThe above script will add `<WORKDIR>/scripts/` to your `PATH` env and
275e94a168cSLei YU`devtool` is in the path.
276e94a168cSLei YU
277e94a168cSLei YUBelow are real examples.
278e94a168cSLei YU
279e94a168cSLei YU
280e94a168cSLei YU### devtool on ipmi
281e94a168cSLei YU
282e94a168cSLei YUIf you want to debug or add a new function in ipmi, you probably need to
283e94a168cSLei YUchange the code in [phosphor-host-ipmid][1].
284e94a168cSLei YUChecking the recipes, you know this repo is in [phosphor-ipmi-host.bb][2].
285e94a168cSLei YUBelow are the steps to use devtool to modify the code locally, build and test
286e94a168cSLei YUit.
287e94a168cSLei YU1. Use devtool to create a local repo:
288e94a168cSLei YU   ```
289e94a168cSLei YU   devtool modify phosphor-ipmi-host
290e94a168cSLei YU   ```
291e94a168cSLei YU   devtool clones the repo into `build/workspace/sources/phosphor-ipmi-host`,
292e94a168cSLei YU   creates and checkout branch `devtool`.
293e94a168cSLei YU2. Make changes in the repo, e.g. adding code to handle new ipmi commands or
294e94a168cSLei YU   simply adding trace logs.
295e94a168cSLei YU3. Now you can build the whole image or the ipmi recipe itself:
296e94a168cSLei YU   ```
297e94a168cSLei YU   bitbake obmc-phosphor-image  # Build the whole image
298e94a168cSLei YU   bitbake phosphor-ipmi-host  # Build the recipe
299e94a168cSLei YU   ```
300e94a168cSLei YU4. To test your change, either flash the whole image or replace the changed
301e94a168cSLei YU   binary. Note that the changed code is built into `libapphandler.so` and it
302e94a168cSLei YU   is used by both host and net ipmi daemon.
303e94a168cSLei YU   It is recommended that you copy the changed binary to BMC because it is
304e94a168cSLei YU   easier to test:
305e94a168cSLei YU   ```
306e94a168cSLei YU   # Replace libapphandler.so.0.0.0
307e94a168cSLei YU   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/
308e94a168cSLei YU   systemctl restart phosphor-ipmi-host.service  # Restart the inband ipmi daemon
309e94a168cSLei YU   # Or restart phosphor-ipmi-net.service if you want to test net ipmi.
310e94a168cSLei YU   ```
311e94a168cSLei YU5. Now you can test your changes.
312e94a168cSLei YU
313e94a168cSLei YU
314e94a168cSLei YU## Develop linux kernel
315e94a168cSLei YU
316e94a168cSLei YU### devtool on linux kernel
317e94a168cSLei YUIf you want to work on linux kernel, you can use devtool as well, with some
318e94a168cSLei YUdifferences from regular repos.
319e94a168cSLei YU
320e94a168cSLei YU**Note**: As of [ac72846][3] the linux kernel recipe name is changed to
321e94a168cSLei YU`linux-aspeed` for Aspeed based OpenBMC builds.
322e94a168cSLei YUIn the following examples, replace `linux-obmc` with `linux-aspeed` if you are
323e94a168cSLei YUon a revision later than [ac72846][3].
324e94a168cSLei YU
325e94a168cSLei YU1. devtool does not create the 'devtool' branch. Instead, it checkout the
326e94a168cSLei YU   branch specified in the recipe.
327e94a168cSLei YU   For example, on the OpenBMC v2.2 tag, `linux-obmc_4.13.bb` specifies
328e94a168cSLei YU   `dev-4.13` branch.
329e94a168cSLei YU2. If there are patches, `devtool` applies them directly on the branch.
330e94a168cSLei YU3. devtool copies the defconfig and machine-specific config into `oe-workdir`.
331e94a168cSLei YU4. devtool generates the `.config` file based on the above configs.
332e94a168cSLei YU
333e94a168cSLei YUYou can modify the code and build the kernel as usual as follows:
334e94a168cSLei YU```
335e94a168cSLei YUbitbake linux-obmc -c build
336e94a168cSLei YU```
337e94a168cSLei YU
338e94a168cSLei YU### Modify config
339e94a168cSLei YUIf you need to change the config and save it as defconfig for further use:
340e94a168cSLei YU```
341e94a168cSLei YUbitbake linux-obmc -c menuconfig
342e94a168cSLei YU# Edit the configs and after save it generates
343e94a168cSLei YU# .config.new as the new kernel config
344e94a168cSLei YU
345e94a168cSLei YUbitbake linux-obmc -c savedefconfig
346e94a168cSLei YU# It will save the new defconfig at oe-workdir/linux-obmc-<version>/defconfig
347e94a168cSLei YU```
348e94a168cSLei YU
349e94a168cSLei YU### Test linux kernel
350e94a168cSLei YUAfter build, you can flash the image to test the new kernel.
351e94a168cSLei YUHowever, it is always slow to flash an image to the chip.
352e94a168cSLei YU
353e94a168cSLei YUThere is a faster way to load the kernel via network so you can easily test
354e94a168cSLei YUkernel builds.
355e94a168cSLei YU
356e94a168cSLei YUOpenBMC kernel build generates `fit` image, including `kernel`, `dtb` and
357e94a168cSLei YU`initramfs`.
358e94a168cSLei YUTypically we can load it via tftp, taking Romulus as an example:
359e94a168cSLei YU1. Put `build/tmp/deploy/images/romulus/fitImage-obmc-phosphor-initramfs-romulus.bin`
360e94a168cSLei YU   to a tftp server, name it to `fitImage`
361e94a168cSLei YU2. Reboot BMC and press keys to enter uboot shell;
362e94a168cSLei YU3. In uboot:
363e94a168cSLei YU   ```
364e94a168cSLei YU   setenv ethaddr <mac:addr>  # Set mac address if there it is unavailable
365e94a168cSLei YU   setenv ipaddr 192.168.0.80  # Set BMC IP
366e94a168cSLei YU   setenv serverip 192.168.0.11  # Set tftp server IP
367e94a168cSLei YU   tftp 0x83000000 fitImage  # Load fit image to ram. Use 0x43000000 on AST2400
368e94a168cSLei YU   bootm 0x83000000  # Boot from fit image
369e94a168cSLei YU   ```
370e94a168cSLei YUThen you are running an OpenBMC with your updated kernel.
371e94a168cSLei YU
372e94a168cSLei YU
373e94a168cSLei YU[1]: https://github.com/openbmc/phosphor-host-ipmid
374e94a168cSLei YU[2]: https://github.com/openbmc/openbmc/blob/c53f375a0f92f847d2aa50e19de54840e8472c8e/meta-phosphor/recipes-phosphor/ipmi/phosphor-ipmi-host_git.bb
375e94a168cSLei YU[3]: https://github.com/openbmc/openbmc/commit/ac7284629ea572cf27d69949dc4014b3b226f14f
376