1*4882a593Smuzhiyun# 2*4882a593Smuzhiyun# (C) Copyright 2014 Google, Inc 3*4882a593Smuzhiyun# Simon Glass <sjg@chromium.org> 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0+ 6*4882a593Smuzhiyun# 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunBackground 9*4882a593Smuzhiyun---------- 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunU-Boot traditionally had a board.c file for each architecture. This introduced 12*4882a593Smuzhiyunquite a lot of duplication, with each architecture tending to do 13*4882a593Smuzhiyuninitialisation slightly differently. To address this, a new 'generic board 14*4882a593Smuzhiyuninit' feature was introduced in March 2013 (further motivation is 15*4882a593Smuzhiyunprovided in the cover letter below). 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunAll boards and architectures have moved to this as of mid 2016. 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunWhat has changed? 21*4882a593Smuzhiyun----------------- 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunThe main change is that the arch/<arch>/lib/board.c file is removed in 24*4882a593Smuzhiyunfavour of common/board_f.c (for pre-relocation init) and common/board_r.c 25*4882a593Smuzhiyun(for post-relocation init). 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunRelated to this, the global_data and bd_t structures now have a core set of 28*4882a593Smuzhiyunfields which are common to all architectures. Architecture-specific fields 29*4882a593Smuzhiyunhave been moved to separate structures. 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun 32*4882a593SmuzhiyunFurther Background 33*4882a593Smuzhiyun------------------ 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunThe full text of the original generic board series is reproduced below. 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun--8<------------- 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunThis series creates a generic board.c implementation which contains 40*4882a593Smuzhiyunthe essential functions of the major arch/xxx/lib/board.c files. 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunWhat is the motivation for this change? 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun1. There is a lot of repeated code in the board.c files. Any change to 45*4882a593Smuzhiyunthings like setting up the baud rate requires a change in 10 separate 46*4882a593Smuzhiyunplaces. 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun2. Since there are 10 separate files, adding a new feature which requires 49*4882a593Smuzhiyuninitialisation is painful since it must be independently added in 10 50*4882a593Smuzhiyunplaces. 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun3. As time goes by the architectures naturally diverge since there is limited 53*4882a593Smuzhiyunpressure to compare features or even CONFIG options against similar things 54*4882a593Smuzhiyunin other board.c files. 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun4. New architectures must implement all the features all over again, and 57*4882a593Smuzhiyunsometimes in subtle different ways. This places an unfair burden on getting 58*4882a593Smuzhiyuna new architecture fully functional and running with U-Boot. 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun5. While it is a bit of a tricky change, I believe it is worthwhile and 61*4882a593Smuzhiyunachievable. There is no requirement that all code be common, only that 62*4882a593Smuzhiyunthe code that is common should be located in common/board.c rather than 63*4882a593Smuzhiyunarch/xxx/lib/board.c. 64*4882a593Smuzhiyun 65*4882a593SmuzhiyunAll the functions of board_init_f() and board_init_r() are broken into 66*4882a593Smuzhiyunseparate function calls so that they can easily be included or excluded 67*4882a593Smuzhiyunfor a particular architecture. It also makes it easier to adopt Graeme's 68*4882a593Smuzhiyuninitcall proposal when it is ready. 69*4882a593Smuzhiyun 70*4882a593Smuzhiyunhttp://lists.denx.de/pipermail/u-boot/2012-January/114499.html 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunThis series removes the dependency on generic relocation. So relocation 73*4882a593Smuzhiyunhappens as one big chunk and is still completely arch-specific. See the 74*4882a593Smuzhiyunrelocation series for a proposed solution to this for ARM: 75*4882a593Smuzhiyun 76*4882a593Smuzhiyunhttp://lists.denx.de/pipermail/u-boot/2011-December/112928.html 77*4882a593Smuzhiyun 78*4882a593Smuzhiyunor Graeme's recent x86 series v2: 79*4882a593Smuzhiyun 80*4882a593Smuzhiyunhttp://lists.denx.de/pipermail/u-boot/2012-January/114467.html 81*4882a593Smuzhiyun 82*4882a593SmuzhiyunInstead of moving over a whole architecture, this series takes the approach 83*4882a593Smuzhiyunof simply enabling generic board support for an architecture. It is then up 84*4882a593Smuzhiyunto each board to opt in by defining CONFIG_SYS_GENERIC_BOARD in the board 85*4882a593Smuzhiyunconfig file. If this is not done, then the code will be generated as 86*4882a593Smuzhiyunbefore. This allows both sets of code to co-exist until we are comfortable 87*4882a593Smuzhiyunwith the generic approach, and enough boards run. 88*4882a593Smuzhiyun 89*4882a593SmuzhiyunARM is a relatively large board.c file and one which I can test, therefore 90*4882a593SmuzhiyunI think it is a good target for this series. On the other hand, x86 is 91*4882a593Smuzhiyunrelatively small and simple, but different enough that it introduces a 92*4882a593Smuzhiyunfew issues to be solved. So I have chosen both ARM and x86 for this series. 93*4882a593SmuzhiyunAfter a suggestion from Wolfgang I have added PPC also. This is the 94*4882a593Smuzhiyunlargest and most feature-full board, so hopefully we have all bases 95*4882a593Smuzhiyuncovered in this RFC. 96*4882a593Smuzhiyun 97*4882a593SmuzhiyunA generic global_data structure is also required. This might upset a few 98*4882a593Smuzhiyunpeople. Here is my basic reasoning: most fields are the same, all 99*4882a593Smuzhiyunarchitectures include and need it, most global_data.h files already have 100*4882a593Smuzhiyun#ifdefs to select fields for a particular SOC, so it is hard to 101*4882a593Smuzhiyunsee why architecures are different in this area. We can perhaps add a 102*4882a593Smuzhiyunway to put architecture-specific fields into a separate header file, but 103*4882a593Smuzhiyunfor now I have judged that to be counter-productive. 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunSimilarly we need a generic bd_info structure, since generic code will 106*4882a593Smuzhiyunbe accessing it. I have done this in the same way as global_data and the 107*4882a593Smuzhiyunsame comments apply. 108*4882a593Smuzhiyun 109*4882a593SmuzhiyunThere was dicussion on the list about passing gd_t around as a parameter 110*4882a593Smuzhiyunto pre-relocation init functions. I think this makes sense, but it can 111*4882a593Smuzhiyunbe done as a separate change, and this series does not require it. 112*4882a593Smuzhiyun 113*4882a593SmuzhiyunWhile this series needs to stand on its own (as with the link script 114*4882a593Smuzhiyuncleanup series and the generic relocation series) the goal is the 115*4882a593Smuzhiyununification of the board init code. So I hope we can address issues with 116*4882a593Smuzhiyunthis in mind, rather than focusing too narrowly on particular ARM, x86 or 117*4882a593SmuzhiyunPPC issues. 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunI have run-tested ARM on Tegra Seaboard only. To try it out, define 120*4882a593SmuzhiyunCONFIG_SYS_GENERIC_BOARD in your board file and rebuild. Most likely on 121*4882a593Smuzhiyunx86 and PPC at least it will hang, but if you are lucky it will print 122*4882a593Smuzhiyunsomething first :-) 123*4882a593Smuzhiyun 124*4882a593SmuzhiyunI have run this though MAKEALL with CONFIG_SYS_GENERIC_BOARD on for all 125*4882a593SmuzhiyunARM, PPC and x86 boards. There are a few failures due to errors in 126*4882a593Smuzhiyunthe board config, which I have sent patches for. The main issue is 127*4882a593Smuzhiyunjust the difference between __bss_end and __bss_end__. 128*4882a593Smuzhiyun 129*4882a593SmuzhiyunNote: the first group of commits are required for this series to build, 130*4882a593Smuzhiyunbut could be separated out if required. I have included them here for 131*4882a593Smuzhiyunconvenience. 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun------------->8-- 134*4882a593Smuzhiyun 135*4882a593SmuzhiyunSimon Glass, sjg@chromium.org 136*4882a593SmuzhiyunMarch 2014 137*4882a593SmuzhiyunUpdated after final removal, May 2016 138