Skip to main content.

U-Boot Coding Style

The following Coding Style requirements shall be mandatory for all code contributed to the U-Boot project.

Exceptions are only allowed if code from other projects is integrated with no or only minimal changes.

The following rules apply:

Submissions of new code or patches that do not conform to these requirements shall be rejected with a request to reformat the changes.

U-Boot Code Documentation

U-Boot adopted the kernel-doc annotation style, this is the only exception from multi-line comment rule of Coding Style. While not mandatory, adding documentation is strongly advised. The Linux kernel kernel-doc document applies with no changes.

Use structures for I/O access

U-Boot typically uses a C structure to map out the registers in an I/O region, rather than offsets. The reasons for this are:

This may need to change to the kernel model if we allow for more run-time detection of what drivers are appropriate for what we're running on.

Include files

You should follow this ordering in U-Boot:

   <common.h>
   <others.h>
   <asm/...>
   <arch/arm/...>
   <linux/...>
   "local.h"

Within that order, sort your includes.

It is important to include common.h first since it provides basic features used by most files, e.g. CONFIG options.

For files that need to be compiled for the host (e.g. tools), you need to use '#ifndef USE_HOSTCC' to avoid including common.h since it includes a lot of internal U-Boot things. See common/image.c for an example.

If your file uses driver model, include in the C file. Do not include dm.h in a header file. Try to use forward declarations (e.g. 'struct udevice') instead.