18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciDeviceTree Booting
48c2ecf20Sopenharmony_ci------------------
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciDuring the development of the Linux/ppc64 kernel, and more specifically, the
78c2ecf20Sopenharmony_ciaddition of new platform types outside of the old IBM pSeries/iSeries pair, it
88c2ecf20Sopenharmony_ciwas decided to enforce some strict rules regarding the kernel entry and
98c2ecf20Sopenharmony_cibootloader <-> kernel interfaces, in order to avoid the degeneration that had
108c2ecf20Sopenharmony_cibecome the ppc32 kernel entry point and the way a new platform should be added
118c2ecf20Sopenharmony_cito the kernel. The legacy iSeries platform breaks those rules as it predates
128c2ecf20Sopenharmony_cithis scheme, but no new board support will be accepted in the main tree that
138c2ecf20Sopenharmony_cidoesn't follow them properly.  In addition, since the advent of the arch/powerpc
148c2ecf20Sopenharmony_cimerged architecture for ppc32 and ppc64, new 32-bit platforms and 32-bit
158c2ecf20Sopenharmony_ciplatforms which move into arch/powerpc will be required to use these rules as
168c2ecf20Sopenharmony_ciwell.
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciThe main requirement that will be defined in more detail below is the presence
198c2ecf20Sopenharmony_ciof a device-tree whose format is defined after Open Firmware specification.
208c2ecf20Sopenharmony_ciHowever, in order to make life easier to embedded board vendors, the kernel
218c2ecf20Sopenharmony_cidoesn't require the device-tree to represent every device in the system and only
228c2ecf20Sopenharmony_cirequires some nodes and properties to be present. For example, the kernel does
238c2ecf20Sopenharmony_cinot require you to create a node for every PCI device in the system. It is a
248c2ecf20Sopenharmony_cirequirement to have a node for PCI host bridges in order to provide interrupt
258c2ecf20Sopenharmony_cirouting information and memory/IO ranges, among others. It is also recommended
268c2ecf20Sopenharmony_cito define nodes for on chip devices and other buses that don't specifically fit
278c2ecf20Sopenharmony_ciin an existing OF specification. This creates a great flexibility in the way the
288c2ecf20Sopenharmony_cikernel can then probe those and match drivers to device, without having to hard
298c2ecf20Sopenharmony_cicode all sorts of tables. It also makes it more flexible for board vendors to do
308c2ecf20Sopenharmony_ciminor hardware upgrades without significantly impacting the kernel code or
318c2ecf20Sopenharmony_cicluttering it with special cases.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciEntry point
358c2ecf20Sopenharmony_ci~~~~~~~~~~~
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciThere is one single entry point to the kernel, at the start
388c2ecf20Sopenharmony_ciof the kernel image. That entry point supports two calling
398c2ecf20Sopenharmony_ciconventions:
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci        a) Boot from Open Firmware. If your firmware is compatible
428c2ecf20Sopenharmony_ci        with Open Firmware (IEEE 1275) or provides an OF compatible
438c2ecf20Sopenharmony_ci        client interface API (support for "interpret" callback of
448c2ecf20Sopenharmony_ci        forth words isn't required), you can enter the kernel with:
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci              r5 : OF callback pointer as defined by IEEE 1275
478c2ecf20Sopenharmony_ci              bindings to powerpc. Only the 32-bit client interface
488c2ecf20Sopenharmony_ci              is currently supported
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci              r3, r4 : address & length of an initrd if any or 0
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci              The MMU is either on or off; the kernel will run the
538c2ecf20Sopenharmony_ci              trampoline located in arch/powerpc/kernel/prom_init.c to
548c2ecf20Sopenharmony_ci              extract the device-tree and other information from open
558c2ecf20Sopenharmony_ci              firmware and build a flattened device-tree as described
568c2ecf20Sopenharmony_ci              in b). prom_init() will then re-enter the kernel using
578c2ecf20Sopenharmony_ci              the second method. This trampoline code runs in the
588c2ecf20Sopenharmony_ci              context of the firmware, which is supposed to handle all
598c2ecf20Sopenharmony_ci              exceptions during that time.
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci        b) Direct entry with a flattened device-tree block. This entry
628c2ecf20Sopenharmony_ci        point is called by a) after the OF trampoline and can also be
638c2ecf20Sopenharmony_ci        called directly by a bootloader that does not support the Open
648c2ecf20Sopenharmony_ci        Firmware client interface. It is also used by "kexec" to
658c2ecf20Sopenharmony_ci        implement "hot" booting of a new kernel from a previous
668c2ecf20Sopenharmony_ci        running one. This method is what I will describe in more
678c2ecf20Sopenharmony_ci        details in this document, as method a) is simply standard Open
688c2ecf20Sopenharmony_ci        Firmware, and thus should be implemented according to the
698c2ecf20Sopenharmony_ci        various standard documents defining it and its binding to the
708c2ecf20Sopenharmony_ci        PowerPC platform. The entry point definition then becomes:
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci                r3 : physical pointer to the device-tree block
738c2ecf20Sopenharmony_ci                (defined in chapter II) in RAM
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci                r4 : physical pointer to the kernel itself. This is
768c2ecf20Sopenharmony_ci                used by the assembly code to properly disable the MMU
778c2ecf20Sopenharmony_ci                in case you are entering the kernel with MMU enabled
788c2ecf20Sopenharmony_ci                and a non-1:1 mapping.
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci                r5 : NULL (as to differentiate with method a)
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciNote about SMP entry: Either your firmware puts your other
838c2ecf20Sopenharmony_ciCPUs in some sleep loop or spin loop in ROM where you can get
848c2ecf20Sopenharmony_cithem out via a soft reset or some other means, in which case
858c2ecf20Sopenharmony_ciyou don't need to care, or you'll have to enter the kernel
868c2ecf20Sopenharmony_ciwith all CPUs. The way to do that with method b) will be
878c2ecf20Sopenharmony_cidescribed in a later revision of this document.
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciBoard supports (platforms) are not exclusive config options. An
908c2ecf20Sopenharmony_ciarbitrary set of board supports can be built in a single kernel
918c2ecf20Sopenharmony_ciimage. The kernel will "know" what set of functions to use for a
928c2ecf20Sopenharmony_cigiven platform based on the content of the device-tree. Thus, you
938c2ecf20Sopenharmony_cishould:
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci        a) add your platform support as a _boolean_ option in
968c2ecf20Sopenharmony_ci        arch/powerpc/Kconfig, following the example of PPC_PSERIES,
978c2ecf20Sopenharmony_ci        PPC_PMAC and PPC_MAPLE. The later is probably a good
988c2ecf20Sopenharmony_ci        example of a board support to start from.
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci        b) create your main platform file as
1018c2ecf20Sopenharmony_ci        "arch/powerpc/platforms/myplatform/myboard_setup.c" and add it
1028c2ecf20Sopenharmony_ci        to the Makefile under the condition of your ``CONFIG_``
1038c2ecf20Sopenharmony_ci        option. This file will define a structure of type "ppc_md"
1048c2ecf20Sopenharmony_ci        containing the various callbacks that the generic code will
1058c2ecf20Sopenharmony_ci        use to get to your platform specific code
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciA kernel image may support multiple platforms, but only if the
1088c2ecf20Sopenharmony_ciplatforms feature the same core architecture.  A single kernel build
1098c2ecf20Sopenharmony_cicannot support both configurations with Book E and configurations
1108c2ecf20Sopenharmony_ciwith classic Powerpc architectures.
111