blob: 5b3eacf7783a35de260636a6bd63655980f90936 [file] [log] [blame]
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001%
2% This document is released under the GPL
Stefan Reinauerebf25892009-04-21 21:45:11 +00003% Initially written by Stefan Reinauer, <stepan@coresystems.de>
Stefan Reinauer14e22772010-04-27 06:56:47 +00004%
Stefan Reinauer37414ca2003-11-22 15:15:47 +00005
6\documentclass[titlepage,12pt]{article}
7\usepackage{a4}
8\usepackage{graphicx}
9\usepackage{url}
10\usepackage[pdftex]{hyperref}
11% \usepackage{makeidx}
12% \makeindex
13
14\hypersetup{
15 urlbordercolor={1 1 1},
16 menubordercolor={1 1 1},
17 linkbordercolor={1 1 1},
18 colorlinks=false,
19 % pdfpagemode=None, % PDF-Viewer starts without TOC
20 % pdfstartview=FitH,
Stefan Reinauerebf25892009-04-21 21:45:11 +000021 pdftitle={coreboot on AMD64},
Stefan Reinauer37414ca2003-11-22 15:15:47 +000022 pdfauthor={Stefan Reinauer},
Stefan Reinauerebf25892009-04-21 21:45:11 +000023 pdfsubject={coreboot configuration and build process},
24 pdfkeywords={coreboot, Opteron, AMD64, configuration, Build}
Stefan Reinauer37414ca2003-11-22 15:15:47 +000025}
26
27
28% \newcommand{\sh}[1]{\begin{verbatim}\texttt{#1}\end{verbatim}}
29% \newcommand{\prog}[1]{\textit{#1}}
30
31\setlength{\parindent}{0pt}
32
Stefan Reinauerebf25892009-04-21 21:45:11 +000033\title{coreboot on AMD64}
34\author{Stefan Reinauer $<$stepan@coresystems.de$>$}
35\date{April 19th, 2009}
Stefan Reinauer37414ca2003-11-22 15:15:47 +000036
37\begin{document}
38
39\maketitle
40
Stefan Reinauer14e22772010-04-27 06:56:47 +000041\thispagestyle{empty}
Stefan Reinauer37414ca2003-11-22 15:15:47 +000042
43\tableofcontents
44
45\newpage
46
47%
48% 1 Abstract
49%
50
51\section{Abstract}
52
Stefan Reinauerebf25892009-04-21 21:45:11 +000053This document targets porting coreboot to new mainboards and creating
54custom firmware images using coreboot. It describes how to build
55coreboot images for the AMD64 platform, including hypertransport
Stefan Reinauer37414ca2003-11-22 15:15:47 +000056configuration and pertinent utilities. If you are missing information or
57find errors in the following descriptions, contact
Stefan Reinauerebf25892009-04-21 21:45:11 +000058\href{mailto:stepan@coresystems.de}{\textit{Stefan Reinauer $<$stepan@coresystems.de$>$}}
Stefan Reinauer37414ca2003-11-22 15:15:47 +000059
60
61%
Stefan Reinauerf69f7e22004-02-10 17:30:04 +000062% 2 Changes
63%
64
65\section{Changes}
66 \begin{itemize}
Stefan Reinauerebf25892009-04-21 21:45:11 +000067 \item 2009/04/19 replace LinuxBIOS with coreboot
Stefan Reinauer2c83b272004-06-02 11:25:31 +000068 \item 2004/06/02 url and language fixes from Ken Fuchs $<$kfuchs@winternet.com$>$
Stefan Reinauerf69f7e22004-02-10 17:30:04 +000069 \item 2004/02/10 acpi and option rom updates
Stefan Reinauer14e22772010-04-27 06:56:47 +000070 \item 2003/11/18 initial release
Stefan Reinauerf69f7e22004-02-10 17:30:04 +000071 \end{itemize}
72
73
74
75%
Stefan Reinauerebf25892009-04-21 21:45:11 +000076% 3 What is coreboot
Stefan Reinauer37414ca2003-11-22 15:15:47 +000077%
78
Stefan Reinauerebf25892009-04-21 21:45:11 +000079\section{What is coreboot?}
Stefan Reinauer37414ca2003-11-22 15:15:47 +000080
Stefan Reinauer14e22772010-04-27 06:56:47 +000081coreboot aims to replace the normal BIOS found on x86, AMD64, PPC,
Stefan Reinauerebf25892009-04-21 21:45:11 +000082Alpha, and other machines with a Linux kernel that can boot Linux from a cold
83start. The startup code of an average coreboot port is about 500 lines of
84assembly and 5000 lines of C. It executes 16 instructions to get into 32bit
85protected mode and then performs DRAM and other hardware initializations
Stefan Reinauer37414ca2003-11-22 15:15:47 +000086required before Linux can take over.
87
88The projects primary motivation initially was maintenance of large
89clusters. Not surprisingly interest and contributions have come from
90people with varying backgrounds. Nowadays a large and growing number of
Stefan Reinauerebf25892009-04-21 21:45:11 +000091Systems can be booted with coreboot, including embedded systems,
Stefan Reinauer37414ca2003-11-22 15:15:47 +000092Desktop PCs and Servers.
93
94%
Stefan Reinauerf69f7e22004-02-10 17:30:04 +000095% 4 Build Requirements
Stefan Reinauer37414ca2003-11-22 15:15:47 +000096%
97
98\section{Build Requirements}
Stefan Reinauerebf25892009-04-21 21:45:11 +000099To build coreboot for AMD64 from the sources you need a recent Linux
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000100system for x86 or AMD64. SUSE Linux 8.2 or 9.0 are known to work fine.
101The following toolchain is recommended:
102
103 \begin{itemize}
104 \item GCC 3.3.1
105 \item binutils 2.14.90.0.5
106 \item Python 2.3
107 \item CVS 1.11.6
108 \end{itemize}
109
110\textbf{NOTE:} Later versions should also work. Prior versions might lead to problems.
111
112\newpage
113
114%
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000115% 5 Getting the Sources
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000116%
117
118\section{Getting the Sources}
119
Stefan Reinauerebf25892009-04-21 21:45:11 +0000120The latest coreboot sources are available via subversion. The subversion
121repository is maintained at SourceForge.net (the project name is
122\emph{FreeBIOS}). First you should create a directory for your
123coreboot trees:
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000124
125{ \small
126\begin{verbatim}
Stefan Reinauerebf25892009-04-21 21:45:11 +0000127$ mkdir coreboot
128$ cd coreboot
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000129\end{verbatim}
130}
131
Stefan Reinauerebf25892009-04-21 21:45:11 +0000132You can get the entire source tree via SVN:
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000133
Stefan Reinauer14e22772010-04-27 06:56:47 +0000134{ \small
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000135\begin{verbatim}
Stefan Reinauerebf25892009-04-21 21:45:11 +0000136$ svn co svn://coreboot.org/repos/trunk/coreboot-v2
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000137\end{verbatim}
138}
139
140Once the source tree is checked out, it can be updated with:
141
142{ \small
143\begin{verbatim}
Stefan Reinauerebf25892009-04-21 21:45:11 +0000144% svn update
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000145\end{verbatim}
146}
147
Stefan Reinauerebf25892009-04-21 21:45:11 +0000148For the case your corporate firewall blocks port 3690 (subversion) we set up a
149snapshot site that keeps the last few hundred source code revisions. It
150is available at \url{http://qa.coreboot.org/}.
151Due to major structural enhancements to \hbox{coreboot}, AMD64 support
152is only available in the \texttt{coreboot-v2} tree. This tree reflects (as
153of November 2003) coreboot version 1.1.5 and will lead to coreboot 2.0
Stefan Reinauer14e22772010-04-27 06:56:47 +0000154when finished. Most x86 hardware is currently only supported by the
Stefan Reinauerebf25892009-04-21 21:45:11 +0000155coreboot 1.0 tree.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000156
157%
Stefan Reinauerebf25892009-04-21 21:45:11 +0000158% 6 coreboot configuration overview
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000159%
160
Stefan Reinauerebf25892009-04-21 21:45:11 +0000161\section{coreboot configuration overview}
162To support a large variety of existing hardware coreboot allows for a
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000163lot of configuration options that can be tweaked in several ways:
164
165\begin{itemize}
Stefan Reinauer14e22772010-04-27 06:56:47 +0000166\item
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000167Firmware image specific configuration options can be set in the image
168configuration file which is usually found in
Stefan Reinauerebf25892009-04-21 21:45:11 +0000169\texttt{coreboot-v2/targets/$<$vendor$>$/$<$mainboard$>$/}. Such
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000170options are the default amount of output verbosity during bootup, image
171size, use of fallback mechanisms, firmware image size and payloads
172(Linux Kernel, Bootloader...) The default configuration file name is
Stefan Reinauerebf25892009-04-21 21:45:11 +0000173\texttt{Config.lb}, but coreboot allows multiple configurations to
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000174reside in that directory.
175
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000176\item Mainboard specific configuration options can be set in the
177mainboard configuration file placed in
Stefan Reinauerebf25892009-04-21 21:45:11 +0000178\texttt{coreboot-v2/src/mainboard/$<$vendor$>$/$<$mainboard$>$}. The
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000179mainboard configuration file is always called \texttt{Config.lb}. It
180contains information on the onboard components of the mainboard like
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000181CPU type, northbridge, southbridge, hypertransport configuration and
182SuperIO configuration. This configuration file also allows to include
Stefan Reinauerebf25892009-04-21 21:45:11 +0000183addon code to hook into the coreboot initialization mechanism at
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000184basically any point.
185
186\end{itemize}
187
188This document describes different approaches of changing and configuring the
Stefan Reinauerebf25892009-04-21 21:45:11 +0000189coreboot source tree when building for AMD64.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000190
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000191%
Stefan Reinauerebf25892009-04-21 21:45:11 +0000192% 7 Building coreboot
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000193%
194
Stefan Reinauerebf25892009-04-21 21:45:11 +0000195\section{Building coreboot}
196One of the design goals for building coreboot was to keep object files
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000197out of the source tree in a separate place. This is mandatory for
Stefan Reinauerebf25892009-04-21 21:45:11 +0000198building parallel coreboot images for several distinct mainboards
199and/or platforms. Therefore building coreboot consists of two steps:
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000200\begin{itemize}
201\item
202creating a build tree which holds all files automatically created by the
203configuration utility and the object files
204\item
Stefan Reinauerebf25892009-04-21 21:45:11 +0000205compiling the coreboot code and creating a flashable firmware image.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000206\end{itemize}
207
208The first of these two steps is accomplished by the \texttt{buildtarget}
Stefan Reinauerebf25892009-04-21 21:45:11 +0000209script found in \texttt{coreboot-v2/targets/}. To build coreboot for
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000210instance for the AMD Solo Athlon64 mainboard enter:
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000211
212\begin{verbatim}
Stefan Reinauerebf25892009-04-21 21:45:11 +0000213% cd coreboot-v2/targets
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000214% ./buildtarget amd/solo
215\end{verbatim}
216
217This will create a directory containing a Makefile and other software
218components needed for this build. The directory name is defined in the
219firmware image specific configuration file. In the case of AMD's Solo
Stefan Reinauer14e22772010-04-27 06:56:47 +0000220mainboard the default directory resides in
Stefan Reinauerebf25892009-04-21 21:45:11 +0000221\texttt{coreboot-v2/targets/amd/solo/solo}. To build the coreboot image, do
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000222
223\begin{verbatim}
224% cd amd/solo/solo
225% make
226\end{verbatim}
227
Stefan Reinauerebf25892009-04-21 21:45:11 +0000228The coreboot image filename is specified in the firmware image specific
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000229configuration file. The default filename for AMD's Solo mainboard is
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000230\texttt{solo.rom}.
231
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000232%
Stefan Reinauerebf25892009-04-21 21:45:11 +0000233% 8 Programming coreboot to flash memory
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000234%
235
Stefan Reinauerebf25892009-04-21 21:45:11 +0000236\section{Programming coreboot to flash memory}
237The image resulting from a coreboot build can be directly programmed to
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000238a flash device, either using a hardware flash programmer or by using the
239Linux flash driver devbios or mtd. This document assumes that you use a
240hardware flash programmer. If you are interested in doing in-system
241software flash programming, find detailed information:
242
243\begin{itemize}
244\item \url{http://www.openbios.org/development/devbios.html} (/dev/bios)
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000245\item \url{http://www.linux-mtd.infradead.org/} (Memory Technology Device Subsystem MTD)
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000246\end{itemize}
247
248\newpage
249
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000250%
Stefan Reinauerebf25892009-04-21 21:45:11 +0000251% 9 coreboot configuration
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000252%
253
Stefan Reinauerebf25892009-04-21 21:45:11 +0000254\section{coreboot configuration}
255The following chapters will cope with configuring coreboot. All
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000256configuration files share some basic rules
257\begin{itemize}
258\item
Stefan Reinauerebf25892009-04-21 21:45:11 +0000259The default configuration file name in coreboot is \texttt{Config.lb}.
Stefan Reinauer14e22772010-04-27 06:56:47 +0000260\item
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000261All variables used in a configuration file have to be declared in this
262file with \texttt{uses VARNAME} before usage.
263\item
264Comments can be added on a new line by using the comment identifier
265\texttt{\#} at the beginning of the line.
266\item
Stefan Reinauerebf25892009-04-21 21:45:11 +0000267coreboot distinguishes between statements and options. Statements cause
268the coreboot configuration mechanism to act, whereas options set
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000269variables that are used by the build scripts or source code.
Stefan Reinauer14e22772010-04-27 06:56:47 +0000270\item
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000271Default configuration values can be set in the mainboard configuration
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000272files (keyword default)
Stefan Reinauer14e22772010-04-27 06:56:47 +0000273\item
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000274Option overrides to the default configuration can only be specified in
275the build target configuration file
Stefan Reinauer14e22772010-04-27 06:56:47 +0000276\texttt{coreboot-v2/targets/$<$vendor$>$/$<$mainboard$>$/Config.lb}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000277(keyword option)
278\end{itemize}
279
280\subsection{Common Configuration Statements}
281
282\begin{itemize}
283
284\item \begin{verbatim}uses\end{verbatim}
285
286All local configuration variables have to be declared before they can be
287used. Example:
288\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +0000289 uses CONFIG_ROM_IMAGE_SIZE
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000290\end{verbatim}
291
292\textbf{NOTE:} Only configuration variables known to the configuration
Stefan Reinauer14e22772010-04-27 06:56:47 +0000293system can be used in configuration files. coreboot checks
Stefan Reinauerebf25892009-04-21 21:45:11 +0000294\texttt{coreboot-v2/src/config/Options.lb} to see whether a configuration
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000295variable is known.
296
297\item \begin{verbatim}default\end{verbatim}
298
299The \texttt{default} statement is used to set a configuration variable
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000300with an overridable default value. It is commonly used in mainboard
Stefan Reinauer14e22772010-04-27 06:56:47 +0000301configuration files.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000302
303Example:
304
305\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +0000306 default CONFIG_ROM_IMAGE_SIZE=0x10000
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000307\end{verbatim}
308
309It is also possible to assign the value of one configuration variable to
310another one, i.e.:
311
312\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +0000313 default CONFIG_FALLBACK_SIZE=CONFIG_ROM_SIZE
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000314\end{verbatim}
315
316Also, simple expressions are allowed:
317
318\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +0000319 default CONFIG_FALLBACK_SIZE=(CONFIG_ROM_SIZE - NORMAL_SIZE)
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000320\end{verbatim}
321
322If an option contains a string, this string has to be protected with
Stefan Reinauer14e22772010-04-27 06:56:47 +0000323quotation marks:
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000324
325\begin{verbatim}
Stefan Reinauere4ff2a512006-08-23 10:52:12 +0000326 default CC="gcc -m32"
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000327\end{verbatim}
328
329\item \begin{verbatim}option\end{verbatim}
330
331The \texttt{option} statement basically behaves identically to the
332\texttt{default} statement. But unlike default it can only be used in
333build target configuration files
Stefan Reinauerebf25892009-04-21 21:45:11 +0000334(\texttt{coreboot-v2/targets/$<$vendor$>$/$<$mainboard$>$}). The option
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000335statement allows either to set new options or to override default values
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000336set with the default statement in a mainboard configuration file.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000337Syntax and application are the same as with default.
338
339\end{itemize}
340
341\subsection{Firmware image specific configuration}
Stefan Reinauerebf25892009-04-21 21:45:11 +0000342coreboot allows to create different firmware images for the same
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000343hardware. Such images can differ in the amount of output they produce,
344the payload, the number of subimages they consist of etc.
345
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000346The firmware image specific configuration file can be found in \\
Stefan Reinauerebf25892009-04-21 21:45:11 +0000347\texttt{coreboot-v2/targets/$<$vendor$>$/<mainboard$>$}.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000348
349\subsubsection{Firmware image specific keywords}
350In addition to the above described keywords the following statements are
351available in firmware image specific configuration files:
352
353\begin{itemize}
354\item \begin{verbatim}romimage\end{verbatim}
355
356The \texttt{romimage} definition describes a single rom build within the
Stefan Reinauerebf25892009-04-21 21:45:11 +0000357final coreboot image. Normally there are two romimage definitions per
358coreboot build: \texttt{normal} and \texttt{fallback}.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000359
360Each \texttt{romimage} section needs to specify a mainboard directory and a
361payload. The mainboard directory contains the mainboard specific
362configuration file and source code. It is specified relatively to
Stefan Reinauerebf25892009-04-21 21:45:11 +0000363\texttt{coreboot-v2/src/mainboard}. The payload definition is an absolute
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000364path to a static elf binary (i.e Linux kernel or etherboot)
365
366\begin{verbatim}
367romimage "normal"
Stefan Reinauer08670622009-06-30 15:17:49 +0000368 option CONFIG_USE_FALLBACK_IMAGE=0
369 option CONFIG_ROM_IMAGE_SIZE=0x10000
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000370 option COREBOOT_EXTRA_VERSION=".0Normal"
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000371 mainboard amd/solo
372 payload /suse/stepan/tg3ide_
373 disk.zelf
374end
375\end{verbatim}
376
377\item \begin{verbatim}buildrom\end{verbatim}
378
379The \texttt{buildrom} statement is used to determine which of the
Stefan Reinauerebf25892009-04-21 21:45:11 +0000380coreboot image builds (created using \texttt{romimage}) are packed
381together to the final coreboot image. It also specifies the order of
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000382the images and the final image size:
383
384\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +0000385 buildrom ./solo.rom CONFIG_ROM_SIZE "normal" "fallback"
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000386\end{verbatim}
387
388\end{itemize}
389
390
391\subsubsection{Firmware image configuration options}
392In addition to the definitions described above there are a number of
393commonly used options. Configuration options set in the firmware image
394specific configuration file can override default selections from the
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000395Mainboard specific configuration. See above examples about
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000396option on how to set them.
397
398\begin{itemize}
399
400\item \begin{verbatim}CC\end{verbatim}
401
402Target C Compiler. Default is \texttt{\$(CROSS\_COMPILE)gcc}. Set to
Stefan Reinauer14e22772010-04-27 06:56:47 +0000403\texttt{gcc -m32} for compiling AMD64 coreboot images on an AMD64
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000404machine.
405
406\item \begin{verbatim}CONFIG_CHIP_CONFIGURE \end{verbatim}
407
408Use new \textit{chip\_configure} method for configuring (nonpci)
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000409devices. Set to \texttt{1} for all AMD64 mainboards.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000410
Stefan Reinauer08670622009-06-30 15:17:49 +0000411\item \begin{verbatim}CONFIG_DEFAULT_CONSOLE_LOGLEVEL\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000412
Stefan Reinauer14e22772010-04-27 06:56:47 +0000413Console will log at this level unless changed. Default is \texttt{7},
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000414minimum is \texttt{0}, maximum is \texttt{10}.
415
416\item \begin{verbatim}CONFIG_CONSOLE_SERIAL8250\end{verbatim}
417
418Log messages to 8250 uart based serial console. Default is \texttt{0}
419(don't log to serial console). This value should be set to \texttt{1}
420for all AMD64 builds.
421
Stefan Reinauer08670622009-06-30 15:17:49 +0000422\item \begin{verbatim}CONFIG_ROM_SIZE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000423
424Size of final ROM image. This option has no default value.
425
Stefan Reinauer08670622009-06-30 15:17:49 +0000426\item \begin{verbatim}CONFIG_FALLBACK_SIZE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000427
Stefan Reinauer14e22772010-04-27 06:56:47 +0000428Fallback image size. Defaults to \texttt{65536} bytes. \textbf{NOTE:}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000429This does not include the fallback payload.
430
Stefan Reinauer08670622009-06-30 15:17:49 +0000431\item \begin{verbatim}CONFIG_HAVE_OPTION_TABLE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000432
433Export CMOS option table. Default is \texttt{0}. Set to \texttt{1} if
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000434your mainboard has CMOS memory and you want to use it to store
Stefan Reinauerebf25892009-04-21 21:45:11 +0000435coreboot parameters (Loglevel, serial line speed, ...)
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000436
Ed Swierkbe13dc72006-12-15 12:56:28 +0000437\item \begin{verbatim}CONFIG_ROM_PAYLOAD\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000438
Ed Swierkbe13dc72006-12-15 12:56:28 +0000439Boot image is located in ROM (as opposed to \texttt{CONFIG\_IDE\_PAYLOAD}, which
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000440will boot from an IDE disk)
441
Stefan Reinauer08670622009-06-30 15:17:49 +0000442\item \begin{verbatim}CONFIG_HAVE_FALLBACK_BOOT\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000443
444Set to \texttt{1} if fallback booting is required. Defaults to
445\texttt{0}.
446
447\end{itemize}
448
449
450The following options should be used within a romimage section:
451
452\begin{itemize}
453
Stefan Reinauer08670622009-06-30 15:17:49 +0000454\item \begin{verbatim}CONFIG_USE_FALLBACK_IMAGE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000455
456Set to \texttt{1} to build a fallback image. Defaults to \texttt{0}
457
Stefan Reinauer08670622009-06-30 15:17:49 +0000458\item \begin{verbatim}CONFIG_ROM_IMAGE_SIZE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000459
460Default image size. Defaults to \texttt{65535} bytes.
461
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000462\item \begin{verbatim}COREBOOT_EXTRA_VERSION\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000463
Stefan Reinauerebf25892009-04-21 21:45:11 +0000464coreboot extra version. This option has an empty string as default. Set
465to any string to add an extra version string to your coreboot build.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000466
467\end{itemize}
468
469\newpage
470
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000471\subsection{Mainboard specific configuration}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000472
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000473Mainboard specific configuration files describe the onboard
474mainboard components, i.e. bridges, number and type of CPUs. They also
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000475contain rules for building the low level start code which is translated
476using romcc and/or the GNU assembler. This code enables caches and
477registers, early mtrr settings, fallback mechanisms, dram init and
478possibly more.
479
Stefan Reinauer14e22772010-04-27 06:56:47 +0000480\textbf{NOTE:} The \texttt{option} keyword can not be used in mainboard
481specific configuration files. Options shall instead be set using the
482\texttt{default} keyword so that they can be overridden by the image
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000483specific configuration files if needed.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000484
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000485\subsubsection{Mainboard specific keywords}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000486
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000487The following statements are used in mainboard specific configuration
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000488files:
489
490\begin{itemize}
491\item \begin{verbatim}arch\end{verbatim}
492
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000493Sets the CPU architecture. This should be \texttt{i386} for AMD64 boards.\\
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000494Example:
495
496\begin{verbatim}
497 arch i386 end
498\end{verbatim}
499
500\item \begin{verbatim}cpu\end{verbatim}
501
502The cpu statement is needed once per possibly available CPU. In a
503one-node system, write:
504
505\begin{verbatim}
506 cpu k8 "cpu0" end
507\end{verbatim}
508
509\item \begin{verbatim}driver\end{verbatim}
510
511The \texttt{driver} keyword adds an object file to the driver section of a
Stefan Reinauer236d1022009-04-21 22:05:50 +0000512coreboot image. This means it can be used by the PCI device
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000513initialization code. Example:
514
515\begin{verbatim}
516 driver mainboard.o
517\end{verbatim}
518
519\item \begin{verbatim}object\end{verbatim}
520
Stefan Reinauerebf25892009-04-21 21:45:11 +0000521The \texttt{object} keyword adds an object file to the coreboot image.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000522Per default the object file will be compiled from a \texttt{.c} file
523with the same name. Symbols defined in such an object file can be used
524in other object files and drivers. Example:
525
526\begin{verbatim}
527 object reset.o
528\end{verbatim}
529
530\item \begin{verbatim}makerule\end{verbatim}
531
532This keyword can be used to extend the existing file creation rules
533during the build process. This is useful if external utilities have to
Stefan Reinauerebf25892009-04-21 21:45:11 +0000534be used for the build. coreboot on AMD64 uses romcc for it's early
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000535startup code placed in auto.c.
536
Stefan Reinauer14e22772010-04-27 06:56:47 +0000537To tell the configuration mechanism how to build \texttt{romcc} files,
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000538do:
539
540\begin{verbatim}
541makerule ./auto.E
Stefan Reinauer08670622009-06-30 15:17:49 +0000542 depends "$(CONFIG_MAINBOARD)/auto.c option_table.h ./romcc"
Stefan Reinauere4ff2a512006-08-23 10:52:12 +0000543 action "./romcc -E -mcpu=k8 -O2 -I$(TOP)/src -I. $(CPPFLAGS) \
Stefan Reinauer08670622009-06-30 15:17:49 +0000544 $(CONFIG_MAINBOARD)/auto.c -o $@"
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000545end
546makerule ./auto.inc
Stefan Reinauer08670622009-06-30 15:17:49 +0000547 depends "$(CONFIG_MAINBOARD)/auto.c option_table.h ./romcc"
Stefan Reinauere4ff2a512006-08-23 10:52:12 +0000548 action "./romcc -mcpu=k8 -O2 -I$(TOP)/src -I. $(CPPFLAGS) \
Stefan Reinauer08670622009-06-30 15:17:49 +0000549 $(CONFIG_MAINBOARD)/auto.c -o $@"
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000550end
551\end{verbatim}
552
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000553Each \texttt{makerule} section contains file dependencies (using the
Stefan Reinauer14e22772010-04-27 06:56:47 +0000554texttt{depends} keyword) and an action that is taken when the dependencies
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000555are satisfied (using the \texttt{action} keyword).
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000556
557\item \begin{verbatim}mainboardinit\end{verbatim}
558
559With the mainboardinit keyword it's possible to include assembler code
Stefan Reinauerebf25892009-04-21 21:45:11 +0000560directly into the coreboot image. This is used for early infrastructure
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000561initialization, i.e. to switch to protected mode. Example:
562
563\begin{verbatim}
564 mainboardinit cpu/i386/entry16.inc
565\end{verbatim}
566
567\item \begin{verbatim}ldscript\end{verbatim}
568
Stefan Reinauerebf25892009-04-21 21:45:11 +0000569The GNU linker ld is used to link object files together to a coreboot
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000570ROM image.
571
572Since it is a lot more comfortable and flexible to use the GNU linker
573with linker scripts (ldscripts) than to create complex command line
Stefan Reinauerebf25892009-04-21 21:45:11 +0000574calls, coreboot features including linker scripts to control image
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000575creation. Example:
576
577\begin{verbatim}
578 ldscript /cpu/i386/entry16.lds
579\end{verbatim}
580
581
582\item \begin{verbatim}dir\end{verbatim}
583
Stefan Reinauerebf25892009-04-21 21:45:11 +0000584coreboot reuses as much code between the different ports as possible.
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000585To achieve this, commonly used code can be stored in a separate
586directory. For a new mainboard, it is enough to know that the code in
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000587that directory can be used as is.
588
Stefan Reinauerebf25892009-04-21 21:45:11 +0000589coreboot will also read a \texttt{Config.lb} file stored in that
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000590directory. This happens with:
591
592\begin{verbatim}
593 dir /pc80
594\end{verbatim}
595
596
597\item \begin{verbatim}config\end{verbatim}
598
599This keyword is needed by the new chip configuration scheme. Should be
600used as:
601
602\begin{verbatim}
603 config chip.h
604\end{verbatim}
605
606\item \begin{verbatim}register\end{verbatim}
607The \texttt{register} keyword can occur in any section, passing
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000608additional \\
609parameters to the code handling the associated device.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000610Example:
611
612\begin{verbatim}
613 register "com1" = "{1, 0, 0x3f8, 4}"
614\end{verbatim}
615
616\item \begin{verbatim}northbridge\end{verbatim}
617
618The \texttt{northbridge} keyword describes a system northbridge. Some
619systems, like AMD64, can have more than one northbridge, i.e. one per
620CPU node. Each northbridge is described by the path to the northbridge
Stefan Reinauerebf25892009-04-21 21:45:11 +0000621code in coreboot (relative to \texttt{coreboot-v2/src/northbridge}), i.e.
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000622\texttt{amd/amdk8} and a unique name (i.e \texttt{mc0}) \\
623Example:
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000624
625\begin{verbatim}
626 northbridge amd/amdk8 "mc0"
627 [..]
628 end
629\end{verbatim}
630
631\item \begin{verbatim}southbridge\end{verbatim}
632
Stefan Reinauerebf25892009-04-21 21:45:11 +0000633To simplify the handling of bus bridges in a coreboot system, all
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000634bridges available in a system that are not northbridges (i.e AGP, IO,
635PCIX) are seen as southbridges.
636
637Since from the CPUs point of view any southbridge is connected via the
638northbridge, a southbridge section is declared within the northbridge
639section of the north bridge it is attached to.
640
641Like the northbridge, any other bridge is described by the path to it's
642driver code, and a unique name. If the described bridge is a
643hypertransport device, the northbridge's hypertransport link it connects
644to can be specified using the \texttt{link} keyword. Example:
645
646\begin{verbatim}
647northbridge amd/amdk8 "mc0"
648 [..]
649 southbridge amd/amd8111 "amd8111" link 0
650 [..]
651 end
652 [..]
653end
654\end{verbatim}
655
656\item \begin{verbatim}pci\end{verbatim}
657
658The \texttt{pci} keyword can only occur within a \texttt{northbridge} or
659\texttt{southbridge} section. It is used to describe the PCI devices
660that are provided by the bridge. Generally all bridge sections have a
661couple of \texttt{pci} keywords.
662
Stefan Reinauerebf25892009-04-21 21:45:11 +0000663The first occurrence of the \texttt{pci} keyword tells coreboot where
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000664the bridge devices start, relative to the PCI configuration space used
665by the bridge. The following occurences of the \texttt{pci} keyword
Stefan Reinauer14e22772010-04-27 06:56:47 +0000666describe the provided devices.
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000667
668Adding the option \texttt{on} or \texttt{off} to a PCI device will
669enable or disable this device. This feature can be used if some bridge
670devices are not wired to hardware outputs and thus are not used.
671
672Example:
673
674\begin{verbatim}
675northbridge amd/amdk8 "mc1"
676 pci 0:19.0
677 pci 0:19.0
678 pci 0:19.0
679 pci 0:19.1
680 pci 0:19.2
681 pci 0:19.3
682end
683\end{verbatim}
684
685or
686
687\begin{verbatim}
688southbridge amd/amd8111 "amd8111" link 0
689 pci 0:0.0
690 pci 0:1.0 on
691 pci 0:1.1 on
692 pci 0:1.2 on
693 pci 0:1.3 on
694 pci 0:1.5 off
695 pci 0:1.6 off
696 pci 1:0.0 on
697 pci 1:0.1 on
698 pci 1:0.2 on
699 pci 1:1.0 off
700 [..]
701end
702\end{verbatim}
703
704\item \begin{verbatim}superio\end{verbatim}
705
706SuperIO devices are basically handled like brigdes. They are taking
Stefan Reinauerebf25892009-04-21 21:45:11 +0000707their driver code from \texttt{coreboot-v2/src/superio/}. They don't
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000708provide a PCI compatible configuration interface, but instead are ISA
709PnP devices. Normally they are connected to a southbridge. If this is
710the case, the \texttt{superio} section will be a subsection of the
711\texttt{southbridge} section of the southbridge it is connected to.
712Example:
713
714\begin{verbatim}
Uwe Hermannd86417b2006-10-24 23:00:42 +0000715superio nsc/pc87360 link 1
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000716 pnp 2e.0
717 pnp 2e.1
718 pnp 2e.2
719 pnp 2e.3
720 pnp 2e.4
721 pnp 2e.5
722 pnp 2e.6
723 pnp 2e.7
724 pnp 2e.8
725 pnp 2e.9
726 pnp 2e.a
727 register "com1" = "{1, 0, 0x3f8, 4}"
728 register "lpt" = "{1}"
729end
730\end{verbatim}
731
732\end{itemize}
733
734\newpage
735
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000736\subsubsection{Mainboard specific configuration options}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000737
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000738The following options are commonly used in mainboard specific
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000739configuration files.
740
741They should be set using the \texttt{default} keyword:
742
743\begin{itemize}
744
Stefan Reinauer08670622009-06-30 15:17:49 +0000745\item \begin{verbatim}CONFIG_HAVE_HARD_RESET\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000746
747If set to \texttt{1}, this option defines that there is a hard reset
748function for this mainboard. This option is not defined per default.
749
Stefan Reinauer08670622009-06-30 15:17:49 +0000750\item \begin{verbatim}CONFIG_HAVE_PIRQ_TABLE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000751
752If set to \texttt{1}, this option defines that there is an IRQ Table for
753this mainboard. This option is not defined per default.
754
Stefan Reinauer08670622009-06-30 15:17:49 +0000755\item \begin{verbatim}CONFIG_IRQ_SLOT_COUNT\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000756
757Number of IRQ slots. This option is not defined per default.
758
Stefan Reinauer08670622009-06-30 15:17:49 +0000759\item \begin{verbatim}CONFIG_HAVE_MP_TABLE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000760
761Define this option to build an MP table (v1.4). The default is not to
762build an MP table.
763
Stefan Reinauer08670622009-06-30 15:17:49 +0000764\item \begin{verbatim}CONFIG_HAVE_OPTION_TABLE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000765
766Define this option to export a CMOS option table. The default is not to
767export a CMOS option table.
768
769\item \begin{verbatim}CONFIG_SMP\end{verbatim}
770
771Set this option to \texttt{1} if the mainboard supports symmetric
772multiprocessing (SMP). This option defaults to \texttt{0} (no SMP).
773
774\item \begin{verbatim}CONFIG_MAX_CPUS\end{verbatim}
775
776If \begin{verbatim}CONFIG_SMP\end{verbatim} is set, this option defines
777the maximum number of CPUs (i.e. the number of CPU sockets) in the
778system. Defaults to \texttt{1}.
779
780\item \begin{verbatim}CONFIG_IOAPIC\end{verbatim}
781
782Set this option to \texttt{1} to enable IOAPIC support. This is
783mandatory if you want to boot a 64bit Linux kernel on an AMD64 system.
784
Stefan Reinauer08670622009-06-30 15:17:49 +0000785\item \begin{verbatim}CONFIG_STACK_SIZE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000786
Stefan Reinauerebf25892009-04-21 21:45:11 +0000787coreboot stack size. The size of the function call stack defaults to
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000788\texttt{0x2000} (8k).
789
Stefan Reinauer08670622009-06-30 15:17:49 +0000790\item \begin{verbatim}CONFIG_HEAP_SIZE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000791
Stefan Reinauerebf25892009-04-21 21:45:11 +0000792coreboot heap size. The heap is used when coreboot allocates memory
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000793with malloc(). The default heap size is \texttt{0x2000}, but AMD64 boards
794generally set it to \texttt{0x4000} (16k)
795
Stefan Reinauer08670622009-06-30 15:17:49 +0000796\item \begin{verbatim}CONFIG_XIP_ROM_BASE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000797
Stefan Reinauerebf25892009-04-21 21:45:11 +0000798Start address of area to cache during coreboot execution directly from
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000799ROM.
800
Stefan Reinauer08670622009-06-30 15:17:49 +0000801\item \begin{verbatim}CONFIG_XIP_ROM_SIZE\end{verbatim}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000802
Stefan Reinauerebf25892009-04-21 21:45:11 +0000803Size of area to cache during coreboot execution directly from ROM
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000804
805\item \begin{verbatim}CONFIG_COMPRESS\end{verbatim}
806
807Set this option to \texttt{1} for a compressed image. If set to
808\texttt{0}, the image is bigger but will start slightly faster (since no
809decompression is needed).
810
811\end{itemize}
812
813
814\newpage
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000815
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000816%
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000817% 10. Tweaking the source code
Stefan Reinauer14e22772010-04-27 06:56:47 +0000818%
Stefan Reinauerf69f7e22004-02-10 17:30:04 +0000819
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000820\section{Tweaking the source code}
821Besides configuring the existing code it is sometimes necessary or
Stefan Reinauerebf25892009-04-21 21:45:11 +0000822desirable to tweak certain parts of coreboot by direct changes to the
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000823code. This chapter covers some possible enhancements and changes that
Stefan Reinauerebf25892009-04-21 21:45:11 +0000824are needed when porting coreboot to a new mainboard or just come
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000825handy now and then.
826
827\subsection{Hypertransport configuration}
Stefan Reinauerebf25892009-04-21 21:45:11 +0000828Before coreboot is able to activate all CPUs and detect bridges
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000829attached to these CPUs (and thus, see all devices attached to the
830system) it has to initialize the coherent hypertransport devices.
831
832The current algorithms to do coherent hypertransport initialization are
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000833not fully, automatically evaluating the hypertransport chain graph.
Stefan Reinauerebf25892009-04-21 21:45:11 +0000834Therefore the code needs to be adapted when porting coreboot to a new
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000835AMD64 mainboard. An example arrangement of hypertransport devices
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000836looks like this:
837
838\begin{figure}[htb]
839\centering
840\includegraphics[scale=1.0]{hypertransport.pdf}
841\caption{Example: Hypertransport Link Connections}
842\label{fix:hypertransport}
843\end{figure}
844
845Each hypertransport device has one to three hypertransport links that
846are used for device interconnection. These links are called LDT$[$012$]$, or
847accordingly UP, ACROSS, DOWN. Communication between the hypertransport
848devices can be freely routed, honoring the physical wiring. Teaching the
849coherent hypertransport initialization algorithm this wiring happens in
850two steps.
851
852\newpage
853
854\begin{enumerate}
855\item Setting outgoing connections
856The algorithm needs to know which outgoing port of a CPU node is
857connected to the directly succeeding node. This is done in
Stefan Reinauerebf25892009-04-21 21:45:11 +0000858\texttt{coreboot-v2/src/mainboard/$<$vendor$>$/$<$mainboard$>$/auto.c}
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000859with a number of preprocessor defines (one define for two-node systems,
860three defines for four-node systems).
861
862The ports in question are flagged with a circle in the graph for
863illustration. For the example graph above (all outgoing connections are
864realized using LDT1/ACROSS) the defines are:
865
866\begin{verbatim}
867#define CONNECTION_0_1 ACROSS
868#define CONNECTION_0_2 ACROSS
869#define CONNECTION_1_3 ACROSS
870\end{verbatim}
871
872\item Describing routing information between CPUs.
873
874There are basically three different message types for hypertransport
875communication:
876\begin{enumerate}
877\item request packages
878\item response packages
879\item broadcast packages
880\end{enumerate}
881
882These three message types are routed using different hypertransport
883ports. The routing information is written to the AMD K8 routing table.
884In an Nnode system this routing table consists of 3*N*N entries , one
885for each message type and for each possible CPU --> CPU communication. For
Stefan Reinauerebf25892009-04-21 21:45:11 +0000886simplicity coreboot keeps the 3 routing entries for each CPU --> CPU
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000887communication in one machine word. The routing table of each node looks
888like this:
889
890\begin{verbatim}
891/* Routing Table for Node i
892 *
893 * F0: 0x40, 0x44, 0x48, 0x4c, 0x50, 0x54, 0x58, 0x5c
894 * i: 0, 1, 2, 3, 4, 5, 6, 7
895 *
896 * [ 0: 3] Request Route
897 * [0] Route to this node
898 * [1] Route to Link 0
899 * [2] Route to Link 1
900 * [3] Route to Link 2
901 * [11: 8] Response Route
902 * [0] Route to this node
903 * [1] Route to Link 0
904 * [2] Route to Link 1
905 * [3] Route to Link 2
906 * [19:16] Broadcast route
907 * [0] Route to this node
908 * [1] Route to Link 0
909 * [2] Route to Link 1
910 * [3] Route to Link 2
911 */
912\end{verbatim}
913
914The routing table is passed to the coherent hypertransport
915initialization algorithm by defining a function called
916\texttt{generate\_row()} in \texttt{auto.c}:
917
918\begin{verbatim}
919static unsigned int generate_row
920 (uint8_t node, uint8_t row, uint8_t maxnodes)
921\end{verbatim}
922
923This function is trivial if there is only one CPU in the system, since
924no routing has to be done:
925
926\begin{verbatim}
927static unsigned int generate_row
928 (uint8_t node, uint8_t row, uint8_t maxnodes)
929{
930 return 0x00010101; /* default row entry */
931}
932\end{verbatim}
933
934On a two-node system things look slightly more complicated. Since the
935coherent hypertransport initialization algorithm works by consecutively
936enabling CPUs, it contains routing information for driving the system
937with one node and two nodes:
938
939\begin{verbatim}
940static unsigned int generate_row
941 (uint8_t node, uint8_t row, uint8_t maxnodes)
942{
943 uint32_t ret=0x00010101; /* default row entry */
944 static const unsigned int rows_2p[2][2] = {
945 { 0x00050101, 0x00010404 },
946 { 0x00010404, 0x00050101 }
947 };
948 if(maxnodes>2) maxnodes=2;
949 if (!(node>=maxnodes || row>=maxnodes)) {
950 ret=rows_2p[node][row];
951 }
952 return ret;
953}
954\end{verbatim}
955
956Systems with four nodes have to contain routing information for one, two
957and four-node setups:
958
959\begin{verbatim}
960static unsigned int generate_row
961 (uint8_t node, uint8_t row, uint8_t maxnodes)
962{
963 uint32_t ret=0x00010101; /* default row entry */
964 static const unsigned int rows_2p[2][2] = {
965 { 0x00030101, 0x00010202 },
966 { 0x00010202, 0x00030101 }
967 };
968 static const unsigned int rows_4p[4][4] = {
969 { 0x00070101, 0x00010202, 0x00030404, 0x00010204 },
970 { 0x00010202, 0x000b0101, 0x00010208, 0x00030808 },
971 { 0x00030808, 0x00010208, 0x000b0101, 0x00010202 },
972 { 0x00010204, 0x00030404, 0x00010202, 0x00070101 }
973 };
974 if (!(node>=maxnodes || row>=maxnodes)) {
975 if (maxnodes==2)
976 ret=rows_2p[node][row];
977 if (maxnodes==4)
978 ret=rows_4p[node][row];
979 }
980 return ret;
981}
982\end{verbatim}
983\end{enumerate}
984
985\subsection{DRAM configuration}
986Setting up the RAM controller(s) is probably the most complex part of
Stefan Reinauerebf25892009-04-21 21:45:11 +0000987coreboot. Basically coreboot serially initializes all RAM controllers
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000988in the system, using SPDROM (serial presence detect) data to set
989timings, size and other properties. The SPD data is usually read
990utilizing the I2C SMBUS interface of the southbridge.
991
992There is one central data structure that describes the RAM controllers
Stefan Reinauer2c83b272004-06-02 11:25:31 +0000993available on an AMD64 system and the associated devices:
Stefan Reinauer37414ca2003-11-22 15:15:47 +0000994
995\begin{verbatim}
996struct mem_controller {
997 unsigned node_id;
998 device_t f0, f1, f2, f3;
999 uint8_t channel0[4];
1000 uint8_t channel1[4];
1001};
1002\end{verbatim}
1003
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001004Available mainboard implementations and CPUs create the need to add
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001005special setup code to RAM initialization in a number of places.
Stefan Reinauerebf25892009-04-21 21:45:11 +00001006coreboot provides hooks to easily add code in these places without
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001007having to change the generic code. Whether these hooks have to be used
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001008depends on the mainboard design. In many cases the functions executed
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001009by the hooks just carry out trivial default settings or they are even
1010empty.
1011
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001012Some mainboard/CPU combinations need to trigger an additional memory
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001013controller reset before the memory can be initialized properly. This is,
1014for example, used to get memory working on preC stepping AMD64
Stefan Reinauerebf25892009-04-21 21:45:11 +00001015processors. coreboot provides two hooks for triggering onboard memory
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001016reset logic:
1017
1018\begin{itemize}
1019\item \begin{verbatim}static void memreset_setup(void)\end{verbatim}
1020\item \begin{verbatim}static void memreset(int controllers, const struct
1021 mem_controller *ctrl)\end{verbatim}
1022\end{itemize}
1023
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001024Some mainboards utilize an SMBUS hub or possibly other mechanisms to
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001025allow using a large number of SPDROMs and thus ram sockets. The result
1026is that only the SPDROM information of one cpu node is visible at a
1027time. The following function, defined in \texttt{auto.c}, is called every time
1028before a memory controller is initialized and gets the memory controller
1029information of the next controller as a parameter:
1030
1031\begin{verbatim}
1032static inline void activate_spd_rom (const struct mem_controller *ctrl)
1033\end{verbatim}
1034
1035The way SMBUS hub information is coded into the \texttt{mem\_controller}
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001036structure is mainboard implementation specific and not
Stefan Reinauerebf25892009-04-21 21:45:11 +00001037described here. See \texttt{coreboot-v2/src/mainboard/amd/quartet/auto.c}
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001038for an example.
1039
Stefan Reinauerebf25892009-04-21 21:45:11 +00001040coreboot folks have agreed on SPD data being the central information
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001041source for RAM specific information. But not all mainboards/RAM
1042modules feature a physical SPD ROM. To still allow an easy to use SPD
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001043driven setup, there is a hook that abstracts reading the SPD ROM
1044ingredients that are used by the memory initialization mechanism:
1045
1046\begin{verbatim}
1047static inline int spd_read_byte(unsigned device, unsigned address)
1048\end{verbatim}
1049
1050This function, defined in \texttt{auto.c}, directly maps it's calls to
1051\texttt{smbus\_read\_byte()} calls if SPD ROM information is read via
1052the I2C SMBUS:
1053
1054\begin{verbatim}
1055static inline int spd_read_byte(unsigned device, unsigned address)
1056{
1057 return smbus_read_byte(device & 0xff, address);
1058}
1059\end{verbatim}
1060
1061If there is no SPD ROM available in the system design, this function
1062keeps an array of SPD ROM information hard coded per logical RAM module.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001063It returns the faked' SPD ROM information using device and address
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001064as indices to this array.
1065
1066
1067\subsection {IRQ Tables}
1068
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001069Mainboards that provide an IRQ table should have the following two
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001070variables set in their \texttt{Config.lb} file:
1071
1072\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +00001073default CONFIG_HAVE_PIRQ_TABLE=1
1074default CONFIG_IRQ_SLOT_COUNT=7
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001075\end{verbatim}
1076
Stefan Reinauerebf25892009-04-21 21:45:11 +00001077This will make coreboot look for the file \\
1078\texttt{coreboot-v2/src/mainboard/<vendor>/<mainboard>/irq\_tables.c} which
1079contains the source code definition of the IRQ table. coreboot corrects
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001080small inconsistencies in the IRQ table during startup (checksum and
Stefan Reinauer14e22772010-04-27 06:56:47 +00001081number of entries), but it is not yet writing IRQ tables in a completely
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001082dynamic way.
1083
1084\textbf{NOTE:} To get Linux to understand and actually use the IRQ
1085table, it is not always a good idea to specify the vendor and device id
1086of the actually present interrupt router device. Linux 2.4 for example
1087does not know about the interrupt router of the AMD8111 southbridge. In
1088such cases it is advised to choose the vendor/device id of a compatible
1089device that is supported by the Linux kernel. In case of the AMD8111
1090interrupt router it is advised to specify the AMD768/Opus interrupt
1091controller instead (vendor id=\texttt{0x1022}, device id=\texttt{0x7443})
1092
1093\subsection {MP Tables}
1094
Stefan Reinauerebf25892009-04-21 21:45:11 +00001095coreboot contains code to create MP tables conforming the
1096Multiprocessor Specification V1.4. To include an MP Table in a coreboot
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001097image, the following configuration variables have to be set (in the
1098mainboard specific configuration file
Stefan Reinauerebf25892009-04-21 21:45:11 +00001099\texttt{coreboot-v2/src/mainboard/<vendor><mainboard>/Config.lb}):
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001100
1101\begin{verbatim}
1102default CONFIG_SMP=1
1103default CONFIG_MAX_CPUS=1 # 2,4,..
Stefan Reinauer08670622009-06-30 15:17:49 +00001104default CONFIG_HAVE_MP_TABLE=1
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001105\end{verbatim}
1106
Stefan Reinauerebf25892009-04-21 21:45:11 +00001107coreboot will then look for a function for setting up the MP table in
1108the file \texttt{coreboot-v2/src/mainboard<vendor>/<mainboard>/mptable.c}:
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001109
1110\begin{verbatim}
1111void *smp_write_config_table(void *v, unsigned long * processor_map)
1112\end{verbatim}
1113
1114MP Table generation is still somewhat static, i.e. changing the bus
1115numbering will force
1116you to adopt the code in mptable.c. This is subject to change in future
1117revisions.
1118
Stefan Reinauerc0f4e2a2004-02-10 16:53:55 +00001119\subsection {ACPI Tables}
1120
Stefan Reinauerebf25892009-04-21 21:45:11 +00001121There is initial ACPI support in coreboot now. Currently the only gain with
Stefan Reinauerc0f4e2a2004-02-10 16:53:55 +00001122this is the ability to use HPET timers in Linux. To achieve this, there is a
Stefan Reinauer14e22772010-04-27 06:56:47 +00001123framework that can generate the following tables:
Stefan Reinauerc0f4e2a2004-02-10 16:53:55 +00001124\begin{itemize}
1125\item RSDP
1126\item RSDT
1127\item MADT
1128\item HPET
1129\end{itemize}
1130
Stefan Reinauerebf25892009-04-21 21:45:11 +00001131To enable ACPI in your coreboot build, add the following lines to your
Stefan Reinauerc0f4e2a2004-02-10 16:53:55 +00001132configuration files:
1133\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +00001134uses CONFIG_HAVE_ACPI_TABLES
Stefan Reinauerc0f4e2a2004-02-10 16:53:55 +00001135[..]
Stefan Reinauer08670622009-06-30 15:17:49 +00001136option CONFIG_HAVE_ACPI_TABLES=1
Stefan Reinauerc0f4e2a2004-02-10 16:53:55 +00001137\end{verbatim}
1138
1139To keep Linux doing it's pci ressource allocation based on IRQ tables and MP
1140tables, you have to specify the kernel parameter \texttt{pci=noacpi} otherwise
Stefan Reinauer14e22772010-04-27 06:56:47 +00001141your PCI devices won't get interrupts.
Stefan Reinauerc0f4e2a2004-02-10 16:53:55 +00001142It's likely that more ACPI support will follow, when there is need for certain
1143features.
1144
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001145\subsection{POST}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001146coreboot has three different methods of handling POST codes. They can
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001147be triggered using configuration file options.
1148\begin{itemize}
1149\item
1150\emph{Ignore POST completely}. No early code debugging is possible with
1151this setting. Set the configuration variable \texttt{NO\_POST} to
Stefan Reinauerebf25892009-04-21 21:45:11 +00001152\texttt{1} to switch off all POST handling in coreboot.
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001153\item
1154\emph{Normal IO port 80 POST}. This is the default behavior of
Stefan Reinauerebf25892009-04-21 21:45:11 +00001155coreboot. No configuration variables have to be set. To be able to see
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001156port 80 POST output, you need a POST expansion card for ISA or PCI. Port
115780 POST allows simple debugging without any other output method
1158available (serial interface or VGA display)
1159\item
Stefan Reinauer14e22772010-04-27 06:56:47 +00001160\emph{Serial POST}.
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001161This option allows to push POST messages to the serial interface instead
1162of using IO ports. \textbf{NOTE:} The serial interface has to be
1163initialized before serial POST can work. To use serial POST, set the
1164configuration variable \texttt{CONFIG\_SERIAL\_POST} to the value 1.
1165\end{itemize}
1166
1167
1168\subsection{HDT Debugging}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001169If you are debugging your coreboot code with a Hardware Debug Tool
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001170(HDT), you can find the source code line for a given physical EIP
1171address as follows: Look the address up in the file linuxbios.map. Then
1172search the label Lxx in the file auto.inc created by romcc. The original
1173source code file and line number is mentioned in auto.inc.
1174
1175
1176\subsection{Device Drivers}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001177With only a few data structures coreboot features a simple but flexible
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001178device driver interface. This interface is not intended for autonomously
1179driving the devices but to initialize all system components so that they
1180can be used by the booted operating system.
1181
1182Since nowadays most systems are PCI centric, the data structures used
1183are tuned towards (onboard and expansion bus) PCI devices. Each driver
1184consists of at least two structures.
1185
1186The \texttt{pci\_driver} structure maps PCI vendor/device id pairs to a
1187second structure that describes a set of functions that together
1188initialize and operate the device:
1189
1190\begin{verbatim}
1191 static void adaptec_scsi_init(struct device *dev)
1192 {
1193 [..]
1194 }
1195 static struct device_operations lsi_scsi_ops = {
1196 .read_resources = pci_dev_read_resources,
1197 .set_resources = pci_dev_set_resources,
1198 .enable_resources = pci_dev_enable_resources,
1199 .init = lsi_scsi_init,
1200 .scan_bus = 0,
1201 };
Stefan Reinauer8e96ba22010-03-16 23:33:29 +00001202 static const struct pci_driver lsi_scsi_driver __pci_driver = {
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001203 .ops = &lsi_scsi_ops,
1204 .vendor = 0xXXXX,
1205 .device = 0xXXXX,
1206 };
1207\end{verbatim}
1208
1209By separating the two structures above, M:N relations between compatible
1210devices and drivers can be described. The driver source code containing
Stefan Reinauerebf25892009-04-21 21:45:11 +00001211above data structures and code have to be added to a coreboot image
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001212using the driver keyword in the mainboard specific configuration file \\
Stefan Reinauerebf25892009-04-21 21:45:11 +00001213\texttt{coreboot-v2/src/mainboard/<vendor>/<mainboard>/Config.lb}:
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001214
1215\begin{verbatim}
1216 driver lsi_scsi.o
1217\end{verbatim}
1218
1219\subsection{Bus Bridges}
1220
Stefan Reinauerebf25892009-04-21 21:45:11 +00001221Currently all bridges supported in the coreboot-v2 tree are transparent
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001222bridges. This means, once the bridge is initialized, it's remote devices
Stefan Reinauerebf25892009-04-21 21:45:11 +00001223are visible on one of the PCI buses without special probing. coreboot
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001224supports also bridges that are nontransparent. The driver support code
1225can provide a \texttt{scan\_bus} function to scan devices behind the bridge.
1226
1227\subsection{CPU Reset}
1228When changing speed and width of hypertransport chain connections
Stefan Reinauerebf25892009-04-21 21:45:11 +00001229coreboot has to either assert an LDTSTOP or a reset to make the changes
1230become active. Additionally Linux can do a firmware reset, if coreboot
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001231provides the needed infrastructure. To use this capability, define the
Uwe Hermann105c1552009-09-04 19:25:51 +00001232option \texttt{CONFIG\_HAVE\_HARD\_RESET} and add an object file specifying the
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001233reset code in your mainboard specific configuration file
Stefan Reinauerebf25892009-04-21 21:45:11 +00001234\texttt{coreboot-v2/src/mainboard/$<$vendor$>$/$<$mainboard$>$/Config.lb}:
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001235
1236\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +00001237 default CONFIG_HAVE_HARD_RESET=1
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001238 object reset.o
1239\end{verbatim}
1240
1241The C source file \texttt{reset.c} (resulting in \texttt{reset.o}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001242during compilation) shall define the following function to take care
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001243of the system reset:
1244
1245\begin{verbatim}
1246 void hard_reset(void);
1247\end{verbatim}
1248
Stefan Reinauerebf25892009-04-21 21:45:11 +00001249See \texttt{coreboot-v2/src/mainboard/arima/hdama/reset.c} for an example
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001250implementation.
1251
1252\newpage
1253
1254%
Stefan Reinauerebf25892009-04-21 21:45:11 +00001255% 11. coreboot Internals
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001256%
1257
Stefan Reinauerebf25892009-04-21 21:45:11 +00001258\section{coreboot Internals}
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001259This chapter covers some of the internal structures and algorithms of
Stefan Reinauerebf25892009-04-21 21:45:11 +00001260coreboot that have not been mentioned so far.
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001261
1262\subsection{Code Flow}
1263
1264\begin{figure}[htb]
1265\centering
1266\includegraphics[scale=0.7]{codeflow.pdf}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001267\caption{coreboot rough Code Flow}
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001268\label{fix:codeflow}
1269\end{figure}
1270
1271\newpage
1272
1273\subsection{Fallback mechanism}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001274coreboot provides a mechanism to pack two different coreboot builds
1275within one coreboot ROM image. Using the system CMOS memory coreboot
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001276determines whether the last boot with a default image succeeded and
1277boots a failsafe image on failure. This allows insystem testing without
1278the risk to render the system unusable. See
Stefan Reinauerebf25892009-04-21 21:45:11 +00001279\texttt{coreboot-v2/src/mainboard/arima/hdama/failover.c} for example
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001280code. The fallback mechanism can be used with the \texttt{cmos\_util}.
1281
1282\subsection{(Un) Supported Standards}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001283coreboot supports the following standards
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001284\begin{itemize}
1285\item Multiprocessing Specification (MPSPEC) 1.4
Stefan Reinauerc0f4e2a2004-02-10 16:53:55 +00001286\item IRQ Tables (PIRQ)
1287\item ACPI (initial support on AMD64)
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001288\item Elf Booting
1289\end{itemize}
1290However, the following standards are not supported until now, and will
1291probably not be supported in future revisions:
1292\begin{itemize}
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001293\item APM
1294\end{itemize}
1295
Stefan Reinauerebf25892009-04-21 21:45:11 +00001296\subsection{coreboot table}
1297coreboot stores information about the system in a data structure called
1298the coreboot table. This table can be read under Linux using the tool
1299nvramtool from the Lawrence Livermore National Laboratory.
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001300
1301Get more information about lxbios and the utility itself at
1302\url{http://www.llnl.gov/linux/lxbios/lxbios.html}
1303
1304\subsection{ROMCC limitations}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001305ROMCC, part of the coreboot project, is a C compiler that translates to
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001306completely rommable code. This means the resulting code does not need
Stefan Reinauerebf25892009-04-21 21:45:11 +00001307any memory to work. This is one of the major improvements in coreboot
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001308V2, since it allows almost all code to be written in C. DRAM
1309initialization can be factored and reused more easily among mainboards
1310and platforms.
1311
1312Since no memory is available during this early initialization point,
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001313romcc has to map all used variables in registers for the time being.
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001314Same applies for their stack usage. Generally the less registers are
1315used up by the algorithms, the better code can be factored, resulting in
1316a smaller object size. Since getting the best register usage is an NP
1317hard problem, some heuristics are used to get reasonable translation
1318time. If you run out of registers during compilation, try to refactor
1319your code.
1320
1321\subsection{CMOS handling}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001322coreboot can use the mainboard's CMOS memory to store information
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001323defined in a data structure called the CMOS table . This information
1324contains serial line speed, fallback boot control, output verbosity,
1325default boot device, ECC control, and more. It can be easily enhanced by
1326enhancing the CMOS table. This table, if present, is found at
Stefan Reinauerebf25892009-04-21 21:45:11 +00001327\texttt{coreboot-v2/src/mainboard/$<$vendor$>$/$<$mainboard$>$/cmos.layout}.
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001328It describes the available options, their possible values and their
1329position within the CMOS memory. The layout file looks as follows:
1330\begin{verbatim}
1331 # startbit length config configID name
1332 [..]
1333 392 3 e 5 baud_rate
1334 [..]
Stefan Reinauer14e22772010-04-27 06:56:47 +00001335
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001336 # configid value human readable description
1337 5 0 115200
1338 5 1 57600
1339 5 2 38400
1340 5 3 19200
1341 5 4 9600
1342 5 5 4800
1343 5 6 2400
1344 5 7 1200
Stefan Reinauer14e22772010-04-27 06:56:47 +00001345
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001346\end{verbatim}
1347
1348To change CMOS values from a running Linux system, use the
Stefan Reinauerebf25892009-04-21 21:45:11 +00001349\texttt{cmos\_util}, provided by Linux Networks as part of the coreboot
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001350utilities suite. Get it at
1351\textit{ftp://ftp.lnxi.com/pub/linuxbios/utilities/}
1352
1353\subsection {Booting Payloads}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001354coreboot can load a payload binary from a Flash device or IDE. This
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001355payload can be a boot loader, like FILO or Etherboot, a kernel image, or
Ronald G. Minnich34fc4ab2014-10-06 15:30:37 +00001356any other static ELF binary. If you specify a bzImage as the payload,
1357the cbfs utility will figure out how to create a coreboot payload from it.
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001358
1359\subsection{Kernel on dhcp/tftp}
1360
1361One possible scenario during testing is that you keep your kernel (or
1362any additional payload) on a different machine on the network. This can
1363quickly be done using a DHCP and TFTP server.
1364
1365Use for example following \texttt{/etc/dhcpd.conf} (adapt to your
1366network):
1367
1368\begin{verbatim}
1369 subnet 192.168.1.0 netmask 255.255.255.0 {
1370 range 192.168.1.0 192.168.1.31;
1371 option broadcastaddress 192.168.1.255;
1372 }
Stefan Reinauer14e22772010-04-27 06:56:47 +00001373
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001374 ddnsupdatestyle adhoc;
Stefan Reinauer14e22772010-04-27 06:56:47 +00001375
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001376 host hammer12 {
1377 hardware ethernet 00:04:76:EA:64:31;
1378 fixedaddress 192.168.1.24;
1379 filename "vmlinuz.elf";
1380 }
1381\end{verbatim}
1382
1383
1384Additionally you have to run a \texttt{tftp} server. You can start one
1385using \texttt{inetd}. To do this, you have to remove the comment from
1386the following line in \texttt{/etc/inetd.conf}:
1387
1388\begin{verbatim}
1389 tftp dgram udp wait root /usr/sbin/in.tftpd in.tftpd -s /tftpboot
1390\end{verbatim}
1391
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001392Then put your kernel image \texttt{vmlinuz.elf} in \texttt{/tftpboot} on
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001393the \texttt{tftp} server.
1394
1395
1396\newpage
1397
1398%
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001399% 12. Advanced Device Initialization Mechanisms
1400%
1401
1402\section{Advanced Device Initialization Mechanisms}
1403
1404Like software, today's hardware is getting more and more complex. To
1405stay flexible many hardware vendors start breaking hardware
Stefan Reinauer2c83b272004-06-02 11:25:31 +00001406compatibility to old standards like VGA. Thus, VGA is still supported by
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001407most cards, but emulation has to be enabled by the firmware for the
1408device to operate properly. Also, many expansion cards are small
1409discrete systems that have to initialize attached ram, download
1410controller firmware and similar. Without this initialization, an
1411operating system can not take advantage of the hardware, so there needs
1412to be a way to address this issue. There are several alternatives:
1413
Stefan Reinauerebf25892009-04-21 21:45:11 +00001414\subsection{Native coreboot Support}
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001415
Stefan Reinauerebf25892009-04-21 21:45:11 +00001416For some devices (ie Trident Cyberblade 3d) there is native coreboot
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001417support This means there is a small driver bound to the PCI id of the
1418device that is called after PCI device ressources are allotted.
1419
1420PROs:
1421 \begin{itemize}
1422 \item open source
1423 \item minimal driver
1424 \item early control
1425 \end{itemize}
1426
1427CONs:
1428 \begin{itemize}
1429 \item need an additional driver
1430 \item viable for onboard devices only
1431 \item not flexible for pci cards
1432 \end{itemize}
1433
1434\subsection{Using Native Linux Support}
1435
Stefan Reinauerebf25892009-04-21 21:45:11 +00001436A simple way of getting a whole lot of drivers available for coreboot
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001437is to reuse Linux drivers by putting a Linux kernel to flash. This
1438works, because no drivers are needed to get the Linux kernel (as opposed
1439to store the kernel on a harddisk connected to isa/scsi/raid storage)
1440
1441PROs:
1442 \begin{itemize}
1443 \item large number of open source drivers
1444 \end{itemize}
1445
1446CONs:
1447 \begin{itemize}
1448 \item need Linux in Flash (BLOAT!)
1449 \item drivers expect devices to be initialized (LSI1020/1030)
1450 \item Linux only
1451 \item large flash needed (4MBit minimum, normal operations 8+ MBit)
1452 \end{itemize}
1453
1454
1455\subsection{Running X86 Option ROMs}
1456
1457Especially SCSI/RAID controllers and graphics adapters come with a
1458special option rom. This option rom usually contains x86 binary code
1459that uses a legacy PCBIOS interface for device interaction. If this code
1460gets executed, the device becomes operable in Linux and other operating
1461systems.
1462
1463PROs:
1464 \begin{itemize}
1465 \item really flexible
1466 \item no need for additional drivers on firmware layer
1467 \item large number of supported devices
1468 \end{itemize}
1469
1470CONs:
1471 \begin{itemize}
1472 \item non-x86 platforms need complex emulation
1473 \item x86 platforms need legacy API
1474 \item outdated concept
1475 \end{itemize}
1476
1477
1478\subsection{Running Open Firmware Option ROMs}
1479
1480Some PCI devices come with open firmware option roms. These devices are
1481normally found in computers from SUN, Apple or IBM. Open Firmware is a
1482instruction set architecture independent firmware standard that allows
1483device specific initialization using simple, small, but flexible
1484bytecode that runs with minimal footprint on all architectures that have
1485an Open Firmware implementation.
1486
1487There is a free Open Firmware implementation available, called OpenBIOS,
Stefan Reinauerebf25892009-04-21 21:45:11 +00001488that runs on top of coreboot. See www.openbios.org
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001489
1490PROs:
1491 \begin{itemize}
1492 \item architecture independence
1493 \item small footprint
1494 \item clean concept, less bugs
1495 \end{itemize}
1496
1497CONs:
1498 \begin{itemize}
1499 \item only small number of devices come with OpenFirmware capable option roms
1500 \end{itemize}
1501
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001502%
1503% 13 image types
1504%
1505
1506\section{Image types}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001507There used to be one image type for coreboot, as described above. Since this paper was written (2004) there have been many changes. First, the name
Stefan Reinauer236d1022009-04-21 22:05:50 +00001508was changed to coreboot, for many reasons. Second, Cache As Ram support (CAR)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001509was added for many AMD CPUs, which both simplified and complicated things. Simplification came with the removal of romcc; complication came with the addition of new ways to build.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001510
Stefan Reinauer14e22772010-04-27 06:56:47 +00001511There are two big additions to the build process and, furthermore, more than two new CONFIG variables to control them.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001512
1513\begin{itemize}
Stefan Reinauer08670622009-06-30 15:17:49 +00001514\item \begin{verbatim}CONFIG_USE_DCACHE_RAM\end{verbatim}
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001515
1516Set to \texttt{1} to use Cache As Ram (CAR). Defaults to \texttt{0}
1517
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001518\end{itemize}
1519
1520Before going over the new image types, derived from v3, we will quickly review the standard v2 image types. We are hoping this review will
Stefan Reinauer14e22772010-04-27 06:56:47 +00001521aid comprehension.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001522
Stefan Reinauer14e22772010-04-27 06:56:47 +00001523A coreboot rom file consists of one or more \textit{images}. All images consist of a part that runs in ROM, and a part that runs in RAM. The RAM can be in compressed form and is decompressed when needed by the ROM code. The main function of the ROM code is to get memory working. Both ROM and RAM consist of a very small amount of assembly code and mostly C code.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001524
Ronald G. Minnich2cecce52009-04-20 15:36:57 +00001525\subsection{romcc images (from emulation/qemu)}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001526ROMCC images are so-called because C code for the ROM part is compiled with romcc. romcc is an optimizing C compiler which compiles one, and only
1527one file; to get more than one file, one must include the C code via include statements. The main ROM code .c file is usually called auto.c.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001528\subsubsection{How it is built}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001529Romcc compiles auto.c to produce auto.inc. auto.inc is included in the main crt0.S, which is then preprocessed to produce crt0.s. The inclusion of files into crt0.S is controlled by the CONFIG\_CRT0\_INCLUDES variable. crt0.s is then assembled.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001530
Stefan Reinauer14e22772010-04-27 06:56:47 +00001531File for the ram part are compiled in a conventional manner.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001532
Stefan Reinauer14e22772010-04-27 06:56:47 +00001533The final step is linking. The use of named sections is used very heavily in coreboot to control where different bits of code go. The reset vector must go in the top 16 bytes. The start portion of the ROM code must go in the top 64K bytes, since most chipsets only enable this much ROM at startup time. Here is a quick look at a typical image:
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001534\begin{verbatim}
1535 [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
1536 [ 0] NULL 00000000 000000 000000 00 0 0 0
1537 [ 1] .ram PROGBITS ffff0000 001000 005893 00 WA 0 0 1
1538 [ 2] .rom PROGBITS ffff5893 006893 00029d 00 AX 0 0 16
1539 [ 3] .reset PROGBITS fffffff0 006ff0 000010 00 A 0 0 1
1540 [ 4] .id PROGBITS ffffffd1 006fd1 00001f 00 A 0 0 1
1541 [ 5] .shstrtab STRTAB 00000000 007000 000030 00 0 0 1
1542 [ 6] .symtab SYMTAB 00000000 007170 000c30 10 7 37 4
1543 [ 7] .strtab STRTAB 00000000 007da0 000bfd 00 0 0 1
1544\end{verbatim}
1545
Stefan Reinauer14e22772010-04-27 06:56:47 +00001546The only sections that get loaded into a ROM are the Allocated ones. We can see the .ram, .rom, .reset and .id sections.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001547\subsubsection{layout}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001548As we mentioned, the ROM file consists of multiple images. In the basic file, there are two full coreboot rom images. The build sequence for each is the same, and in fact the ldscript.ld files are almost identical. The only difference is in a few makefile variables, generated by the config tool.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001549
1550\begin{itemize}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001551\item CONFIG\_PAYLOAD\_SIZE. Each image may have a different payload size.
1552\item CONFIG\_ROMBASE Each image must have a different base in rom.
1553\item CONFIG\_RESET Unclear what this is used for.
Uwe Hermann105c1552009-09-04 19:25:51 +00001554\item CONFIG\_EXCEPTION\_VECTORS where an optional IDT might go.
Stefan Reinauer14e22772010-04-27 06:56:47 +00001555\item CONFIG\_USE\_OPTION\_TABLE if set, an option table section will be linked in.
1556\item CONFIG\_ROM\_PAYLOAD\_START This is the soon-to-be-deprecated way of locating a payload. cbfs eliminates this.
Uwe Hermann105c1552009-09-04 19:25:51 +00001557\item CONFIG\_USE\_FALLBACK\_IMAGE Whether this is a fallback or normal image
Stefan Reinauer14e22772010-04-27 06:56:47 +00001558\item CONFIG\_ROM\_SECTION\_SIZE Essentially, the payload size. Soon to be deprecated.
Uwe Hermann105c1552009-09-04 19:25:51 +00001559\item CONFIG\_ROM\_IMAGE\_SIZE Size of this image (i.e. fallback or normal image)
1560\item CONFIG\_ROM\_SIZE Total size of the ROM
Stefan Reinauer14e22772010-04-27 06:56:47 +00001561\item CONFIG\_XIP\_RAM\_BASE The start of eXecute In Place code. XIP allows for not copying code to ram, but just running it from ROM.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001562\end{itemize}
1563
Stefan Reinauer14e22772010-04-27 06:56:47 +00001564Each image (normal or fallback) is built completely independently and does not get linked to the other. They are assembled into one ROM image by the (soon to be deprecated) buildrom tool, or by the cbfs tool.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001565
1566\subsubsection{boot sequence}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001567We boot and start at fffffff0. We then jump to the entry point at \_start. \_start does some machine init and an lgdt and jumps to \_\_protected\_start, at which point we are in protected mode. The code does a bit more machine setup and then starts executing the romcc code.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001568
Stefan Reinauer14e22772010-04-27 06:56:47 +00001569If fallback has been built in, some setup needs to be done. On some machines, it is extensive. Full rom decoding must be enabled. This may in turn require additional PCI setup to enable decoding to be enabled (!). To decided which image to use, hardware registers (cold boot on the Opteron) or CMOS are checked. Finally, once the image to use has been decided, a jmp is performed, viz:
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001570\begin{verbatim}
1571 /* This is the primary cpu how should I boot? */
1572 else if (do_normal_boot()) {
1573 goto normal_image;
1574 }
1575 else {
1576 goto fallback_image;
1577 }
1578 normal_image:
1579 __asm__ volatile ("jmp __normal_image"
1580 : /* outputs */
1581 : "a" (bist), "b" (cpu_init_detectedx) /* inputs */
1582 );
1583
1584 fallback_image:
Stefan Reinauer08670622009-06-30 15:17:49 +00001585#if CONFIG_HAVE_FAILOVER_BOOT==1
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001586 __asm__ volatile ("jmp __fallback_image"
1587 : /* outputs */
1588 : "a" (bist), "b" (cpu_init_detectedx) /* inputs */
1589 )
1590#endif
1591 ;
1592\end{verbatim}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001593How does the fallback image get the symbol for normal entry? Via magic in the ldscript.ld -- remember, the images are not linked to each other.
1594Finally, we can see this in the Config.lb for most mainboards:
Ronald G. Minnich2cecce52009-04-20 15:36:57 +00001595\begin{verbatim}
Stefan Reinauer08670622009-06-30 15:17:49 +00001596if CONFIG_USE_FALLBACK_IMAGE
Ronald G. Minnich2cecce52009-04-20 15:36:57 +00001597 mainboardinit cpu/x86/16bit/reset16.inc
1598 ldscript /cpu/x86/16bit/reset16.lds
1599else
1600 mainboardinit cpu/x86/32bit/reset32.inc
1601 ldscript /cpu/x86/32bit/reset32.lds
1602end
1603\end{verbatim}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001604What does this mean? the non-fallback image has a 32-bit entry point; fallback has a 16-bit entry point. The reason for this is that some code from fallback always runs, so as to pick fallback or normal; but the normal is always called from 32-bit code.
Ronald G. Minnich2cecce52009-04-20 15:36:57 +00001605\subsection{car images (from lippert/roadrunner-lx)}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001606CAR images in their simplest form are modified romcc images. The file is usually cache\_as\_ram\_auto.c. C inclusion is still used. The main difference is in the build sequence. The compiler command line is a very slight changed: instead of using romcc to generate an auto.inc include file, gcc us used. Then, two perl scripts are used to rename the .text and .data sections to .rom.text and .rom.data respectively.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001607\subsubsection{How it is built}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001608The build is almost identical to the romcc build. Since the auto.inc file exists, it can be included as before. The crt0\_includes.h file has one addition: a file that enables CAR, in this case it is \textit{src/cpu/amd/model\_lx/cache\_as\_ram.inc}.
Ronald G. Minnich2cecce52009-04-20 15:36:57 +00001609\subsubsection{layout}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001610No significant change from romcc code.
Ronald G. Minnich2cecce52009-04-20 15:36:57 +00001611\subsubsection{boot sequence}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001612No significant change from romcc code, except that the CAR code has to set up a stack.
Ronald G. Minnich2cecce52009-04-20 15:36:57 +00001613
Ronald G. Minnichb88a1fc2009-04-20 22:10:34 +00001614\subsection{car + CONFIG\_USE\_INIT images (new emulation/qemu}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001615This type of image makes more use of the C compiler. In this type of image, in fact,
1616seperate compilation is possible but is not always used. Oddly enough, this option is only used in PPC boards. That said, we need to move to this way of building. Including C code is poor style.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001617\subsubsection{How it is built}
Ronald G. Minnichb88a1fc2009-04-20 22:10:34 +00001618There is a make variable, INIT-OBJECTS, that for all our other targets is empty. In this type of build, INIT-OBJECTS is a list of C files that are created from the config tool initobject command. Again, with INIT-OBJECTS we can finally stop including .c files and go with seperate compilation.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001619\subsubsection{layout}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001620No significant change from romcc code.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001621\subsubsection{boot sequence}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001622No significant change from romcc code, except that the CAR code has to set up a stack.
Ronald G. Minnichb88a1fc2009-04-20 22:10:34 +00001623
1624\subsubsection{layout}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001625No significant change from romcc code.
Ronald G. Minnichb88a1fc2009-04-20 22:10:34 +00001626\subsubsection{boot sequence}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001627No significant change from romcc code, except that the CAR code has to set up a stack.
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001628\subsection{failover}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001629Failover is the newest way to lay out a ROM. The choice of which image to run is removed from the fallback image and moved into a small, standalone piece of code. The code is simple enough to show here:
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001630\begin{verbatim}
1631static unsigned long main(unsigned long bist)
1632{
1633 if (do_normal_boot())
1634 goto normal_image;
1635 else
1636 goto fallback_image;
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001637
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001638normal_image:
1639 __asm__ __volatile__("jmp __normal_image" : : "a" (bist) : );
1640
1641cpu_reset:
1642 __asm__ __volatile__("jmp __cpu_reset" : : "a" (bist) : );
1643
1644fallback_image:
1645 return bist;
1646}
1647
1648\end{verbatim}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001649Some motherboards have a more complex bus structure (e.g. Opteron). In those cases, the failover can be more complex, as it requires some hardware initialization to work correctly. As of this writing (April 2009), these boards have their own failover:
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001650\begin{quote}
1651./src/mainboard/iei/nova4899r/failover.c
1652./src/mainboard/emulation/qemu-x86/failover.c
Uwe Hermann503959c2009-05-12 14:01:14 +00001653./src/mainboard/supermicro/x6dhr\_ig/failover.c
1654./src/mainboard/supermicro/x6dai\_g/failover.c
1655./src/mainboard/supermicro/x6dhe\_g2/failover.c
1656./src/mainboard/supermicro/x6dhr\_ig2/failover.c
1657./src/mainboard/supermicro/x6dhe\_g/failover.c
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001658./src/mainboard/dell/s1850/failover.c
1659./src/mainboard/intel/xe7501devkit/failover.c
1660./src/mainboard/intel/jarrell/failover.c
1661./src/mainboard/olpc/btest/failover.c
Uwe Hermann503959c2009-05-12 14:01:14 +00001662./src/mainboard/olpc/rev\_a/failover.c
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001663./src/mainboard/via/epia-m/failover.c
1664\end{quote}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001665Here is one of the more complicated ones:
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001666\begin{verbatim}
1667static unsigned long main(unsigned long bist)
1668{
1669 /* Did just the cpu reset? */
1670 if (memory_initialized()) {
1671 if (last_boot_normal()) {
1672 goto normal_image;
1673 } else {
1674 goto cpu_reset;
1675 }
1676 }
1677
1678 /* This is the primary cpu how should I boot? */
1679 else if (do_normal_boot()) {
1680 goto normal_image;
1681 }
1682 else {
1683 goto fallback_image;
1684 }
1685 normal_image:
1686 asm volatile ("jmp __normal_image"
1687 : /* outputs */
1688 : "a" (bist) /* inputs */
1689 : /* clobbers */
1690 );
1691 cpu_reset:
1692 asm volatile ("jmp __cpu_reset"
1693 : /* outputs */
1694 : "a"(bist) /* inputs */
1695 : /* clobbers */
1696 );
1697 fallback_image:
1698 return bist;
1699}
1700
1701\end{verbatim}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001702They're not that different, in fact. So why are there different copies all over the tree? Simple: code inclusion. Most of the failover.c are different because they include different bits of code. Here is a key reason for killing C code inclusion in the tree.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001703\subsubsection{How it is built}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001704There two additional config variables:
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001705\begin{itemize}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001706\item HAVE\_FAILOVER\_IMAGE Has to be defined when certain files are included.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001707\item USE\_FAILOVER\_IMAGE Enables the use of the failover image
1708\end{itemize}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001709Confusingly enough, almost all the uses of these two variables are either nested or both required to be set, e.g.
1710The fallback and normal builds are the same. The target config has a new clause that looks like this:
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001711\begin{verbatim}
1712romimage "failover"
Stefan Reinauer08670622009-06-30 15:17:49 +00001713 option CONFIG_USE_FAILOVER_IMAGE=1
1714 option CONFIG_USE_FALLBACK_IMAGE=0
1715 option CONFIG_ROM_IMAGE_SIZE=CONFIG_FAILOVER_SIZE
1716 option CONFIG_XIP_ROM_SIZE=CONFIG_FAILOVER_SIZE
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001717 option COREBOOT_EXTRA_VERSION="\$(shell cat ../../VERSION)\_Failover"
1718end
1719\end{verbatim}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001720This new section uses some constructs not yet discussed in detail. XIP\_ROM\_SIZE just refers to the
1721fact that the failover code is eXecute In Place, i.e. not copied to RAM. Of course, the ROM part of normal/fallback is as well, so the usage of XIP here is somewhat confusing. Finally, the USE\_FAILOVER\_IMAGE variable is set, which changes code compilation in a few places. If we just consider non-mainbard files, there are:
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001722\begin{verbatim}
1723src/cpu/amd/car/cache_as_ram.inc
1724src/arch/i386/Config.lb
1725\end{verbatim}
1726For the cache\_as\_ram.inc file, the changes relate to the fact that failover code sets up CAR, so that fallback code need not.
1727
Stefan Reinauer14e22772010-04-27 06:56:47 +00001728For the Config.lb, several aspects of build change.
1729When USE\_FAILOVER\_IMAGE, entry into both normal and fallback bios images is via a 32-bit entry point (when not defined, entry into fallback is a 16-entry point at the power-on reset vector).
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001730\subsubsection{layout}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001731Failover.c becomes the new bootblock at the top of memory. It calls either normal or fallback. The address of normal and fallback is determined by ldscript magic.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001732\subsubsection{boot sequence}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001733failover.c tests a few variables and the calls the normal or fallback payload depending on those variables; usually they are CMOS settings.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001734\subsection{Proposed new image forat}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001735The new image format will use seperate compilation -- no C code included! -- on all files.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001736
Stefan Reinauer14e22772010-04-27 06:56:47 +00001737The new design has a few key goals:
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001738\begin{itemize}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001739\item Always use a bootblock (currently called failover).
1740The name failover.c, being utterly obscure, will not be used; instead, we will name the file bootblock.c. Instead of having a different copy for each mainboard, we can have just one copy.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001741\item Always use seperate compilation
1742\item Always use printk etc. in the ROM code
Stefan Reinauer14e22772010-04-27 06:56:47 +00001743\item (longer term) from the bootblock, always use cbfs to locate the normal/fallback etc. code. This code will be XIP.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001744\end{itemize}
1745
1746\subsubsection{How it is built}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001747For now, since we are still using the config tool, we'll need a new command: bootblockobject, which creates a list of files to be included in the bootblock. Not a lot else will have to change. We are going to move to using the v3 CAR code assembly code (one or two files at most, instead of many) and, instead of the thicket of little ldscript files, one ldscript file. This strategy is subject to modification as events dictate.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001748\subsubsection{layout}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001749Almost the same, for now, as the current failover code.
Ronald G. Minnich2c245ff2009-04-23 03:59:33 +00001750\subsubsection{boot sequence}
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001751%
Ronald G. Minnichef5f8a72009-04-17 16:18:02 +00001752% 14 Glossary
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001753%
1754
1755\section{Glossary}
1756\begin{itemize}
1757\item payload
1758
Stefan Reinauerebf25892009-04-21 21:45:11 +00001759coreboot only cares about low level machine initialization, but also has
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001760very simple mechanisms to boot a file either from FLASHROM or IDE. That
1761file, possibly a Linux Kernel, a boot loader or Etherboot, are called
1762payload, since it is the first software executed that does not cope with
1763pure initialization.
1764
1765\item flash device
1766
1767Flash devices are commonly used in all different computers since unlike
1768ROMs they can be electronically erased and reprogrammed.
1769\end{itemize}
1770
1771\newpage
1772
1773%
Stefan Reinauerf69f7e22004-02-10 17:30:04 +00001774% 14 Bibliography
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001775%
1776
1777\section{Bibliography}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001778\subsection{Additional Papers on coreboot}
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001779
1780\begin{itemize}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001781 \item
Stefan Reinauerebf25892009-04-21 21:45:11 +00001782 \textit{\url{http://www.coreboot.org/Documentation}}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001783 \item
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001784 \textit{\url{http://www.lysator.liu.se/upplysning/fa/linuxbios.pdf}}
Stefan Reinauer14e22772010-04-27 06:56:47 +00001785 \item
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001786 \textit{\url{http://portal.acm.org/citation.cfm?id=512627}}
1787\end{itemize}
1788
1789\subsection {Links}
1790
1791\begin{itemize}
1792 \item Etherboot: \textit{\url{http://www.etherboot.org/}}
Stefan Reinauerebf25892009-04-21 21:45:11 +00001793 \item Filo: \textit{\url{http://www.coreboot.org/FILO}}
Stefan Reinauer37414ca2003-11-22 15:15:47 +00001794 \item OpenBIOS: \textit{\url{http://www.openbios.org/}}
1795\end{itemize}
1796
1797\end{document}