10f605c15SSimon Glass# 20f605c15SSimon Glass# (C) Copyright 2014 Google, Inc 30f605c15SSimon Glass# Simon Glass <sjg@chromium.org> 40f605c15SSimon Glass# 50f605c15SSimon Glass# SPDX-License-Identifier: GPL-2.0+ 60f605c15SSimon Glass# 70f605c15SSimon Glass 80f605c15SSimon GlassBackground 90f605c15SSimon Glass---------- 100f605c15SSimon Glass 11*89b199c3SSimon GlassU-Boot traditionally had a board.c file for each architecture. This introduced 12*89b199c3SSimon Glassquite a lot of duplication, with each architecture tending to do 130f605c15SSimon Glassinitialisation slightly differently. To address this, a new 'generic board 14*89b199c3SSimon Glassinit' feature was introduced in March 2013 (further motivation is 150f605c15SSimon Glassprovided in the cover letter below). 160f605c15SSimon Glass 17*89b199c3SSimon GlassAll boards and architectures have moved to this as of mid 2016. 18*89b199c3SSimon Glass 190f605c15SSimon Glass 200f605c15SSimon GlassWhat has changed? 210f605c15SSimon Glass----------------- 220f605c15SSimon Glass 23*89b199c3SSimon GlassThe main change is that the arch/<arch>/lib/board.c file is removed in 240f605c15SSimon Glassfavour of common/board_f.c (for pre-relocation init) and common/board_r.c 250f605c15SSimon Glass(for post-relocation init). 260f605c15SSimon Glass 270f605c15SSimon GlassRelated to this, the global_data and bd_t structures now have a core set of 280f605c15SSimon Glassfields which are common to all architectures. Architecture-specific fields 290f605c15SSimon Glasshave been moved to separate structures. 300f605c15SSimon Glass 310f605c15SSimon Glass 320f605c15SSimon GlassFurther Background 330f605c15SSimon Glass------------------ 340f605c15SSimon Glass 350f605c15SSimon GlassThe full text of the original generic board series is reproduced below. 360f605c15SSimon Glass 370f605c15SSimon Glass--8<------------- 380f605c15SSimon Glass 390f605c15SSimon GlassThis series creates a generic board.c implementation which contains 400f605c15SSimon Glassthe essential functions of the major arch/xxx/lib/board.c files. 410f605c15SSimon Glass 420f605c15SSimon GlassWhat is the motivation for this change? 430f605c15SSimon Glass 440f605c15SSimon Glass1. There is a lot of repeated code in the board.c files. Any change to 450f605c15SSimon Glassthings like setting up the baud rate requires a change in 10 separate 460f605c15SSimon Glassplaces. 470f605c15SSimon Glass 480f605c15SSimon Glass2. Since there are 10 separate files, adding a new feature which requires 490f605c15SSimon Glassinitialisation is painful since it must be independently added in 10 500f605c15SSimon Glassplaces. 510f605c15SSimon Glass 52a560ad70SRicardo Ribalda3. As time goes by the architectures naturally diverge since there is limited 53a560ad70SRicardo Ribaldapressure to compare features or even CONFIG options against similar things 540f605c15SSimon Glassin other board.c files. 550f605c15SSimon Glass 560f605c15SSimon Glass4. New architectures must implement all the features all over again, and 57a560ad70SRicardo Ribaldasometimes in subtle different ways. This places an unfair burden on getting 580f605c15SSimon Glassa new architecture fully functional and running with U-Boot. 590f605c15SSimon Glass 600f605c15SSimon Glass5. While it is a bit of a tricky change, I believe it is worthwhile and 610f605c15SSimon Glassachievable. There is no requirement that all code be common, only that 620f605c15SSimon Glassthe code that is common should be located in common/board.c rather than 630f605c15SSimon Glassarch/xxx/lib/board.c. 640f605c15SSimon Glass 650f605c15SSimon GlassAll the functions of board_init_f() and board_init_r() are broken into 660f605c15SSimon Glassseparate function calls so that they can easily be included or excluded 670f605c15SSimon Glassfor a particular architecture. It also makes it easier to adopt Graeme's 680f605c15SSimon Glassinitcall proposal when it is ready. 690f605c15SSimon Glass 700f605c15SSimon Glasshttp://lists.denx.de/pipermail/u-boot/2012-January/114499.html 710f605c15SSimon Glass 720f605c15SSimon GlassThis series removes the dependency on generic relocation. So relocation 730f605c15SSimon Glasshappens as one big chunk and is still completely arch-specific. See the 740f605c15SSimon Glassrelocation series for a proposed solution to this for ARM: 750f605c15SSimon Glass 760f605c15SSimon Glasshttp://lists.denx.de/pipermail/u-boot/2011-December/112928.html 770f605c15SSimon Glass 780f605c15SSimon Glassor Graeme's recent x86 series v2: 790f605c15SSimon Glass 800f605c15SSimon Glasshttp://lists.denx.de/pipermail/u-boot/2012-January/114467.html 810f605c15SSimon Glass 820f605c15SSimon GlassInstead of moving over a whole architecture, this series takes the approach 830f605c15SSimon Glassof simply enabling generic board support for an architecture. It is then up 840f605c15SSimon Glassto each board to opt in by defining CONFIG_SYS_GENERIC_BOARD in the board 850f605c15SSimon Glassconfig file. If this is not done, then the code will be generated as 860f605c15SSimon Glassbefore. This allows both sets of code to co-exist until we are comfortable 870f605c15SSimon Glasswith the generic approach, and enough boards run. 880f605c15SSimon Glass 890f605c15SSimon GlassARM is a relatively large board.c file and one which I can test, therefore 900f605c15SSimon GlassI think it is a good target for this series. On the other hand, x86 is 910f605c15SSimon Glassrelatively small and simple, but different enough that it introduces a 920f605c15SSimon Glassfew issues to be solved. So I have chosen both ARM and x86 for this series. 930f605c15SSimon GlassAfter a suggestion from Wolfgang I have added PPC also. This is the 940f605c15SSimon Glasslargest and most feature-full board, so hopefully we have all bases 950f605c15SSimon Glasscovered in this RFC. 960f605c15SSimon Glass 970f605c15SSimon GlassA generic global_data structure is also required. This might upset a few 980f605c15SSimon Glasspeople. Here is my basic reasoning: most fields are the same, all 990f605c15SSimon Glassarchitectures include and need it, most global_data.h files already have 1000f605c15SSimon Glass#ifdefs to select fields for a particular SOC, so it is hard to 1010f605c15SSimon Glasssee why architecures are different in this area. We can perhaps add a 1020f605c15SSimon Glassway to put architecture-specific fields into a separate header file, but 1030f605c15SSimon Glassfor now I have judged that to be counter-productive. 1040f605c15SSimon Glass 1050f605c15SSimon GlassSimilarly we need a generic bd_info structure, since generic code will 1060f605c15SSimon Glassbe accessing it. I have done this in the same way as global_data and the 1070f605c15SSimon Glasssame comments apply. 1080f605c15SSimon Glass 1090f605c15SSimon GlassThere was dicussion on the list about passing gd_t around as a parameter 1100f605c15SSimon Glassto pre-relocation init functions. I think this makes sense, but it can 1110f605c15SSimon Glassbe done as a separate change, and this series does not require it. 1120f605c15SSimon Glass 1130f605c15SSimon GlassWhile this series needs to stand on its own (as with the link script 1140f605c15SSimon Glasscleanup series and the generic relocation series) the goal is the 1150f605c15SSimon Glassunification of the board init code. So I hope we can address issues with 1160f605c15SSimon Glassthis in mind, rather than focusing too narrowly on particular ARM, x86 or 1170f605c15SSimon GlassPPC issues. 1180f605c15SSimon Glass 1190f605c15SSimon GlassI have run-tested ARM on Tegra Seaboard only. To try it out, define 1200f605c15SSimon GlassCONFIG_SYS_GENERIC_BOARD in your board file and rebuild. Most likely on 1210f605c15SSimon Glassx86 and PPC at least it will hang, but if you are lucky it will print 1220f605c15SSimon Glasssomething first :-) 1230f605c15SSimon Glass 1240f605c15SSimon GlassI have run this though MAKEALL with CONFIG_SYS_GENERIC_BOARD on for all 1250f605c15SSimon GlassARM, PPC and x86 boards. There are a few failures due to errors in 1260f605c15SSimon Glassthe board config, which I have sent patches for. The main issue is 1270f605c15SSimon Glassjust the difference between __bss_end and __bss_end__. 1280f605c15SSimon Glass 1290f605c15SSimon GlassNote: the first group of commits are required for this series to build, 1300f605c15SSimon Glassbut could be separated out if required. I have included them here for 1310f605c15SSimon Glassconvenience. 1320f605c15SSimon Glass 1330f605c15SSimon Glass------------->8-- 1340f605c15SSimon Glass 1350f605c15SSimon GlassSimon Glass, sjg@chromium.org 1360f605c15SSimon GlassMarch 2014 137*89b199c3SSimon GlassUpdated after final removal, May 2016 138