8. Who Am I?
• Macpaul Lin
– Interests and works:
• Open Source
• Networking
• OpenWrt (2006 – 2010)
• U-boot (2010 – 2011)
– Contacts:
• macpaul@gmail.com (macpaul@andestech.com)
• http://www.plurk.com/macpaul
• http://www.facebook.com/macpaul
2011/03/25 Macpaul Lin - OSDC.TW 2011 8
9. Outline
• Introduction to u-boot project.
• The software architecture of U-boot.
• Code commit rules and work flow.
• Suggestions and experiences sharing.
2011/03/25 Macpaul Lin - OSDC.TW 2011 9
10. U-boot - History
• http://en.wikipedia.org/wiki/Das_U-Boot
• Das Unterseeboot
– German for "the submarine."
• GPL
• Boot loader for embedded System
• PPC, ARM, AVR32, MIPS, x86, 68k, Nios, and
MicroBlaze. (and NDS32)
• U-Boot originated in work done by Magnus Damm on a
8xx PowerPC bootloader called 8xxROM.
• Wolfgang Denk moved the project to SourceForge.net.
– http://www.denx.de/wiki/U-Boot/WebHome
2011/03/25 Macpaul Lin - OSDC.TW 2011 10
11. U-boot – Boot Loader
• http://en.wikipedia.org/wiki/Boot_loader#Bo
ot_loader
• Features
– It prepars CPU and RAM to accesse the
nonvolatile devices to load OS into ram.
– It provides firmware upgrade and fail-safe
functions.
– It could run basic diagnostic and testing.
– You can develop simple application on u-boot.
• It also support non-OS frame buffer display (VFD).
2011/03/25 Macpaul Lin - OSDC.TW 2011 11
12. u-boot –
Why release code to u-boot is important ?
• For customers,
– Help on booting their devices.
– Machine type ID is related to Linux Kernel bring
up.
• Release and Clean up is important.
– Boss usually think clean up doesn't help on
contribution to the company.
– Dirty code and old code should be considered as
garbage and debt.
• No productivity to RD.
– It made RD always maintaining old patches when
new release on official project is coming.
2011/03/25 Macpaul Lin - OSDC.TW 2011 12
13. U-boot – Development Model
• Task Force
– Gate Keepers (custodian) by git repository.
• Functions, Architectures, and Vendors.
• Schedule
• Development happens in Release Cycles of 2 months.
• The first 2 weeks are called Merge Window, which is
followed by a Stabilization Period.
• Patches with new code get only accepted while the
Merge Window is open.
• During the Stabilization Period, only patches that
contain bug fixes get applied.
• Release.
2011/03/25 Macpaul Lin - OSDC.TW 2011 13
17. The software architecture
of u-boot
u‐boot ‐ api
‐ arch ‐ nds32 – cpu ‐ soc
‐ board ‐ include
‐ common ‐ lib
‐ drivers
‐ examples
‐ include
‐ lib
‐ net
‐ tools
2011/03/25 Macpaul Lin - OSDC.TW 2011 17
23. Code commit rules
and work flow
• U-boot Mailing list:
– u-boot@lists.denx.de
– http://lists.denx.de/mailman/listinfo/u-boot
– Archives: http://lists.denx.de/pipermail/u-boot/
2011/03/25 Macpaul Lin - OSDC.TW 2011 23
24. u-boot – commit rules
• Patches with related features go together.
• Patches must be ordered and bisected.
– Headers comes before C files.
– Conformed to make and build logic.
• Patches must go with clear descriptions.
– Subject (in category)
– Descriptions
– Signed-off
• Revised patches must be labeled with
versions and simple change log.
• Custodians will test and apply the patches.
2011/03/25 Macpaul Lin - OSDC.TW 2011 24
25. Patches with related features
go together
• Use git rebase -i HEAD~7
– git commit --amend
– git rebase --continue
nds32/ag101/adp-ag101: add board adp-ag101 support
nds32: common bdinfo, bootm, image support
nds32: standalone support
nds32/lib: add generic funcs in NDS32 lib
nds32/ag101: cpu and init funcs of SoC ag101
nds32/core N1213: NDS32 N12 core family N1213
nds32: add header files support for nds32
2011/03/25 Macpaul Lin - OSDC.TW 2011 25
26. Split git commits
• 我接手 u-boot 的時候整包 code 全部被綁在
2 個 patch (git commits) 裡面
• patchutils (doesn't compatible with git)
– filterdiff
• Same single patch file into hunks.
– splitdiff
• Split out every single file-level patch.
2011/03/25 Macpaul Lin - OSDC.TW 2011 26
27. Patches must go with clear
descriptions.
Author: Macpaul Lin <macpaul@andestech.com>
AuthorDate: Mon Oct 25 14:03:51 2010 +0800
Commit: macpaul <macpaul@andestech.com>
subject
CommitDate: Sat Mar 26 00:54:17 2011 +0800
nds32: add NDS32 support into common header file description
signed-off
Add NDS32 support into common header file. git commit -s
Signed‐off‐by: Macpaul Lin <macpaul@andestech.com>
do not use:
2011/03/25
bug number Macpaul Lin - OSDC.TW 2011 27
28. Revised patches must be labeled
with versions
and simple change log
Signed‐off‐by: Macpaul Lin <macpaul@andestech.com>
‐‐‐
Changes for v1‐v4:
‐ Code cleanup and style formatting.
Changes for v5‐v6:
‐ This patch also updated the following changes against the
change after master tree (v2010.12‐rc1).
‐ fix upper case definitions in cache.h
‐ Support GD_FLG_ENV_READY and env_buf vars in nds32
global_data.h.
‐ Add readsb, writesb functions into io.h.
2011/03/25 Macpaul Lin - OSDC.TW 2011 28
http://www.kernel.org/pub/software/scm/git/docs/user‐
manual.html#cleaning‐up‐history
29. Use git send-email to send the
patch
• Remembered add the mailing list and related
developers into the cc. list.
• git send-email goes plain text.
– Do not add patch as an attachment.
– Do not use mime-type in mail header.
– Do not allow your company add "copyright" and
"confidential" in the last section of your patch.
2011/03/25 Macpaul Lin - OSDC.TW 2011 29
30. Coding style
• Linux Coding style.
– http://lxr.linux.no/#linux+v2.6.38/Documentati
on/CodingStyle
– linux/scripts/checkpatch.pl
• U-boot Coding style.
– http://www.denx.de/wiki/U-Boot/CodingStyle
– http://lxr.linux.no/linux/Documentation/CodingS
tyle
2011/03/25 Macpaul Lin - OSDC.TW 2011 30
31. U-boot - Coding style
• All variables, functions, marcos goes to full
uppercase or lower case.
– Do not use “int IE6mustDie;" declaration.
• You must use model name to declare your
device defines.
• Device offset and defines 在 header file 宣告必須使用
產品 " 型號 " ,
• Ex: use FTSDMC021, FTSDMC020,
– Do not use function description: “DRAM_CONTROLLER"
• Ex: CONFIG_FTSDMC021_BANK_SIZE_1M
– Do not use: SDRAM_BANK_SIZE_1M
2011/03/25 Macpaul Lin - OSDC.TW 2011 31
32. U-boot - Coding style
• Files in Makefile or in config.mk must be
ordered.
– A file begins with 'a' must goes before then other
begins with 'b'.
– Ex:
+START = start.o
+COBJS = interrupts.o cpu.o <--- 這樣會被打槍
– Please keep all such lists sorted. 'c' < 'i'.
2011/03/25 Macpaul Lin - OSDC.TW 2011 32
33. U-boot - Coding style
• Global code must never include any board
specific header files.
– This is fundeamentally flawed.
– Wrong Ex:
#include <board/AndesTech/include/porting.h>
#include "../../../board/AndesTech/include/porting.h"
• Declare register offsets by C structures, do
not use #define.
• If definitions of register offsets used by
assembly code is necessary, use tool
(make-asm-offset) to generate the asm.
code.
2011/03/25 Macpaul Lin - OSDC.TW 2011 33
35. Coding style
• Coding style is related to version control
system.
– git (diff) is a mass of the stack of patches.
– Reduce dependance between patches.
– Reduce unnecessary and useless object, log,
history in version control repository.
• Do not follow the old days' coding style.
– Please keep your coding style rules updated.
– Especially do not copy from “ARM” and
“x86” code.
2011/03/25 Macpaul Lin - OSDC.TW 2011 35
36. Coding style
• No Chinese in comment.
if (sound) /* 開聲音 */
writeb(0x1, dev->mute);
• Do not exceed 80 characters in a single line.
– ~/.vimrc
highlight OverLength ctermbg=red ctermfg=white
guibg=#592929
match OverLength /%81v.+/
• Do not use #if 0 and #if 1.
– Use meaningful #define CONFIG_OSDC_TW_R1
2011/03/25 Macpaul Lin - OSDC.TW 2011 36
37. Coding style - misc
– Do not use //... as comment.
• please use /* … */
– Be careful on point statement
• Ex: void *addr
• Wrong Ex:
– void * addr
– Be careful on loop statement
• Ex:
– for (i = 0; i <= 5 ; i++)
– Be careful on brace statement with correct
space.
• Ex: void test(void target, void case)
2011/03/25 Macpaul Lin - OSDC.TW 2011 37
38. Coding style
• You must maintain the commit year of your
copyright/copyleft statement.
– 不論 code 多老,只要 commit 沒有進
maintrunk ,都必須使用「真正」進 commit 的年
份。
– Ex:
# (C) Copyright 2006
Macpaul Lin, Andestech <macpaul@andestech.com>
• Wolfgang's comment:
– So no work has been done on this in the last 4 years? I
guess you want to update your Copyright messages - all of
them.
2011/03/25 Macpaul Lin - OSDC.TW 2011 38
39. Coding style
• The beginning of a functions is declaration.
– Do not put comments at first.
– Wrong Ex:
void cleanup_before_linux(void)
{
/* this function is called just before we call linux */
int i;
}
2011/03/25 Macpaul Lin - OSDC.TW 2011 39
41. Coding style
• 每一行行尾不能有空白或者 t 字元結尾,所有的
行尾都必須是非空白字元結尾。
– No trailing spaces.
• "tt$", "t $", " t"
– No spaces at the beginning.
– Do not use mixed " t" to do indent.
2011/03/25 Macpaul Lin - OSDC.TW 2011 41
42. Coding style – volatile
• What is volatile?
– http://en.wikipedia.org/wiki/Volatile_variable
– http://en.wikipedia.org/wiki/Volatile_variable#Op
timization_comparison_in_C
• Do not use volatile in Linux, driver and boot
loader.
– http://lxr.linux.no/#linux+v2.6.38/Documentati
on/volatile-considered-harmful.txt
2011/03/25 Macpaul Lin - OSDC.TW 2011 42
43. Coding style – volatile
• Like volatile, the kernel primitives which
make concurrent access to data safe
(spinlocks, mutexes, memory barriers, etc.)
are designed to prevent unwanted
optimization.
– Proper spinlock.
• Volatile variables without spinlock still cause problem.
– Memory-mapped I/O register must be accessed
by accessing functions with lock.
– Proper code for busy Waiting.
while (my_variable != what_i_want)
cpu_relax();
2011/03/25 Macpaul Lin - OSDC.TW 2011 43
44. Coding style – volatile
• There are still a few rare situations where
volatile makes sense in the kernel.
• Accessor functions might use volatile on where direct
I/O memory access does work.
• Inline assembly code which changes memory, but
which has no other visible side effects, risks being
deleted by GCC.
• The jiffies variable is special in that it can have a
different value every time it is referenced, but it can be
read without any special locking.
• Pointers to data structures in coherent memory which
might be modified by I/O devices can, sometimes,
legitimately be volatile.
2011/03/25 Macpaul Lin - OSDC.TW 2011 44
45. Coding style – volatile
• Wolfgang:
– Note: this also and especially applies to the
"volatile" and "using I/O accessors instead of
pointer acesses" issues.
– [If not yet, you would probably soon run into
issues when switching to GCC 4.5.x or even
GCC 4.6.]
• https://nongnu.org/software/gcc/gcc-
4.6/changes.html
• A new switch -fstrict-volatile-bitfields has been added.
Using it indicates that accesses to volatile bitfields
should use a single access of the width of the field's
type.
2011/03/25 Macpaul Lin - OSDC.TW 2011 45