new-machine.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. heirarchy 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. It should also be noted that each board is required to have some certain
  37. headers. At the time of this writing, io.h is the only thing that needs
  38. to be provided for each board, and can generally just reference generic
  39. functions (with the exception of isa_port2addr).
  40. Next, for companion chips:
  41. .
  42. `-- arch
  43. `-- sh
  44. `-- cchips
  45. `-- hd6446x
  46. |-- hd64461
  47. | `-- cchip-specific files
  48. `-- hd64465
  49. `-- cchip-specific files
  50. ... and so on. Headers for the companion chips are treated the same way as
  51. board-specific headers. Thus, include/asm-sh/hd64461 is home to all of the
  52. hd64461-specific headers.
  53. Finally, CPU family support is also abstracted:
  54. .
  55. |-- arch
  56. | `-- sh
  57. | |-- kernel
  58. | | `-- cpu
  59. | | |-- sh2
  60. | | | `-- SH-2 generic files
  61. | | |-- sh3
  62. | | | `-- SH-3 generic files
  63. | | `-- sh4
  64. | | `-- SH-4 generic files
  65. | `-- mm
  66. | `-- This is also broken out per CPU family, so each family can
  67. | have their own set of cache/tlb functions.
  68. |
  69. `-- include
  70. `-- asm-sh
  71. |-- cpu-sh2
  72. | `-- SH-2 specific headers
  73. |-- cpu-sh3
  74. | `-- SH-3 specific headers
  75. `-- cpu-sh4
  76. `-- SH-4 specific headers
  77. It should be noted that CPU subtypes are _not_ abstracted. Thus, these still
  78. need to be dealt with by the CPU family specific code.
  79. 2. Adding a New Board
  80. =====================
  81. The first thing to determine is whether the board you are adding will be
  82. isolated, or whether it will be part of a family of boards that can mostly
  83. share the same board-specific code with minor differences.
  84. In the first case, this is just a matter of making a directory for your
  85. board in arch/sh/boards/ and adding rules to hook your board in with the
  86. build system (more on this in the next section). However, for board families
  87. it makes more sense to have a common top-level arch/sh/boards/ directory
  88. and then populate that with sub-directories for each member of the family.
  89. Both the Solution Engine and the hp6xx boards are an example of this.
  90. After you have setup your new arch/sh/boards/ directory, remember that you
  91. also must add a directory in include/asm-sh for headers localized to this
  92. board. In order to interoperate seamlessly with the build system, it's best
  93. to have this directory the same as the arch/sh/boards/ directory name,
  94. though if your board is again part of a family, the build system has ways
  95. of dealing with this, and you can feel free to name the directory after
  96. the family member itself.
  97. There are a few things that each board is required to have, both in the
  98. arch/sh/boards and the include/asm-sh/ heirarchy. In order to better
  99. explain this, we use some examples for adding an imaginary board. For
  100. setup code, we're required at the very least to provide definitions for
  101. get_system_type() and platform_setup(). For our imaginary board, this
  102. might look something like:
  103. /*
  104. * arch/sh/boards/vapor/setup.c - Setup code for imaginary board
  105. */
  106. #include <linux/init.h>
  107. const char *get_system_type(void)
  108. {
  109. return "FooTech Vaporboard";
  110. }
  111. int __init platform_setup(void)
  112. {
  113. /*
  114. * If our hardware actually existed, we would do real
  115. * setup here. Though it's also sane to leave this empty
  116. * if there's no real init work that has to be done for
  117. * this board.
  118. */
  119. /*
  120. * Presume all FooTech boards have the same broken timer,
  121. * and also presume that we've defined foo_timer_init to
  122. * do something useful.
  123. */
  124. board_time_init = foo_timer_init;
  125. /* Start-up imaginary PCI ... */
  126. /* And whatever else ... */
  127. return 0;
  128. }
  129. Our new imaginary board will also have to tie into the machvec in order for it
  130. to be of any use. Currently the machvec is slowly on its way out, but is still
  131. required for the time being. As such, let us take a look at what needs to be
  132. done for the machvec assignment.
  133. machvec functions fall into a number of categories:
  134. - I/O functions to IO memory (inb etc) and PCI/main memory (readb etc).
  135. - I/O remapping functions (ioremap etc)
  136. - some initialisation functions
  137. - a 'heartbeat' function
  138. - some miscellaneous flags
  139. The tree can be built in two ways:
  140. - as a fully generic build. All drivers are linked in, and all functions
  141. go through the machvec
  142. - as a machine specific build. In this case only the required drivers
  143. will be linked in, and some macros may be redefined to not go through
  144. the machvec where performance is important (in particular IO functions).
  145. There are three ways in which IO can be performed:
  146. - none at all. This is really only useful for the 'unknown' machine type,
  147. which us designed to run on a machine about which we know nothing, and
  148. so all all IO instructions do nothing.
  149. - fully custom. In this case all IO functions go to a machine specific
  150. set of functions which can do what they like
  151. - a generic set of functions. These will cope with most situations,
  152. and rely on a single function, mv_port2addr, which is called through the
  153. machine vector, and converts an IO address into a memory address, which
  154. can be read from/written to directly.
  155. Thus adding a new machine involves the following steps (I will assume I am
  156. adding a machine called vapor):
  157. - add a new file include/asm-sh/vapor/io.h which contains prototypes for
  158. any machine specific IO functions prefixed with the machine name, for
  159. example vapor_inb. These will be needed when filling out the machine
  160. vector.
  161. This is the minimum that is required, however there are ample
  162. opportunities to optimise this. In particular, by making the prototypes
  163. inline function definitions, it is possible to inline the function when
  164. building machine specific versions. Note that the machine vector
  165. functions will still be needed, so that a module built for a generic
  166. setup can be loaded.
  167. - add a new file arch/sh/boards/vapor/mach.c. This contains the definition
  168. of the machine vector. When building the machine specific version, this
  169. will be the real machine vector (via an alias), while in the generic
  170. version is used to initialise the machine vector, and then freed, by
  171. making it initdata. This should be defined as:
  172. struct sh_machine_vector mv_vapor __initmv = {
  173. .mv_name = "vapor",
  174. }
  175. ALIAS_MV(vapor)
  176. - finally add a file arch/sh/boards/vapor/io.c, which contains
  177. definitions of the machine specific io functions.
  178. A note about initialisation functions. Three initialisation functions are
  179. provided in the machine vector:
  180. - mv_arch_init - called very early on from setup_arch
  181. - mv_init_irq - called from init_IRQ, after the generic SH interrupt
  182. initialisation
  183. - mv_init_pci - currently not used
  184. Any other remaining functions which need to be called at start up can be
  185. added to the list using the __initcalls macro (or module_init if the code
  186. can be built as a module). Many generic drivers probe to see if the device
  187. they are targeting is present, however this may not always be appropriate,
  188. so a flag can be added to the machine vector which will be set on those
  189. machines which have the hardware in question, reducing the probe to a
  190. single conditional.
  191. 3. Hooking into the Build System
  192. ================================
  193. Now that we have the corresponding directories setup, and all of the
  194. board-specific code is in place, it's time to look at how to get the
  195. whole mess to fit into the build system.
  196. Large portions of the build system are now entirely dynamic, and merely
  197. require the proper entry here and there in order to get things done.
  198. The first thing to do is to add an entry to arch/sh/Kconfig, under the
  199. "System type" menu:
  200. config SH_VAPOR
  201. bool "Vapor"
  202. help
  203. select Vapor if configuring for a FooTech Vaporboard.
  204. next, this has to be added into arch/sh/Makefile. All boards require a
  205. machdir-y entry in order to be built. This entry needs to be the name of
  206. the board directory as it appears in arch/sh/boards, even if it is in a
  207. sub-directory (in which case, all parent directories below arch/sh/boards/
  208. need to be listed). For our new board, this entry can look like:
  209. machdir-$(CONFIG_SH_VAPOR) += vapor
  210. provided that we've placed everything in the arch/sh/boards/vapor/ directory.
  211. Next, the build system assumes that your include/asm-sh directory will also
  212. be named the same. If this is not the case (as is the case with multiple
  213. boards belonging to a common family), then the directory name needs to be
  214. implicitly appended to incdir-y. The existing code manages this for the
  215. Solution Engine and hp6xx boards, so see these for an example.
  216. Once that is taken care of, it's time to add an entry for the mach type.
  217. This is done by adding an entry to the end of the arch/sh/tools/mach-types
  218. list. The method for doing this is self explanatory, and so we won't waste
  219. space restating it here. After this is done, you will be able to use
  220. implicit checks for your board if you need this somewhere throughout the
  221. common code, such as:
  222. /* Make sure we're on the FooTech Vaporboard */
  223. if (!mach_is_vapor())
  224. return -ENODEV;
  225. also note that the mach_is_boardname() check will be implicitly forced to
  226. lowercase, regardless of the fact that the mach-types entries are all
  227. uppercase. You can read the script if you really care, but it's pretty ugly,
  228. so you probably don't want to do that.
  229. Now all that's left to do is providing a defconfig for your new board. This
  230. way, other people who end up with this board can simply use this config
  231. for reference instead of trying to guess what settings are supposed to be
  232. used on it.
  233. Also, as soon as you have copied over a sample .config for your new board
  234. (assume arch/sh/configs/vapor_defconfig), you can also use this directly as a
  235. build target, and it will be implicitly listed as such in the help text.
  236. Looking at the 'make help' output, you should now see something like:
  237. Architecture specific targets (sh):
  238. zImage - Compressed kernel image (arch/sh/boot/zImage)
  239. adx_defconfig - Build for adx
  240. cqreek_defconfig - Build for cqreek
  241. dreamcast_defconfig - Build for dreamcast
  242. ...
  243. vapor_defconfig - Build for vapor
  244. which then allows you to do:
  245. $ make ARCH=sh CROSS_COMPILE=sh4-linux- vapor_defconfig vmlinux
  246. which will in turn copy the defconfig for this board, run it through
  247. oldconfig (prompting you for any new options since the time of creation),
  248. and start you on your way to having a functional kernel for your new
  249. board.