xref: /openbmc/docs/kernel-development.md (revision f4febd002df578bad816239b70950f84ea4567e8)
10eacaee7SJeremy Kerr# OpenBMC kernel development
20eacaee7SJeremy Kerr
3*f4febd00SPatrick WilliamsThe OpenBMC project maintains a kernel tree for use by the project. The tree's
4*f4febd00SPatrick Williamsgeneral development policy is that code must be upstream first. This is a strong
5*f4febd00SPatrick Williamsrequirement, not a hard requirement, and exceptions will be made on a
6*f4febd00SPatrick Williamscase-by-case basis. If in doubt, start a discussion on the mailing list.
74cfd5e27SJoel Stanley
8*f4febd00SPatrick WilliamsThe OpenBMC kernel tree is hosted at https://github.com/openbmc/linux and
9*f4febd00SPatrick Williamscontains the set of patches that we carry. Ideally there would be no patches
10*f4febd00SPatrick Williamscarried, as everything should be upstream.
114cfd5e27SJoel Stanley
12*f4febd00SPatrick WilliamsYour code will make it into the OpenBMC tree in these ways, from most to least
13*f4febd00SPatrick Williamsdesirable:
1409baf302SAndrew Jeffery
154cfd5e27SJoel Stanley1. When the OpenBMC kernel moves to a new upstream release
16*f4febd00SPatrick Williams2. By backporting upstream commits from a newer kernel version to the OpenBMC
17*f4febd00SPatrick Williams   kernel
184cfd5e27SJoel Stanley3. Patches included in the OpenBMC tree temporarily
194cfd5e27SJoel Stanley
204cfd5e27SJoel Stanley## TL;DR
214cfd5e27SJoel Stanley
224cfd5e27SJoel StanleyIf you require a patch added to the tree, follow these steps:
234cfd5e27SJoel Stanley
24*f4febd00SPatrick Williams1. Submit your patch upstream. It doesn't need to be upstream, but it should be
25*f4febd00SPatrick Williams   on it's way
26*f4febd00SPatrick Williams2. Use
27*f4febd00SPatrick Williams   `git format-patch --subject-prefix="PATCH linux dev-4.7" --to=openbmc@lists.ozlabs.org --to=joel@jms.id.au`
28*f4febd00SPatrick Williams   to create a formatted patch
294cfd5e27SJoel Stanley
304cfd5e27SJoel Stanley## Developing a new driver
314cfd5e27SJoel Stanley
32*f4febd00SPatrick WilliamsWhen developing a new driver, your goal is to have the code accepted upstream.
33*f4febd00SPatrick WilliamsThe first step should be to check that there is no existing driver for the
34*f4febd00SPatrick Williamshardware you wish to support. Check the OpenBMC `-dev` tree, check upstream, and
35*f4febd00SPatrick Williamsif you do not find support there ask on the mailing list.
364cfd5e27SJoel Stanley
37*f4febd00SPatrick WilliamsOnce you are sure a driver needs to be written, you should develop and test the
38*f4febd00SPatrick Williamsdriver, before sending it upstream to the relevant maintainers. You should feel
39*f4febd00SPatrick Williamswelcome to cc the OpenBMC list when sending upstream, so other kernel developers
40*f4febd00SPatrick Williamscan provide input where appropriate. Be sure to follow the (upstream development
41*f4febd00SPatrick Williamsprocess)[https://www.kernel.org/doc/Documentation/process/submitting-patches.rst].
424cfd5e27SJoel Stanley
43*f4febd00SPatrick WilliamsIn the past patches underwent 'pre-review' on the OpenBMC mailing list. While
44*f4febd00SPatrick Williamsthis is useful for developers who are not familiar with writing kernel code, it
45*f4febd00SPatrick Williamshas lead to confusion about the upstreaming process, so now we do all of our
46*f4febd00SPatrick Williamsdevelopment in the community.
474cfd5e27SJoel Stanley
48*f4febd00SPatrick WilliamsOnce the driver has been accepted upstream, send the good news to the OpenBMC
49*f4febd00SPatrick Williamslist with a reference to the upstream tree. This may be Linus' tree, or it might
50*f4febd00SPatrick Williamsbe one of the subsystem maintainers. From there the OpenBMC kernel team can
51*f4febd00SPatrick Williamsdecide how best to include your code in the OpenBMC tree.
524cfd5e27SJoel Stanley
534cfd5e27SJoel Stanley### Exceptions
544cfd5e27SJoel Stanley
55*f4febd00SPatrick WilliamsThere are cases where waiting for upstream acceptance will delay the bring-up of
56*f4febd00SPatrick Williamsa new system. This should be avoided through careful planning and early
57*f4febd00SPatrick Williamsdevelopment of the features upstream, but where this has not happened we can
58*f4febd00SPatrick Williamschose to carry the patches in the OpenBMC tree while the upstream development is
59*f4febd00SPatrick Williamsongoing.
604cfd5e27SJoel Stanley
61*f4febd00SPatrick WilliamsAnother exception to the upstream first rule is where patches are modifying
62*f4febd00SPatrick Williamsfiles that are not upstream. This currently includes the aspeed board file
63*f4febd00SPatrick Williams`arch/arm/mach-aspeed/aspeed.c`, and the device tree source files `dts`. The
64*f4febd00SPatrick Williamsboard file should go away when we get drivers written for all of the
65*f4febd00SPatrick Williamsfunctionality; for now it contains some hacks relating to LPC and early init.
664cfd5e27SJoel Stanley
67*f4febd00SPatrick WilliamsIf you find yourself adding to `arch/arm/mach-aspeed/aspeed.c`, first send an
68*f4febd00SPatrick Williamsemail to the OpenBMC list to get the opinion of the kernel developers. Patches
69*f4febd00SPatrick Williamsto `aspeed.c` will be treated with some prejudice as the file will be removed
70*f4febd00SPatrick Williamsonce we have drivers for all of the Aspeed peripherals.
718e923a73SAndrew Jeffery
724cfd5e27SJoel Stanley## Getting existing code in the tree
734cfd5e27SJoel Stanley
74*f4febd00SPatrick WilliamsThe OpenBMC kernel is currently based on the 4.7 series. If there is upstream
75*f4febd00SPatrick Williamscode you would like backported, send it to the list. Be sure to include the
76*f4febd00SPatrick Williamsupstream commit SHA in the commit message.
774cfd5e27SJoel Stanley
784cfd5e27SJoel Stanley## Testing
794cfd5e27SJoel Stanley
8009baf302SAndrew JefferyWhen modifying the tree we currently test on the following platforms:
814cfd5e27SJoel Stanley
824cfd5e27SJoel Stanley- Palmetto, an OpenPower Power8 box containing an ast2400 with NCSI networking
834cfd5e27SJoel Stanley- ast2500-evb, the Aspeed dev board with two PHYs
84*f4febd00SPatrick Williams- Witherspoon, an OpenPower Power9 box containing an ast2500 with NCSI
85*f4febd00SPatrick Williams  networking
864cfd5e27SJoel Stanley- qemu-plametto and qemu-romulus
874cfd5e27SJoel Stanley
88*f4febd00SPatrick WilliamsBefore submitting patches it is recommended you boot test on at least the Qemu
89*f4febd00SPatrick Williamsplatforms, and whatever hardware you have available.
904cfd5e27SJoel Stanley
914cfd5e27SJoel Stanley# Tips and Tricks
924cfd5e27SJoel Stanley
930eacaee7SJeremy KerrSome general hints for kernel development
940eacaee7SJeremy Kerr
950eacaee7SJeremy Kerr## Out-of-tree builds
960eacaee7SJeremy Kerr
970eacaee7SJeremy KerrYou can build a kernel out of the yocto environment, by using the initramfs
980eacaee7SJeremy Kerr(from a pre-existing yocto build) directly:
990eacaee7SJeremy Kerr
1000eacaee7SJeremy Kerr```
1010eacaee7SJeremy Kerrmake ARCH=arm \
1020eacaee7SJeremy Kerr    O=obj \
1030eacaee7SJeremy Kerr    CROSS_COMPILE=arm-linux-gnueabihf- \
1040eacaee7SJeremy Kerr    CONFIG_INITRAMFS_SOURCE=/path/tp/obmc-phosphor-image-palmetto.cpio.gz
1050eacaee7SJeremy Kerr```
1060eacaee7SJeremy Kerr
1070eacaee7SJeremy Kerr(adjust `O` and `CROSS_COMPILE` parameters as appropriate).
1080eacaee7SJeremy Kerr
10909baf302SAndrew JefferyYou'll need to use `aspeed_g4_defconfig` or `aspeed_g5_defconfig` as your base
11009baf302SAndrew Jefferykernel configuration.
1110eacaee7SJeremy Kerr
1120eacaee7SJeremy KerrThe cpio can be found in the following yocto output directory:
1130eacaee7SJeremy Kerr
1140eacaee7SJeremy Kerr```
1150eacaee7SJeremy Kerr build/tmp/deploy/images/palmetto/
1160eacaee7SJeremy Kerr```
1170eacaee7SJeremy Kerr
1184cfd5e27SJoel Stanley## Building a uImage
1190eacaee7SJeremy Kerr
1200eacaee7SJeremy KerrTo build a uImage (for example, to netboot):
1210eacaee7SJeremy Kerr
1220eacaee7SJeremy Kerr```
1230eacaee7SJeremy Kerr# build a zImage using the obmc rootfs
1240eacaee7SJeremy Kerrmake ARCH=arm \
1250eacaee7SJeremy Kerr    O=obj \
1260eacaee7SJeremy Kerr    CROSS_COMPILE=arm-linux-gnueabihf- \
1270eacaee7SJeremy Kerr    CONFIG_INITRAMFS_SOURCE=/path/tp/obmc-phosphor-image-palmetto.cpio.gz
1280eacaee7SJeremy Kerr
1290eacaee7SJeremy Kerr# create a combined zImage + DTB image
1300eacaee7SJeremy Kerrcat obj/arch/arm/boot/zImage \
1310eacaee7SJeremy Kerr    obj/arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb \
1320eacaee7SJeremy Kerr        > obj/aspeed-zimage
1330eacaee7SJeremy Kerr
1340eacaee7SJeremy Kerr# create a uImage
1350eacaee7SJeremy Kerr./scripts/mkuboot.sh -A arm -O linux -C none -T kernel \
1360eacaee7SJeremy Kerr    -a 0x40008000 -e 0x40008000 -n $USER-`date +%Y%m%d%H%M` \
1370eacaee7SJeremy Kerr    -d obj/aspeed-zimage obj/uImage
1380eacaee7SJeremy Kerr```
1398e923a73SAndrew Jeffery
1408e923a73SAndrew JefferyNote that some systems may have upgraded to a FIT-based u-boot, where the old
1418e923a73SAndrew JefferyuImage format is no longer accepted.
142