new-machine.txt 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. Adding a new board to LinuxSH
  2. ================================
  3. Paul Mundt <lethal@linux-sh.org>
  4. This document attempts to outline what steps are necessary to add support
  5. for new boards to the LinuxSH port under the new 2.5 and 2.6 kernels. This
  6. also attempts to outline some of the noticeable changes between the 2.4
  7. and the 2.5/2.6 SH backend.
  8. 1. New Directory Structure
  9. ==========================
  10. The first thing to note is the new directory structure. Under 2.4, most
  11. of the board-specific code (with the exception of stboards) ended up
  12. in arch/sh/kernel/ directly, with board-specific headers ending up in
  13. include/asm-sh/. For the new kernel, things are broken out by board type,
  14. companion chip type, and CPU type. Looking at a tree view of this directory
  15. hierarchy looks like the following:
  16. Board-specific code:
  17. .
  18. |-- arch
  19. | `-- sh
  20. | `-- boards
  21. | |-- adx
  22. | | `-- board-specific files
  23. | |-- bigsur
  24. | | `-- board-specific files
  25. | |
  26. | ... more boards here ...
  27. |
  28. `-- include
  29. `-- asm-sh
  30. |-- adx
  31. | `-- board-specific headers
  32. |-- bigsur
  33. | `-- board-specific headers
  34. |
  35. .. more boards here ...
  36. Next, for companion chips:
  37. .
  38. `-- arch
  39. `-- sh
  40. `-- cchips
  41. `-- hd6446x
  42. `-- hd64461
  43. `-- cchip-specific files
  44. ... and so on. Headers for the companion chips are treated the same way as
  45. board-specific headers. Thus, include/asm-sh/hd64461 is home to all of the
  46. hd64461-specific headers.
  47. Finally, CPU family support is also abstracted:
  48. .
  49. |-- arch
  50. | `-- sh
  51. | |-- kernel
  52. | | `-- cpu
  53. | | |-- sh2
  54. | | | `-- SH-2 generic files
  55. | | |-- sh3
  56. | | | `-- SH-3 generic files
  57. | | `-- sh4
  58. | | `-- SH-4 generic files
  59. | `-- mm
  60. | `-- This is also broken out per CPU family, so each family can
  61. | have their own set of cache/tlb functions.
  62. |
  63. `-- include
  64. `-- asm-sh
  65. |-- cpu-sh2
  66. | `-- SH-2 specific headers
  67. |-- cpu-sh3
  68. | `-- SH-3 specific headers
  69. `-- cpu-sh4
  70. `-- SH-4 specific headers
  71. It should be noted that CPU subtypes are _not_ abstracted. Thus, these still
  72. need to be dealt with by the CPU family specific code.
  73. 2. Adding a New Board
  74. =====================
  75. The first thing to determine is whether the board you are adding will be
  76. isolated, or whether it will be part of a family of boards that can mostly
  77. share the same board-specific code with minor differences.
  78. In the first case, this is just a matter of making a directory for your
  79. board in arch/sh/boards/ and adding rules to hook your board in with the
  80. build system (more on this in the next section). However, for board families
  81. it makes more sense to have a common top-level arch/sh/boards/ directory
  82. and then populate that with sub-directories for each member of the family.
  83. Both the Solution Engine and the hp6xx boards are an example of this.
  84. After you have setup your new arch/sh/boards/ directory, remember that you
  85. should also add a directory in include/asm-sh for headers localized to this
  86. board (if there are going to be more than one). In order to interoperate
  87. seamlessly with the build system, it's best to have this directory the same
  88. as the arch/sh/boards/ directory name, though if your board is again part of
  89. a family, the build system has ways of dealing with this (via incdir-y
  90. overloading), and you can feel free to name the directory after the family
  91. member itself.
  92. There are a few things that each board is required to have, both in the
  93. arch/sh/boards and the include/asm-sh/ hierarchy. In order to better
  94. explain this, we use some examples for adding an imaginary board. For
  95. setup code, we're required at the very least to provide definitions for
  96. get_system_type() and platform_setup(). For our imaginary board, this
  97. might look something like:
  98. /*
  99. * arch/sh/boards/vapor/setup.c - Setup code for imaginary board
  100. */
  101. #include <linux/init.h>
  102. #include <asm/rtc.h> /* for board_time_init() */
  103. const char *get_system_type(void)
  104. {
  105. return "FooTech Vaporboard";
  106. }
  107. int __init platform_setup(void)
  108. {
  109. /*
  110. * If our hardware actually existed, we would do real
  111. * setup here. Though it's also sane to leave this empty
  112. * if there's no real init work that has to be done for
  113. * this board.
  114. */
  115. /*
  116. * Presume all FooTech boards have the same broken timer,
  117. * and also presume that we've defined foo_timer_init to
  118. * do something useful.
  119. */
  120. board_time_init = foo_timer_init;
  121. /* Start-up imaginary PCI ... */
  122. /* And whatever else ... */
  123. return 0;
  124. }
  125. Our new imaginary board will also have to tie into the machvec in order for it
  126. to be of any use.
  127. machvec functions fall into a number of categories:
  128. - I/O functions to IO memory (inb etc) and PCI/main memory (readb etc).
  129. - I/O mapping functions (ioport_map, ioport_unmap, etc).
  130. - a 'heartbeat' function.
  131. - PCI and IRQ initialization routines.
  132. - Consistent allocators (for boards that need special allocators,
  133. particularly for allocating out of some board-specific SRAM for DMA
  134. handles).
  135. There are machvec functions added and removed over time, so always be sure to
  136. consult include/asm-sh/machvec.h for the current state of the machvec.
  137. The kernel will automatically wrap in generic routines for undefined function
  138. pointers in the machvec at boot time, as machvec functions are referenced
  139. unconditionally throughout most of the tree. Some boards have incredibly
  140. sparse machvecs (such as the dreamcast and sh03), whereas others must define
  141. virtually everything (rts7751r2d).
  142. Adding a new machine is relatively trivial (using vapor as an example):
  143. If the board-specific definitions are quite minimalistic, as is the case for
  144. the vast majority of boards, simply having a single board-specific header is
  145. sufficient.
  146. - add a new file include/asm-sh/vapor.h which contains prototypes for
  147. any machine specific IO functions prefixed with the machine name, for
  148. example vapor_inb. These will be needed when filling out the machine
  149. vector.
  150. Note that these prototypes are generated automatically by setting
  151. __IO_PREFIX to something sensible. A typical example would be:
  152. #define __IO_PREFIX vapor
  153. #include <asm/io_generic.h>
  154. somewhere in the board-specific header. Any boards being ported that still
  155. have a legacy io.h should remove it entirely and switch to the new model.
  156. - Add machine vector definitions to the board's setup.c. At a bare minimum,
  157. this must be defined as something like:
  158. struct sh_machine_vector mv_vapor __initmv = {
  159. .mv_name = "vapor",
  160. };
  161. ALIAS_MV(vapor)
  162. - finally add a file arch/sh/boards/vapor/io.c, which contains definitions of
  163. the machine specific io functions (if there are enough to warrant it).
  164. 3. Hooking into the Build System
  165. ================================
  166. Now that we have the corresponding directories setup, and all of the
  167. board-specific code is in place, it's time to look at how to get the
  168. whole mess to fit into the build system.
  169. Large portions of the build system are now entirely dynamic, and merely
  170. require the proper entry here and there in order to get things done.
  171. The first thing to do is to add an entry to arch/sh/Kconfig, under the
  172. "System type" menu:
  173. config SH_VAPOR
  174. bool "Vapor"
  175. help
  176. select Vapor if configuring for a FooTech Vaporboard.
  177. next, this has to be added into arch/sh/Makefile. All boards require a
  178. machdir-y entry in order to be built. This entry needs to be the name of
  179. the board directory as it appears in arch/sh/boards, even if it is in a
  180. sub-directory (in which case, all parent directories below arch/sh/boards/
  181. need to be listed). For our new board, this entry can look like:
  182. machdir-$(CONFIG_SH_VAPOR) += vapor
  183. provided that we've placed everything in the arch/sh/boards/vapor/ directory.
  184. Next, the build system assumes that your include/asm-sh directory will also
  185. be named the same. If this is not the case (as is the case with multiple
  186. boards belonging to a common family), then the directory name needs to be
  187. implicitly appended to incdir-y. The existing code manages this for the
  188. Solution Engine and hp6xx boards, so see these for an example.
  189. Once that is taken care of, it's time to add an entry for the mach type.
  190. This is done by adding an entry to the end of the arch/sh/tools/mach-types
  191. list. The method for doing this is self explanatory, and so we won't waste
  192. space restating it here. After this is done, you will be able to use
  193. implicit checks for your board if you need this somewhere throughout the
  194. common code, such as:
  195. /* Make sure we're on the FooTech Vaporboard */
  196. if (!mach_is_vapor())
  197. return -ENODEV;
  198. also note that the mach_is_boardname() check will be implicitly forced to
  199. lowercase, regardless of the fact that the mach-types entries are all
  200. uppercase. You can read the script if you really care, but it's pretty ugly,
  201. so you probably don't want to do that.
  202. Now all that's left to do is providing a defconfig for your new board. This
  203. way, other people who end up with this board can simply use this config
  204. for reference instead of trying to guess what settings are supposed to be
  205. used on it.
  206. Also, as soon as you have copied over a sample .config for your new board
  207. (assume arch/sh/configs/vapor_defconfig), you can also use this directly as a
  208. build target, and it will be implicitly listed as such in the help text.
  209. Looking at the 'make help' output, you should now see something like:
  210. Architecture specific targets (sh):
  211. zImage - Compressed kernel image (arch/sh/boot/zImage)
  212. adx_defconfig - Build for adx
  213. cqreek_defconfig - Build for cqreek
  214. dreamcast_defconfig - Build for dreamcast
  215. ...
  216. vapor_defconfig - Build for vapor
  217. which then allows you to do:
  218. $ make ARCH=sh CROSS_COMPILE=sh4-linux- vapor_defconfig vmlinux
  219. which will in turn copy the defconfig for this board, run it through
  220. oldconfig (prompting you for any new options since the time of creation),
  221. and start you on your way to having a functional kernel for your new
  222. board.