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