diff options
Diffstat (limited to 'Documentation/sh')
-rw-r--r-- | Documentation/sh/kgdb.txt | 179 | ||||
-rw-r--r-- | Documentation/sh/new-machine.txt | 306 |
2 files changed, 485 insertions, 0 deletions
diff --git a/Documentation/sh/kgdb.txt b/Documentation/sh/kgdb.txt new file mode 100644 index 000000000000..5b04f7f306fc --- /dev/null +++ b/Documentation/sh/kgdb.txt | |||
@@ -0,0 +1,179 @@ | |||
1 | |||
2 | This file describes the configuration and behavior of KGDB for the SH | ||
3 | kernel. Based on a description from Henry Bell <henry.bell@st.com>, it | ||
4 | has been modified to account for quirks in the current implementation. | ||
5 | |||
6 | Version | ||
7 | ======= | ||
8 | |||
9 | This version of KGDB was written for 2.4.xx kernels for the SH architecture. | ||
10 | Further documentation is available from the linux-sh project website. | ||
11 | |||
12 | |||
13 | Debugging Setup: Host | ||
14 | ====================== | ||
15 | |||
16 | The two machines will be connected together via a serial line - this | ||
17 | should be a null modem cable i.e. with a twist. | ||
18 | |||
19 | On your DEVELOPMENT machine, go to your kernel source directory and | ||
20 | build the kernel, enabling KGDB support in the "kernel hacking" section. | ||
21 | This includes the KGDB code, and also makes the kernel be compiled with | ||
22 | the "-g" option set -- necessary for debugging. | ||
23 | |||
24 | To install this new kernel, use the following installation procedure. | ||
25 | |||
26 | Decide on which tty port you want the machines to communicate, then | ||
27 | cable them up back-to-back using the null modem. On the DEVELOPMENT | ||
28 | machine, you may wish to create an initialization file called .gdbinit | ||
29 | (in the kernel source directory or in your home directory) to execute | ||
30 | commonly-used commands at startup. | ||
31 | |||
32 | A minimal .gdbinit might look like this: | ||
33 | |||
34 | file vmlinux | ||
35 | set remotebaud 115200 | ||
36 | target remote /dev/ttyS0 | ||
37 | |||
38 | Change the "target" definition so that it specifies the tty port that | ||
39 | you intend to use. Change the "remotebaud" definition to match the | ||
40 | data rate that you are going to use for the com line (115200 is the | ||
41 | default). | ||
42 | |||
43 | Debugging Setup: Target | ||
44 | ======================== | ||
45 | |||
46 | By default, the KGDB stub will communicate with the host GDB using | ||
47 | ttySC1 at 115200 baud, 8 databits, no parity; these defaults can be | ||
48 | changed in the kernel configuration. As the kernel starts up, KGDB will | ||
49 | initialize so that breakpoints, kernel segfaults, and so forth will | ||
50 | generally enter the debugger. | ||
51 | |||
52 | This behavior can be modified by including the "kgdb" option in the | ||
53 | kernel command line; this option has the general form: | ||
54 | |||
55 | kgdb=<ttyspec>,<action> | ||
56 | |||
57 | The <ttyspec> indicates the port to use, and can optionally specify | ||
58 | baud, parity and databits -- e.g. "ttySC0,9600N8" or "ttySC1,19200". | ||
59 | |||
60 | The <action> can be "halt" or "disabled". The "halt" action enters the | ||
61 | debugger via a breakpoint as soon as kgdb is initialized; the "disabled" | ||
62 | action causes kgdb to ignore kernel segfaults and such until explicitly | ||
63 | entered by a breakpoint in the code or by external action (sysrq or NMI). | ||
64 | |||
65 | (Both <ttyspec> and <action> can appear alone, w/o the separating comma.) | ||
66 | |||
67 | For example, if you wish to debug early in kernel startup code, you | ||
68 | might specify the halt option: | ||
69 | |||
70 | kgdb=halt | ||
71 | |||
72 | Boot the TARGET machinem, which will appear to hang. | ||
73 | |||
74 | On your DEVELOPMENT machine, cd to the source directory and run the gdb | ||
75 | program. (This is likely to be a cross GDB which runs on your host but | ||
76 | is built for an SH target.) If everything is working correctly you | ||
77 | should see gdb print out a few lines indicating that a breakpoint has | ||
78 | been taken. It will actually show a line of code in the target kernel | ||
79 | inside the gdbstub activation code. | ||
80 | |||
81 | NOTE: BE SURE TO TERMINATE OR SUSPEND any other host application which | ||
82 | may be using the same serial port (for example, a terminal emulator you | ||
83 | have been using to connect to the target boot code.) Otherwise, data | ||
84 | from the target may not all get to GDB! | ||
85 | |||
86 | You can now use whatever gdb commands you like to set breakpoints. | ||
87 | Enter "continue" to start your target machine executing again. At this | ||
88 | point the target system will run at full speed until it encounters | ||
89 | your breakpoint or gets a segment violation in the kernel, or whatever. | ||
90 | |||
91 | Serial Ports: KGDB, Console | ||
92 | ============================ | ||
93 | |||
94 | This version of KGDB may not gracefully handle conflict with other | ||
95 | drivers in the kernel using the same port. If KGDB is configured on the | ||
96 | same port (and with the same parameters) as the kernel console, or if | ||
97 | CONFIG_SH_KGDB_CONSOLE is configured, things should be fine (though in | ||
98 | some cases console messages may appear twice through GDB). But if the | ||
99 | KGDB port is not the kernel console and used by another serial driver | ||
100 | which assumes different serial parameters (e.g. baud rate) KGDB may not | ||
101 | recover. | ||
102 | |||
103 | Also, when KGDB is entered via sysrq-g (requires CONFIG_KGDB_SYSRQ) and | ||
104 | the kgdb port uses the same port as the console, detaching GDB will not | ||
105 | restore the console to working order without the port being re-opened. | ||
106 | |||
107 | Another serious consequence of this is that GDB currently CANNOT break | ||
108 | into KGDB externally (e.g. via ^C or <BREAK>); unless a breakpoint or | ||
109 | error is encountered, the only way to enter KGDB after the initial halt | ||
110 | (see above) is via NMI (CONFIG_KGDB_NMI) or sysrq-g (CONFIG_KGDB_SYSRQ). | ||
111 | |||
112 | Code is included for the basic Hitachi Solution Engine boards to allow | ||
113 | the use of ttyS0 for KGDB if desired; this is less robust, but may be | ||
114 | useful in some cases. (This cannot be selected using the config file, | ||
115 | but only through the kernel command line, e.g. "kgdb=ttyS0", though the | ||
116 | configured defaults for baud rate etc. still apply if not overridden.) | ||
117 | |||
118 | If gdbstub Does Not Work | ||
119 | ======================== | ||
120 | |||
121 | If it doesn't work, you will have to troubleshoot it. Do the easy | ||
122 | things first like double checking your cabling and data rates. You | ||
123 | might try some non-kernel based programs to see if the back-to-back | ||
124 | connection works properly. Just something simple like cat /etc/hosts | ||
125 | /dev/ttyS0 on one machine and cat /dev/ttyS0 on the other will tell you | ||
126 | if you can send data from one machine to the other. There is no point | ||
127 | in tearing out your hair in the kernel if the line doesn't work. | ||
128 | |||
129 | If you need to debug the GDB/KGDB communication itself, the gdb commands | ||
130 | "set debug remote 1" and "set debug serial 1" may be useful, but be | ||
131 | warned: they produce a lot of output. | ||
132 | |||
133 | Threads | ||
134 | ======= | ||
135 | |||
136 | Each process in a target machine is seen as a gdb thread. gdb thread related | ||
137 | commands (info threads, thread n) can be used. CONFIG_KGDB_THREAD must | ||
138 | be defined for this to work. | ||
139 | |||
140 | In this version, kgdb reports PID_MAX (32768) as the process ID for the | ||
141 | idle process (pid 0), since GDB does not accept 0 as an ID. | ||
142 | |||
143 | Detaching (exiting KGDB) | ||
144 | ========================= | ||
145 | |||
146 | There are two ways to resume full-speed target execution: "continue" and | ||
147 | "detach". With "continue", GDB inserts any specified breakpoints in the | ||
148 | target code and resumes execution; the target is still in "gdb mode". | ||
149 | If a breakpoint or other debug event (e.g. NMI) happens, the target | ||
150 | halts and communicates with GDB again, which is waiting for it. | ||
151 | |||
152 | With "detach", GDB does *not* insert any breakpoints; target execution | ||
153 | is resumed and GDB stops communicating (does not wait for the target). | ||
154 | In this case, the target is no longer in "gdb mode" -- for example, | ||
155 | console messages no longer get sent separately to the KGDB port, or | ||
156 | encapsulated for GDB. If a debug event (e.g. NMI) occurs, the target | ||
157 | will re-enter "gdb mode" and will display this fact on the console; you | ||
158 | must give a new "target remote" command to gdb. | ||
159 | |||
160 | NOTE: TO AVOID LOSSING CONSOLE MESSAGES IN CASE THE KERNEL CONSOLE AND | ||
161 | KGDB USING THE SAME PORT, THE TARGET WAITS FOR ANY INPUT CHARACTER ON | ||
162 | THE KGDB PORT AFTER A DETACH COMMAND. For example, after the detach you | ||
163 | could start a terminal emulator on the same host port and enter a <cr>; | ||
164 | however, this program must then be terminated or suspended in order to | ||
165 | use GBD again if KGDB is re-entered. | ||
166 | |||
167 | |||
168 | Acknowledgements | ||
169 | ================ | ||
170 | |||
171 | This code was mostly generated by Henry Bell <henry.bell@st.com>; | ||
172 | largely from KGDB by Amit S. Kale <akale@veritas.com> - extracts from | ||
173 | code by Glenn Engel, Jim Kingdon, David Grothe <dave@gcom.com>, Tigran | ||
174 | Aivazian <tigran@sco.com>, William Gatliff <bgat@open-widgets.com>, Ben | ||
175 | Lee, Steve Chamberlain and Benoit Miller <fulg@iname.com> are also | ||
176 | included. | ||
177 | |||
178 | Jeremy Siegel | ||
179 | <jsiegel@mvista.com> | ||
diff --git a/Documentation/sh/new-machine.txt b/Documentation/sh/new-machine.txt new file mode 100644 index 000000000000..eb2dd2e6993b --- /dev/null +++ b/Documentation/sh/new-machine.txt | |||
@@ -0,0 +1,306 @@ | |||
1 | |||
2 | Adding a new board to LinuxSH | ||
3 | ================================ | ||
4 | |||
5 | Paul Mundt <lethal@linux-sh.org> | ||
6 | |||
7 | This document attempts to outline what steps are necessary to add support | ||
8 | for new boards to the LinuxSH port under the new 2.5 and 2.6 kernels. This | ||
9 | also attempts to outline some of the noticeable changes between the 2.4 | ||
10 | and the 2.5/2.6 SH backend. | ||
11 | |||
12 | 1. New Directory Structure | ||
13 | ========================== | ||
14 | |||
15 | The first thing to note is the new directory structure. Under 2.4, most | ||
16 | of the board-specific code (with the exception of stboards) ended up | ||
17 | in arch/sh/kernel/ directly, with board-specific headers ending up in | ||
18 | include/asm-sh/. For the new kernel, things are broken out by board type, | ||
19 | companion chip type, and CPU type. Looking at a tree view of this directory | ||
20 | heirarchy looks like the following: | ||
21 | |||
22 | Board-specific code: | ||
23 | |||
24 | . | ||
25 | |-- arch | ||
26 | | `-- sh | ||
27 | | `-- boards | ||
28 | | |-- adx | ||
29 | | | `-- board-specific files | ||
30 | | |-- bigsur | ||
31 | | | `-- board-specific files | ||
32 | | | | ||
33 | | ... more boards here ... | ||
34 | | | ||
35 | `-- include | ||
36 | `-- asm-sh | ||
37 | |-- adx | ||
38 | | `-- board-specific headers | ||
39 | |-- bigsur | ||
40 | | `-- board-specific headers | ||
41 | | | ||
42 | .. more boards here ... | ||
43 | |||
44 | It should also be noted that each board is required to have some certain | ||
45 | headers. At the time of this writing, io.h is the only thing that needs | ||
46 | to be provided for each board, and can generally just reference generic | ||
47 | functions (with the exception of isa_port2addr). | ||
48 | |||
49 | Next, for companion chips: | ||
50 | . | ||
51 | `-- arch | ||
52 | `-- sh | ||
53 | `-- cchips | ||
54 | `-- hd6446x | ||
55 | |-- hd64461 | ||
56 | | `-- cchip-specific files | ||
57 | `-- hd64465 | ||
58 | `-- cchip-specific files | ||
59 | |||
60 | ... and so on. Headers for the companion chips are treated the same way as | ||
61 | board-specific headers. Thus, include/asm-sh/hd64461 is home to all of the | ||
62 | hd64461-specific headers. | ||
63 | |||
64 | Finally, CPU family support is also abstracted: | ||
65 | . | ||
66 | |-- arch | ||
67 | | `-- sh | ||
68 | | |-- kernel | ||
69 | | | `-- cpu | ||
70 | | | |-- sh2 | ||
71 | | | | `-- SH-2 generic files | ||
72 | | | |-- sh3 | ||
73 | | | | `-- SH-3 generic files | ||
74 | | | `-- sh4 | ||
75 | | | `-- SH-4 generic files | ||
76 | | `-- mm | ||
77 | | `-- This is also broken out per CPU family, so each family can | ||
78 | | have their own set of cache/tlb functions. | ||
79 | | | ||
80 | `-- include | ||
81 | `-- asm-sh | ||
82 | |-- cpu-sh2 | ||
83 | | `-- SH-2 specific headers | ||
84 | |-- cpu-sh3 | ||
85 | | `-- SH-3 specific headers | ||
86 | `-- cpu-sh4 | ||
87 | `-- SH-4 specific headers | ||
88 | |||
89 | It should be noted that CPU subtypes are _not_ abstracted. Thus, these still | ||
90 | need to be dealt with by the CPU family specific code. | ||
91 | |||
92 | 2. Adding a New Board | ||
93 | ===================== | ||
94 | |||
95 | The first thing to determine is whether the board you are adding will be | ||
96 | isolated, or whether it will be part of a family of boards that can mostly | ||
97 | share the same board-specific code with minor differences. | ||
98 | |||
99 | In the first case, this is just a matter of making a directory for your | ||
100 | board in arch/sh/boards/ and adding rules to hook your board in with the | ||
101 | build system (more on this in the next section). However, for board families | ||
102 | it makes more sense to have a common top-level arch/sh/boards/ directory | ||
103 | and then populate that with sub-directories for each member of the family. | ||
104 | Both the Solution Engine and the hp6xx boards are an example of this. | ||
105 | |||
106 | After you have setup your new arch/sh/boards/ directory, remember that you | ||
107 | also must add a directory in include/asm-sh for headers localized to this | ||
108 | board. In order to interoperate seamlessly with the build system, it's best | ||
109 | to have this directory the same as the arch/sh/boards/ directory name, | ||
110 | though if your board is again part of a family, the build system has ways | ||
111 | of dealing with this, and you can feel free to name the directory after | ||
112 | the family member itself. | ||
113 | |||
114 | There are a few things that each board is required to have, both in the | ||
115 | arch/sh/boards and the include/asm-sh/ heirarchy. In order to better | ||
116 | explain this, we use some examples for adding an imaginary board. For | ||
117 | setup code, we're required at the very least to provide definitions for | ||
118 | get_system_type() and platform_setup(). For our imaginary board, this | ||
119 | might look something like: | ||
120 | |||
121 | /* | ||
122 | * arch/sh/boards/vapor/setup.c - Setup code for imaginary board | ||
123 | */ | ||
124 | #include <linux/init.h> | ||
125 | |||
126 | const char *get_system_type(void) | ||
127 | { | ||
128 | return "FooTech Vaporboard"; | ||
129 | } | ||
130 | |||
131 | int __init platform_setup(void) | ||
132 | { | ||
133 | /* | ||
134 | * If our hardware actually existed, we would do real | ||
135 | * setup here. Though it's also sane to leave this empty | ||
136 | * if there's no real init work that has to be done for | ||
137 | * this board. | ||
138 | */ | ||
139 | |||
140 | /* | ||
141 | * Presume all FooTech boards have the same broken timer, | ||
142 | * and also presume that we've defined foo_timer_init to | ||
143 | * do something useful. | ||
144 | */ | ||
145 | board_time_init = foo_timer_init; | ||
146 | |||
147 | /* Start-up imaginary PCI ... */ | ||
148 | |||
149 | /* And whatever else ... */ | ||
150 | |||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | Our new imaginary board will also have to tie into the machvec in order for it | ||
155 | to be of any use. Currently the machvec is slowly on its way out, but is still | ||
156 | required for the time being. As such, let us take a look at what needs to be | ||
157 | done for the machvec assignment. | ||
158 | |||
159 | machvec functions fall into a number of categories: | ||
160 | |||
161 | - I/O functions to IO memory (inb etc) and PCI/main memory (readb etc). | ||
162 | - I/O remapping functions (ioremap etc) | ||
163 | - some initialisation functions | ||
164 | - a 'heartbeat' function | ||
165 | - some miscellaneous flags | ||
166 | |||
167 | The tree can be built in two ways: | ||
168 | - as a fully generic build. All drivers are linked in, and all functions | ||
169 | go through the machvec | ||
170 | - as a machine specific build. In this case only the required drivers | ||
171 | will be linked in, and some macros may be redefined to not go through | ||
172 | the machvec where performance is important (in particular IO functions). | ||
173 | |||
174 | There are three ways in which IO can be performed: | ||
175 | - none at all. This is really only useful for the 'unknown' machine type, | ||
176 | which us designed to run on a machine about which we know nothing, and | ||
177 | so all all IO instructions do nothing. | ||
178 | - fully custom. In this case all IO functions go to a machine specific | ||
179 | set of functions which can do what they like | ||
180 | - a generic set of functions. These will cope with most situations, | ||
181 | and rely on a single function, mv_port2addr, which is called through the | ||
182 | machine vector, and converts an IO address into a memory address, which | ||
183 | can be read from/written to directly. | ||
184 | |||
185 | Thus adding a new machine involves the following steps (I will assume I am | ||
186 | adding a machine called vapor): | ||
187 | |||
188 | - add a new file include/asm-sh/vapor/io.h which contains prototypes for | ||
189 | any machine specific IO functions prefixed with the machine name, for | ||
190 | example vapor_inb. These will be needed when filling out the machine | ||
191 | vector. | ||
192 | |||
193 | This is the minimum that is required, however there are ample | ||
194 | opportunities to optimise this. In particular, by making the prototypes | ||
195 | inline function definitions, it is possible to inline the function when | ||
196 | building machine specific versions. Note that the machine vector | ||
197 | functions will still be needed, so that a module built for a generic | ||
198 | setup can be loaded. | ||
199 | |||
200 | - add a new file arch/sh/boards/vapor/mach.c. This contains the definition | ||
201 | of the machine vector. When building the machine specific version, this | ||
202 | will be the real machine vector (via an alias), while in the generic | ||
203 | version is used to initialise the machine vector, and then freed, by | ||
204 | making it initdata. This should be defined as: | ||
205 | |||
206 | struct sh_machine_vector mv_vapor __initmv = { | ||
207 | .mv_name = "vapor", | ||
208 | } | ||
209 | ALIAS_MV(vapor) | ||
210 | |||
211 | - finally add a file arch/sh/boards/vapor/io.c, which contains | ||
212 | definitions of the machine specific io functions. | ||
213 | |||
214 | A note about initialisation functions. Three initialisation functions are | ||
215 | provided in the machine vector: | ||
216 | - mv_arch_init - called very early on from setup_arch | ||
217 | - mv_init_irq - called from init_IRQ, after the generic SH interrupt | ||
218 | initialisation | ||
219 | - mv_init_pci - currently not used | ||
220 | |||
221 | Any other remaining functions which need to be called at start up can be | ||
222 | added to the list using the __initcalls macro (or module_init if the code | ||
223 | can be built as a module). Many generic drivers probe to see if the device | ||
224 | they are targeting is present, however this may not always be appropriate, | ||
225 | so a flag can be added to the machine vector which will be set on those | ||
226 | machines which have the hardware in question, reducing the probe to a | ||
227 | single conditional. | ||
228 | |||
229 | 3. Hooking into the Build System | ||
230 | ================================ | ||
231 | |||
232 | Now that we have the corresponding directories setup, and all of the | ||
233 | board-specific code is in place, it's time to look at how to get the | ||
234 | whole mess to fit into the build system. | ||
235 | |||
236 | Large portions of the build system are now entirely dynamic, and merely | ||
237 | require the proper entry here and there in order to get things done. | ||
238 | |||
239 | The first thing to do is to add an entry to arch/sh/Kconfig, under the | ||
240 | "System type" menu: | ||
241 | |||
242 | config SH_VAPOR | ||
243 | bool "Vapor" | ||
244 | help | ||
245 | select Vapor if configuring for a FooTech Vaporboard. | ||
246 | |||
247 | next, this has to be added into arch/sh/Makefile. All boards require a | ||
248 | machdir-y entry in order to be built. This entry needs to be the name of | ||
249 | the board directory as it appears in arch/sh/boards, even if it is in a | ||
250 | sub-directory (in which case, all parent directories below arch/sh/boards/ | ||
251 | need to be listed). For our new board, this entry can look like: | ||
252 | |||
253 | machdir-$(CONFIG_SH_VAPOR) += vapor | ||
254 | |||
255 | provided that we've placed everything in the arch/sh/boards/vapor/ directory. | ||
256 | |||
257 | Next, the build system assumes that your include/asm-sh directory will also | ||
258 | be named the same. If this is not the case (as is the case with multiple | ||
259 | boards belonging to a common family), then the directory name needs to be | ||
260 | implicitly appended to incdir-y. The existing code manages this for the | ||
261 | Solution Engine and hp6xx boards, so see these for an example. | ||
262 | |||
263 | Once that is taken care of, it's time to add an entry for the mach type. | ||
264 | This is done by adding an entry to the end of the arch/sh/tools/mach-types | ||
265 | list. The method for doing this is self explanatory, and so we won't waste | ||
266 | space restating it here. After this is done, you will be able to use | ||
267 | implicit checks for your board if you need this somewhere throughout the | ||
268 | common code, such as: | ||
269 | |||
270 | /* Make sure we're on the FooTech Vaporboard */ | ||
271 | if (!mach_is_vapor()) | ||
272 | return -ENODEV; | ||
273 | |||
274 | also note that the mach_is_boardname() check will be implicitly forced to | ||
275 | lowercase, regardless of the fact that the mach-types entries are all | ||
276 | uppercase. You can read the script if you really care, but it's pretty ugly, | ||
277 | so you probably don't want to do that. | ||
278 | |||
279 | Now all that's left to do is providing a defconfig for your new board. This | ||
280 | way, other people who end up with this board can simply use this config | ||
281 | for reference instead of trying to guess what settings are supposed to be | ||
282 | used on it. | ||
283 | |||
284 | Also, as soon as you have copied over a sample .config for your new board | ||
285 | (assume arch/sh/configs/vapor_defconfig), you can also use this directly as a | ||
286 | build target, and it will be implicitly listed as such in the help text. | ||
287 | |||
288 | Looking at the 'make help' output, you should now see something like: | ||
289 | |||
290 | Architecture specific targets (sh): | ||
291 | zImage - Compressed kernel image (arch/sh/boot/zImage) | ||
292 | adx_defconfig - Build for adx | ||
293 | cqreek_defconfig - Build for cqreek | ||
294 | dreamcast_defconfig - Build for dreamcast | ||
295 | ... | ||
296 | vapor_defconfig - Build for vapor | ||
297 | |||
298 | which then allows you to do: | ||
299 | |||
300 | $ make ARCH=sh CROSS_COMPILE=sh4-linux- vapor_defconfig vmlinux | ||
301 | |||
302 | which will in turn copy the defconfig for this board, run it through | ||
303 | oldconfig (prompting you for any new options since the time of creation), | ||
304 | and start you on your way to having a functional kernel for your new | ||
305 | board. | ||
306 | |||