xref: /openbmc/linux/Documentation/powerpc/booting.rst (revision 441848282c59038b6e9a57b233ac6a9449430648)
1*44184828SRob Herring.. SPDX-License-Identifier: GPL-2.0
2*44184828SRob Herring
3*44184828SRob HerringDeviceTree Booting
4*44184828SRob Herring------------------
5*44184828SRob Herring
6*44184828SRob HerringDuring the development of the Linux/ppc64 kernel, and more specifically, the
7*44184828SRob Herringaddition of new platform types outside of the old IBM pSeries/iSeries pair, it
8*44184828SRob Herringwas decided to enforce some strict rules regarding the kernel entry and
9*44184828SRob Herringbootloader <-> kernel interfaces, in order to avoid the degeneration that had
10*44184828SRob Herringbecome the ppc32 kernel entry point and the way a new platform should be added
11*44184828SRob Herringto the kernel. The legacy iSeries platform breaks those rules as it predates
12*44184828SRob Herringthis scheme, but no new board support will be accepted in the main tree that
13*44184828SRob Herringdoesn't follow them properly.  In addition, since the advent of the arch/powerpc
14*44184828SRob Herringmerged architecture for ppc32 and ppc64, new 32-bit platforms and 32-bit
15*44184828SRob Herringplatforms which move into arch/powerpc will be required to use these rules as
16*44184828SRob Herringwell.
17*44184828SRob Herring
18*44184828SRob HerringThe main requirement that will be defined in more detail below is the presence
19*44184828SRob Herringof a device-tree whose format is defined after Open Firmware specification.
20*44184828SRob HerringHowever, in order to make life easier to embedded board vendors, the kernel
21*44184828SRob Herringdoesn't require the device-tree to represent every device in the system and only
22*44184828SRob Herringrequires some nodes and properties to be present. For example, the kernel does
23*44184828SRob Herringnot require you to create a node for every PCI device in the system. It is a
24*44184828SRob Herringrequirement to have a node for PCI host bridges in order to provide interrupt
25*44184828SRob Herringrouting information and memory/IO ranges, among others. It is also recommended
26*44184828SRob Herringto define nodes for on chip devices and other buses that don't specifically fit
27*44184828SRob Herringin an existing OF specification. This creates a great flexibility in the way the
28*44184828SRob Herringkernel can then probe those and match drivers to device, without having to hard
29*44184828SRob Herringcode all sorts of tables. It also makes it more flexible for board vendors to do
30*44184828SRob Herringminor hardware upgrades without significantly impacting the kernel code or
31*44184828SRob Herringcluttering it with special cases.
32*44184828SRob Herring
33*44184828SRob Herring
34*44184828SRob HerringEntry point
35*44184828SRob Herring~~~~~~~~~~~
36*44184828SRob Herring
37*44184828SRob HerringThere is one single entry point to the kernel, at the start
38*44184828SRob Herringof the kernel image. That entry point supports two calling
39*44184828SRob Herringconventions:
40*44184828SRob Herring
41*44184828SRob Herring        a) Boot from Open Firmware. If your firmware is compatible
42*44184828SRob Herring        with Open Firmware (IEEE 1275) or provides an OF compatible
43*44184828SRob Herring        client interface API (support for "interpret" callback of
44*44184828SRob Herring        forth words isn't required), you can enter the kernel with:
45*44184828SRob Herring
46*44184828SRob Herring              r5 : OF callback pointer as defined by IEEE 1275
47*44184828SRob Herring              bindings to powerpc. Only the 32-bit client interface
48*44184828SRob Herring              is currently supported
49*44184828SRob Herring
50*44184828SRob Herring              r3, r4 : address & length of an initrd if any or 0
51*44184828SRob Herring
52*44184828SRob Herring              The MMU is either on or off; the kernel will run the
53*44184828SRob Herring              trampoline located in arch/powerpc/kernel/prom_init.c to
54*44184828SRob Herring              extract the device-tree and other information from open
55*44184828SRob Herring              firmware and build a flattened device-tree as described
56*44184828SRob Herring              in b). prom_init() will then re-enter the kernel using
57*44184828SRob Herring              the second method. This trampoline code runs in the
58*44184828SRob Herring              context of the firmware, which is supposed to handle all
59*44184828SRob Herring              exceptions during that time.
60*44184828SRob Herring
61*44184828SRob Herring        b) Direct entry with a flattened device-tree block. This entry
62*44184828SRob Herring        point is called by a) after the OF trampoline and can also be
63*44184828SRob Herring        called directly by a bootloader that does not support the Open
64*44184828SRob Herring        Firmware client interface. It is also used by "kexec" to
65*44184828SRob Herring        implement "hot" booting of a new kernel from a previous
66*44184828SRob Herring        running one. This method is what I will describe in more
67*44184828SRob Herring        details in this document, as method a) is simply standard Open
68*44184828SRob Herring        Firmware, and thus should be implemented according to the
69*44184828SRob Herring        various standard documents defining it and its binding to the
70*44184828SRob Herring        PowerPC platform. The entry point definition then becomes:
71*44184828SRob Herring
72*44184828SRob Herring                r3 : physical pointer to the device-tree block
73*44184828SRob Herring                (defined in chapter II) in RAM
74*44184828SRob Herring
75*44184828SRob Herring                r4 : physical pointer to the kernel itself. This is
76*44184828SRob Herring                used by the assembly code to properly disable the MMU
77*44184828SRob Herring                in case you are entering the kernel with MMU enabled
78*44184828SRob Herring                and a non-1:1 mapping.
79*44184828SRob Herring
80*44184828SRob Herring                r5 : NULL (as to differentiate with method a)
81*44184828SRob Herring
82*44184828SRob HerringNote about SMP entry: Either your firmware puts your other
83*44184828SRob HerringCPUs in some sleep loop or spin loop in ROM where you can get
84*44184828SRob Herringthem out via a soft reset or some other means, in which case
85*44184828SRob Herringyou don't need to care, or you'll have to enter the kernel
86*44184828SRob Herringwith all CPUs. The way to do that with method b) will be
87*44184828SRob Herringdescribed in a later revision of this document.
88*44184828SRob Herring
89*44184828SRob HerringBoard supports (platforms) are not exclusive config options. An
90*44184828SRob Herringarbitrary set of board supports can be built in a single kernel
91*44184828SRob Herringimage. The kernel will "know" what set of functions to use for a
92*44184828SRob Herringgiven platform based on the content of the device-tree. Thus, you
93*44184828SRob Herringshould:
94*44184828SRob Herring
95*44184828SRob Herring        a) add your platform support as a _boolean_ option in
96*44184828SRob Herring        arch/powerpc/Kconfig, following the example of PPC_PSERIES,
97*44184828SRob Herring        PPC_PMAC and PPC_MAPLE. The later is probably a good
98*44184828SRob Herring        example of a board support to start from.
99*44184828SRob Herring
100*44184828SRob Herring        b) create your main platform file as
101*44184828SRob Herring        "arch/powerpc/platforms/myplatform/myboard_setup.c" and add it
102*44184828SRob Herring        to the Makefile under the condition of your ``CONFIG_``
103*44184828SRob Herring        option. This file will define a structure of type "ppc_md"
104*44184828SRob Herring        containing the various callbacks that the generic code will
105*44184828SRob Herring        use to get to your platform specific code
106*44184828SRob Herring
107*44184828SRob HerringA kernel image may support multiple platforms, but only if the
108*44184828SRob Herringplatforms feature the same core architecture.  A single kernel build
109*44184828SRob Herringcannot support both configurations with Book E and configurations
110*44184828SRob Herringwith classic Powerpc architectures.
111