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