Copyright (c) Hyperion Entertainment and contributors.
Difference between revisions of "Advanced Serial Debugging Guide"
Steven Solie (talk | contribs) |
Roman Kargin (talk | contribs) |
||
(86 intermediate revisions by 4 users not shown) | |||
Line 7: | Line 7: | ||
= Introduction = |
= Introduction = |
||
− | While |
+ | While AmigaOS has "hi-level" capabilities to help debug problems (e.g. redirecting debug outputs to memory and displaying the log with DumpDebugBuffer or using serial redirection tools like Sashimi) it is sometimes still not enough. For example, there is no protection for areas like input and Intuition so we can get into a situation where the GUI is not operational but the OS is still working. Intuition, input and any other necessary components can crash and then the GrimReaper utility has no way to spawn itself. Meanwhile, the kernel, still can output debug information about the crash on serial. |
− | To begin with, you should know that |
+ | To begin with, you should know that AmigaOS has 2 ''reapers''. One is a user friendly utility from SYS:System called GrimReaper. The GrimReaper can be called a "hi-level" one. Another ''reaper'' is called Reaper which is a part of the kernel itself. The kernel's Reaper actually launches the user-friendly GrimReaper when a required. So, you can imagine that when things get nasty, the kernel's reaper not all the time can spawn a GrimReaper, but still can catch some information and output it to the serial. Visually, when such a nasty things happens and input and/or intuition die, you just see a "freeze" of the OS and may think that everything is freezes, while it not: you just can't operate with OS anymore as necessary parts of OS crashes, but OS itself still working and kernel's reaper already throw all the info into the serial. |
− | That |
+ | That means that when you want to do some serious work and you need any way to catch your bugs and/or debug any of your problematic code, then serial debugging is the best and only one way. Of course it's still possible to hope that the system friendly GrimReaper will popup for you and that there will be nothing so hardcore which it will crash Intuition and "freeze" the OS but that's just not enough when it come to doing real work. |
− | You may ask now why |
+ | You may ask now why the serial port is used at all? Why not parallel or something else? Why does everyone keep telling you to use serial debugging as if there is nothing else you can connect a cable to? The answer is in simplicity and reliability. Serial was chosen because it is simple to transfer data, bit by bit, not like for example done with a parallel port. There are different interfaces which also can transfer information bit by bit (like Ethernet, Firewire and USB) but the standard serial port is common to all platforms and far less complex. Because of that it should come as no surprise that the old AmigaOS 3 which works on classic Amigas throw all the debug information via serial port as well. Today, we have different kinds of hardware, where for example USB is pervasive, but USB is more complex and still not as reliable for debugging purposes. |
− | = Serial and |
+ | = Serial and Null Modem = |
== Serial == |
== Serial == |
||
− | |||
− | Serial port (which offten called as RS-232, while in reality it is RS-232C) today is practically removed from all modern computers and replaced by USB, but still, from time to time, you can find out a x86 motherboard with serial port attached. Of course there is solutions to still have serial port on modern PC hardware like usb2serial adapters, and which we for sure need if our computer where we will catch the output didn't have serial, but about that we will talk later. Now, all what we need to know, is that all our ppc based amigas (old 1200/4000 and new a1,sams,peg,x1000) have Serial port and os4 kernel's reaper thrown the debug output over |
||
− | that serial port. |
||
+ | Serial ports (often called RS-232 but it's really RS-232C) have disappeared as a standard option on many user level computers and have been replaced by USB. You can still find many business level x86 motherboards with serial ports. There are solutions for PC hardware without a serial port like USB to serial converters but we will talk about that later. Right now, all we need to know is that all our PowerPC based Amigas, classic Amigas and even the AmigaOne-X1000 have a serial port and the AmigaOS kernel's reaper outputs debug information over that serial port. |
||
− | Serial port can be just 2 types of pinouts: 9 pins and 25 pins. |
||
+ | Serial ports most often come in two pin outs: 9 pins and 25 pins. |
||
− | [[File:01-serial_db25.png|frame|center|25 Pin Connector]] |
||
[[File:02-serial_db9.png|frame|center|9 Pin Connector]] |
[[File:02-serial_db9.png|frame|center|9 Pin Connector]] |
||
− | |||
+ | [[File:01-serial_db25.png|frame|center|25 Pin Connector]] |
||
− | 25 pin one, which usualy called db25, was first one (and because of that we have exactly 25 pins one in old a1200/a4000), but after some years software to use only half of pins, and then 9pin one (which usualy called db9, but in reality it is de9), was result of simplificy. And while a1200/a4000 have old serial connectors with 25pins, pegasos2, x1000, sams have 9 pins connectors. Thats in general make no differenes for our topic, just if you will build your cabled from scratch, then you just should take in account where and what pins are placed. |
||
+ | The 25 pin one, which is usually called DB25, was the first one and is used on the classic Amigas. After some time, software was simplified to use only half of the pins and then 9 pin connector (usually called DB9 but in reality it is DE9) was created. While classic Amigas have the older serial connectors with 25 pins, the Pegasos2, X1000 and Sams all have 9 pin connectors. In general, it makes no differences for our purposes. This is just information in case you decide to build your cable from scratch. |
||
− | While information given there is enough for our article, you still can check wikipedia for more info about serial port and rs232c standard itself: http://en.wikipedia.org/wiki/Serial_port |
||
+ | While the information given there is enough for our article, you still can check out Wikipedia for more information about serial ports and the RS232C standard itself at http://en.wikipedia.org/wiki/Serial_port. |
||
− | == NULL-Modem == |
||
+ | == Null Modem == |
||
− | Today, things are different. Terminals and modems are gone and computers got the same kind of serial port that terminals used to have: "DTE". As result, we can't connect |
||
− | them with a straight, pin-2-pin cable, because it will connect important for data transering pins (TX to TX and RX to RX) like it was when we connect serial port with modem |
||
− | back in times, and that will not work. Solution is to swap necessary wires: TX from one side to RX of another side. Thats already can be called as simply "Null Modem Cable" |
||
− | (through, without ground connected, which is better to do always). |
||
− | |||
− | Usually when you go to shop in 2013 and somehow found a modem-cable, it pretty possible will be _NOT_ null-modem one. You need to ask _exactly_ null-modem one, where pins |
||
− | will be swapped. Of course, workers at shop can even not understrand what you ask, as its all very unpopular today. Visually cables just looks the same, just inside wires |
||
− | can be not swapped => you will have straight serial cable => nothing will works when you will try to catch your output. |
||
+ | In the good old days, when Modems/Teletypes were used to connect over the serial port, it was expected that one side is the ''Data Terminal Equipment'' (DTE) (usually a computer/terminal) and the other side is ''Data Circuit-terminating Equipment'' (DCE) (usually a modem). One side which is an output on a DTE is an input on a DCE and vice versa. Because of that DCE can be connected to a DTE with a straight wired cable. |
||
− | NULL-Modem cable can be of 4 types: |
||
+ | Today things are different. Terminals and modems have mostly disappeared and computers have the same kind of serial port that terminals used to have: DTE. As a result, we can't connect them with a straight, pin to pin cable because it will connect the data transfer pins (TX to TX and RX to RX) like it was when we connect a serial port with a modem and that will not work. The solution is to swap the data transfer wires: TX to RX. That's what is simply called a ''Null Modem Cable'' (though without ground connected which is always better to do). |
||
− | #No hardware handshaking<br/>This cable has only the data and signal ground wires connected. I.e. Rx, Tx and Ground. |
||
+ | |||
− | #Loop back handshaking<br/>Just some "cheat" cable to make a fake flow control. |
||
+ | Usually when you go into a shop and find a modem cable it is most often not a null modem cable. You need to ask for a null modem cable where the data pins have been crossed over. Visually, the cables look exactly the same. Only the wires inside are not cross over and thus it will not transfer any serial debug output. |
||
+ | |||
+ | A null modem cable can one of 4 types: |
||
+ | |||
+ | #No hardware handshaking<br/>This cable has only the data and signal ground wires connected. I.e. RX, TX and ground. |
||
+ | #Loop back handshaking<br/>Just some "cheat" cable to create fake hardware flow control. |
||
#Partial handshaking<br/>Advanced "cheat" cable. |
#Partial handshaking<br/>Advanced "cheat" cable. |
||
− | #Full handshaking<br/>No cheats, just everything |
+ | #Full handshaking<br/>No cheats, just everything that can be in null modem cable. |
− | + | In general, to create a basic null modem cable (that one, with "no hardware handshaking") it is enough to cross over pins 2 and 3 (RxD with TxD) and connect the ground pin. Even with such a simple null modem cable of just 3 wires, you will be able to output debug information and everything will work. You can of course build a cable with full handshaking and it will also work but the hardware may or may support it. For example, the X1000 does not support hardware handshaking and even if you have such a cable, the terminal software where you will capture your debug output you still need to choose the "no handshaking" option. Classic Amiga serial ports support hardware h handshaking. For example, AmigaExplorer from AmigaForever transfers data between Amiga and Windows computers via serial and handshaking helps in that case. So it's better to have a full-handshaking cable and to test it with your hardware. But if you need a null modem cable just for capturing debug output, a simple 3 wire null modem cable will allow up to 115200 and it's more than enough. |
|
− | side, old a1200/a4000 serial ports support Handshaking (for example, such software as AmigaExploirer from AmigaForever, do transfering beetwen amiga and pc computers via serials null-modem cables, and there is speed matter and handshaking helps there). So its better to have just full-handshaking cable, and to test it with your HW. But if you need null-modem cable just for debug output (and in general thats why it need it most of time), even simply null-modem cable are allow 115200 and its more than enough for debug output. At least, there wasn't any problems ever when you need to catch a output from serial, and you can't, because 115200 somehow not enough. |
||
− | {{Note|text=If you have 2 computers which you want to connect |
+ | {{Note|text=If you have 2 computers which you want to connect via serial ports you need a null modem cable and '''not''' a ''straight'' serial cable.}} |
− | + | Since serial ports can be only of 2 types (DB25 and DB9) there are 3 possible pin outs for null modem cables with full handshaking: DB25 to DB25, DB9 to DB9 and DB9 to DB25. |
|
− | [[File:03-db25-db25.png |
+ | [[File:03-db25-db25.png|center|800px]] |
− | [[File: |
+ | [[File:05-db9-db9.png|center|800px]] |
− | [[File: |
+ | [[File:04-db25-db9.png|center|800px]] |
− | + | DB9 to DB9 serial cables are fairly easy to find in stores today but they are not likely to be null modem cables and you will need to work on them. DB25 are more rare and you may need to build a cable yourself. Just buy connectors and connect the necessary wires as shown above. |
|
− | You |
+ | You can also build a cable which has 2 connectors on either side (i.e. DB9 and DB25 on one side and DB9 and DB25 on the other) so you can use either connector type as needed. This can be handy when you have a classic Amiga and modern PowerPC hardware and connected to a PC for example. To build such a cable just follow the same pin logic as shown below and just double them where needed. |
− | you need. For example can be handy when you have and old a1200/a4000, and modern ppc hw, and your PCs happens to be different, etc. I.e. you not need to soldering iron again new |
||
− | cable, just will use one-for-all-times. To build that one you just follow the same pinout logic as shown below, just double them where you need that. |
||
− | + | Another way to solve the problem would be to buy a straight serial cable and add a small connector-adapter which will change the wiring from straight to null modem like in the screenshot below: |
|
− | you just buy small connector-adapter which will do for you that "cross-wire" of pins, and which will make from your "straight" serial cable, a null modem one. Like that on screenshot: |
||
− | + | [[File:06-null_modem_adapter.png|frame|center]] |
|
− | |||
− | + | You can find even more information about null modem cables on [http://en.wikipedia.org/wiki/Null_modem Wikipedia]. |
|
= Connect them now! = |
= Connect them now! = |
||
Line 80: | Line 70: | ||
== Serial<->Serial == |
== Serial<->Serial == |
||
− | There is nothing else you need |
+ | There is nothing else you need except a working null modem cable. It must be a real null modem cable or a ''straight'' serial cable with a null modem adapter; doesn't matter which one. |
− | real null-modem cable, or just "straigt" serial cable with null-modem adapter does not matter: just for serial ports wires should be swapped and you just connect your amiga hw with |
||
− | any other hw (with another amiga, or with any x86 hw, not so matter) by that cable. |
||
== Serial<->USB == |
== Serial<->USB == |
||
+ | This section is important and interesting for anyone who works with AmigaOS. The reason is that it is more difficult to find x86 hardware (which most of us have use as a necessary part of life) with built-in serial ports. It is even more difficult to find a notebook with a serial port. The solution is to use commonly available USB to serial adapters. There are plenty of them from all sorts of different companies. Despite the fact that they are common, some adapters can be better than others. Although most will work without problems and in practice all of the tested ones works fine, you still may found some adapters which can give you some problems. The reason is that USB does not directly translate to serial and data must be buffered between the two while at the same time keeping accurate timing. There is software inside the adapters and more than one way to implement the necessary hardware buffering thus not all adapters are equal and some are better than others. For serious serial work, nothing beats an actual UART which is why they are still an available option on industrial, laboratory and business PCs. |
||
− | Thats the part which is most important and intersting for anyone who today works with amigaos4. The reassons is that there is no more modern x86 HW (which all of us have most of time |
||
− | as necessary part of life) with serial port. More of it, most of tired from those big boxes and have only notebooks, which, again, have no serial ports anymore. The solutions there |
||
− | is easy : you can find out in any shop (yes, even in 2013) , USB-to-Serial adapters. There is plenty of them , from different companies, most of which works with no problems, because |
||
− | all what those adapters do, its just make for your HW which didn't have inbuild serial port, one more serial port. Visually they looks just like this: |
||
+ | If you in interested in building a Serial to USB adapter yourself, you can find plans on the Internet. One example is this [http://pinouts.ru/Converters/usb_serial_adapter_pinout.shtml USB to serial adapter]. |
||
− | >> 08-usb2serial.jpg << |
||
+ | [[File:07-usb2serial.png|frame|center]] |
||
− | Can be different of course, as it just about what kind of connector. Look can be different, but idea the same : in system you have now serial port. I for myself use one from |
||
− | Gembird based on Chips PS2303 on my notebook with winxp, where after installing of drivers it shows ups as COM17: |
||
+ | The look of the adapter can be different of course since it depends on what connectors are used when building a cable. I use one from Gembird based on the PS2303 chip on my notebook with Windows XP, where after installing of drivers it shows ups as COM17: |
||
− | + | [[File:08-settings_win_show.png|frame|center]] |
|
− | After you have in your system |
+ | After you have the USB to serial adapter connected in your system, everything will be the same as if you connected Serial with Serial. A null modem cable is still required or a "straight" cable with a null modem adapter. |
− | the same as if you connect just Serial with Serial. The same exactly null-modem cable, the same can be null-modem adapter with "sraight" cable and so on. |
||
== Serial<->Anything == |
== Serial<->Anything == |
||
− | You |
+ | You can connect serial to any port in a computer. You just need the correct adapter and cable. There are serial to USB (either purchased or made yourself), serial to Firewire adapters, serial to Ethernet, etc. |
− | new "serial". I.e. you can not only use serial-to-usb adapters, but, serial-to-fireware adapters (if you will lucky enough to find out that, or that will build it yourself), or, |
||
− | even, serial to "etherhen", and also, write your own driver for, etc. |
||
− | What |
+ | What I am trying to point here is that it does not matter how but you still need to make a real serial port in your system. USB to serial adapters are most popular because they are readily available, easy to find, inexpensive and well tested. |
− | in shops, easy to utilize, and everything is tested and restested by many ppls. |
||
= Terminal Software and port settings = |
= Terminal Software and port settings = |
||
− | Now, after you have your cable connected |
+ | Now, after you have your cable connected between 2 machines, you need software which will catch the data from one side. The "receiver" side can be an x86 system with Windows, Linux, Mac OS or whatever else. You could also use an Amiga with AmigaOS, pOS, Unix or whatever else runs on classic Amiga hardware or any kind of another hardware. The software is called "Terminal" software and since many of us use x86 systems to capture debug output from our Amigas, we will start with x86. |
− | and with linux, and with macos, and whatever else), and amiga with amigaos, or pOS, or unixes, or whatever was done for old amiga hardware, or ppc macs, or any kind of another HW. |
||
− | That software called "Terminal" software and as most of us use x86 notebooks to capture debug outputs from our amigas, we will start from x86. |
||
− | + | One of the best terminal software packages for x86 is PuTTY. You can get PuTTY from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. Be sure that you get latest/full version because there are some stripped versions around with no support of serial connections. The normal version of PuTTY with working serial support will looks like this: |
|
− | Be sure that you get latest/full version, because in internet some stripped versions flyed where is no support of serial connections done. Normal version with working serial |
||
− | support will looks like this: |
||
+ | [[File:09-putty_serial.png|frame|center]] |
||
− | |||
− | >> 10-putty_serial.png << |
||
− | On |
+ | On Amiga (if you connect 2 Amigas by serial) you can use the old 68k Term 4.8: |
+ | [[File:10-term48_serial.png|frame|center]] |
||
+ | On Linux you can also use PuTTY or the well-known minicom. |
||
− | >> 11-term48_serial.png << |
||
+ | Whatever software is used, it is all about getting the debug data from your Amiga. Debug output is ASCII text data, so anything which can just grab information from your serial port and redirect it where you need it (console or file) will work. You can even write your own simple code which will receive data without the need for any terminal programs. But that's in theory, in practice it is better to use something which is already done. |
||
− | On linux <insert here> |
||
+ | The settings which you need to use and which always works on any Amiga hardware from which you want to get your serial output are: |
||
− | On mac <insert here> |
||
+ | baud: 115200 |
||
+ | data bits: 8 |
||
+ | stop bits: 1 |
||
+ | parity: none |
||
+ | flow control: none |
||
+ | |||
+ | It may work with other settings (like different parity and flow control), but as it was pointed out before, on some hardware it may not work at all, on another it will not work as intended, so just these setting to do your first test. After all, you can always change your settings later and experiment after everything works. |
||
+ | = How to redirect debug output to serial = |
||
− | But its all in general about how just to get all the data. Debug outputs its plain text data, so anything which just cat grab info from your serial |
||
− | port and redirect where you need (to console or to file, not so matter) will works. I.e. you can just write your own simple code which will recieve data, without needs of |
||
− | any terminals. But thats in theory, in practice of course better to use something which already done. |
||
+ | By default, AmigaOS debug output is sent to a memory debug buffer and not to serial. This is done for simplicity. If something happens, especially bugs, then just type "DumpDebugBuffer" in a shell and it shows you what the debug output was. This is similar to using the Sashimi tool which redirects serial output to the console. |
||
− | The settings which you need to use and which 100% will works on any of amiga HW from which you want to get your serial output are: |
||
+ | For developers, it is usually best to output everything to the serial port so you need to switch the output to serial. There are 2 ways to do this: boot option in the firmware (U-Boot for Sams/Eyetech AmigaOnes, OpenFirmware for Pegasos2 and CFE for X1000) and the "KDebug" utility. |
||
− | baud: 115200 |
||
− | data bits: 8 |
||
− | stop bits: 1 |
||
− | parity: none |
||
− | flow control: none |
||
− | |||
− | It may works with some other settings (like different parity and flow control), but as it point out before, on some HW it may not works at all, on another will works not as extended, |
||
− | so just use it all the time like this when you do your first tests. After all you always can do your experiments when everything will works with those settings. |
||
+ | == Firmware method == |
||
− | = How to redirect debug output to serial = |
||
+ | Given there are so many different hardware platforms on which to run AmigaOS today, it should come as no surprise that they use different boot firmwares. AmigaOne-XE/MicroA1-C/Sam uses U-Boot, Pegasos2 uses OpenFirmware and the AmigaOne X1000 uses CFE. For all of them the boot menu options can be a bit different and you need to refer to the documentation which comes with the hardware. But in all cases you have a common variable called '''os4_commandline''' which you need to set. The name of that variable is the same for all the hardware platforms which support AmigaOS. Just the way the variable is setup varies. |
||
− | By default debug output of amigaos4 sends to the memory, and not to serial: thats done for simplifyty user friendly usage of debug logs. I.e. you have |
||
− | something happens, not expectually bugs, just any debug output and you want to see it. So you just type in console "dumpdebugbuffer", and it show you what |
||
− | debug output was (you also can use Sashimi tool, its will automatically redirect output to the console in realtime). |
||
− | + | For example on Pegasos2 OpenFirmware, to redirect output to serial with the "munge" debug kernel option and debug level 7 in OF you do: |
|
− | (UBOOT for sams/old amigaones, OpenFirmware for pegasos2 and CFE for x1000) and "kdebug" utility. |
||
+ | Pegasos BIOS Extensions Copyright 2001-2004 by bplan GmbH. |
||
− | == Firmware way == |
||
+ | All rights Reserved. |
||
− | |||
+ | Auto-boot in 1 seconds - press ESC to abort, ENTER to boot: aborted |
||
− | As we have many different hw on which os4 can be run today, then there is no suprise that they all use different firmwares: a1/sams use UBOOT, pegasos2 use |
||
+ | ok# |
||
− | OpenFirmware and x1000 use CFE. For all of them bootmenu options will be different, and you need to refer to the documentation which come with HW, but in all |
||
+ | ok# setenv os4_commandline serial munge debuglevel=7 |
||
− | the cases you have variable called "os4_commandline" to which you spend your arguments, for example: |
||
+ | and then boot AmigaOS. |
||
− | x1000/cfe to set debuglevel to 0 and output to serial: |
||
+ | On AmigaOne X1000/CFE set munge, debuglevel to 4 and output to serial: |
||
− | os4_commandline DEBUGLEVEL=0 SERIAL |
||
+ | setenv -p os4_commandline "serial munge debuglevel=4" |
||
− | Pegasos2 OpenFirmware to redirect otput to serial with debug kernel's option "munge": |
||
+ | and then boot AmigaOS. For CFE if you are not using -p, then the variable is only saved for that session, not permanently. |
||
− | os4_commandline='munge' |
||
− | + | On Sam/AmigaOne U-Boot with the same munge, debuglevel=7 and serial redirect: |
|
− | os4_commandline= |
+ | setenv os4_commandline "serial munge debuglevel=7" |
+ | saveenv |
||
+ | On X5000 it's the same U-Boot as with Sam/AmigaOne, so as example set serial, munge and debuglevel to 5: |
||
− | == Kdebug way == |
||
+ | setenv os4_commandline serial munge debuglevel=5 |
||
− | Kdebug is command line utility placed in System:C/kdebug and come as part of Kernel. By that utility you can redirect your output to serial/memory (i.e. it will |
||
+ | saveenv |
||
− | overwrite what you do from firmware), as well as by that you can setup debug levels. You just put for example to s:user-startup something like: |
||
+ | In other words, use SetEnv to set the os4_commandline variable and then boot the OS. You can also verify what the variable is using the "printenv" command. |
||
− | run >NIL: kdegbug "debug level 5" |
||
− | run >NIL: kdebug "console serial" |
||
+ | Just so you are not confused, "amigaboot.of" (the code which first boots) is the component which parses the os4_commandline '''firmware variable''' and ''didn't'' parse any command line arguments. It only parses firmware variables and then passes them on to the kernel. If you try something like ''amigaboot.of os4_commandline = "serial"'', it will not work and will be ignored, the same as any other extra parameters you provide. So be sure that you use "setenv" and check via "printenv" that you set the variable correctly. |
||
− | And so you have level 5 output thrown on your serial line. |
||
+ | == KDebug method == |
||
− | = Get most of serial debugging (debug kernel + debug levels + munge + memguard) = |
||
+ | KDebug is command line utility found in SYS:C which communicates with the AmigaOS kernel. With this utility you can redirect your output to serial or memory. It will override whatever you do with the os4_commandline firmware variable. This is very handy for setting different debug levels at the time you need it. For example, you may also put a command in S:User-Startup |
||
− | To start with, you need to read those 2 articles: |
||
+ | run >NIL: kdebug "debuglevel 5" |
||
+ | run >NIL: kdebug "console serial" |
||
+ | This will set the debug level to 5 and output via the serial port. |
||
− | 1. http://wiki.amigaos.net/index.php/Debug_Kernel |
||
− | 2. http://wiki.amigaos.net/index.php/Exec_Debug |
||
+ | To note ,that in firmware method we use '=' for debuglevel, i.e. 'debuglevel=5'. But when we use 'kdebug", then instead of '=' we put space, i.e. 'debuglevel 5'. |
||
− | From which you should do the accumtion just when you develop anything, you should all the time use debug.kernel. Debug.kernel provide you with some more functionality in |
||
− | compare with user's plain kernel, as well as it give you ability to plays with debug levels, where you can choice how much of "system" debug output you want to get. Its |
||
− | pretty easy to miss that bit, that debug-levels works only on debug.kernels. Usually developers start to plays with levels, see no changes, and start to think "wtf, why it |
||
− | not works". It works, just kernel should be debug one. |
||
+ | {{Note|Quotation marks are mandatory when using the KDebug tool. What KDebug does is send whatever string you enter directly to the AmigaOS kernel for interpretation. The KDebug command itself does not parse the string.}} |
||
− | And while debug kernel give you some debug functionality, it still didn't cover everything possible like for example do old MungWalls (i.e. debug kernel have only "Munge" |
||
− | feature, but not "Wall" feature), or like for example do MemGuard (can be found on os4depot), which add on top of kernel some more dirty-stuff-catch. |
||
+ | {{Note|KDebug method have higher priority. I.e. if you set your environment variable to some values, and then after os is boots use KDebug to change the settings, then they ''will'' be taken in account and previous one will be forgotten. The only thing that you can't enable/disable by KDebug is 'munge'.}} |
||
− | So, to get most of your serial debugging, you need to use that combo: debug kernel with "munge" option enabled, "memguard" running on background and set debug level to the |
||
+ | |||
− | value you find most interesting. Usually 5 or 7 is enough, but sometime when bug so heavy and strange, you can raise the volume in hope to see something intersting. |
||
+ | = Getting the Most out of Serial Debugging = |
||
+ | |||
+ | To start with, you need to read the following articles: |
||
+ | # [[Debug_Kernel|The Debug Kernel]] |
||
+ | # [[Exec_Debug|Exec Debug]] |
||
+ | |||
+ | To get the most out of serial debugging, developers should use what is called the debug kernel (named '''kernel.debug'''). The debug kernel provides you with more functionality compared with the release kernel at the cost of some execution speed. One thing provided is the ability to play with debug levels where you can choose how much "system" debug output you want to see. It's pretty easy to miss the fact that debug levels only work on debug kernels. You can play with levels, see no change, and you then wonder "Why doesn't it work?". It works, it is just that the kernel should be the debug one. |
||
+ | |||
+ | And while the debug kernel does give you some debug functionality, it still may not cover everything. For example, tools like the old MungWall tool can do a bit more: debug kernel has only the "munge" feature but not the "wall" feature. Another example is MemGuard (which can be found on [http://www.os4depot.net OS4Depot]) adds additional debug capabilities on top of what the debug kernel provides and catches more difficult to find bugs. |
||
+ | |||
+ | So, to get most of serial debugging, you need to use a combination: debug kernel with "munge" option enabled, MemGuard running in the background and set debug level to the value you find most informative. Usually 5 or 7 is enough but sometimes, when a bug is behaving very strangely, you can raise the value in the hope that you see something interesting. |
||
= If nothing works = |
= If nothing works = |
||
− | Now to |
+ | Now on to troubleshooting. If you build/buy a cable, adapters and all the stuff, connect everything, fire up the terminal software, set up everything correctly and still nothing works, then: |
− | nothing works, then: |
||
− | + | # Check the cable |
|
+ | # Check the ports. |
||
+ | # Check the cable again :) |
||
+ | # Check program's settings and settings of the port if it USB to serial one. |
||
+ | Be sure that for you have right settings and in the terminal software (especially the baud, flow control and parity). |
||
− | Easy way to check if the port is working |
||
− | |||
− | ... TODO to finish ... |
||
− | |||
− | |||
− | 2. Twice recheck a cable. |
||
− | |||
− | The best and only one way will be a meter which set to "beep" or 0mhs, so when you will touch wires on different sides you will heard "beep" if it connected. Recheck |
||
− | all of them as they should be, and if all is ok, then cable is fine. If you use null-modem adapter on top of "straight" serial cable, then recheck with it anyway just in |
||
− | case, by the same meter. |
||
− | |||
+ | If you have a few '''spare''' connectors that you can use for troubleshooting, just solder a jumper between TX and RX (pins 2 and 3 on DB9). |
||
− | 3. Check program's settings and settings of the port if it usb-2-serial one. |
||
+ | Then open a terminal program on the computer, set it up as described above, and turn "Local Echo" OFF. When Local Echo is OFF it does |
||
− | |||
+ | NOT show what you are typing, it only shows what comes in over the serial port. |
||
− | Be sure that for you have right settings and in terminal software (expectually those ones about speed, flow control and parity) as well as |
||
+ | |||
+ | The "loopback" connector has TX and RX connected, so it will loop whatever you send back to you. Plug a female loopback directly into the serial port connector and you should see whatever you type, because it is being "looped back" through your test plug. Now take the loopback off, connect your cable, and attach a male loopback at the other end of the cable. If you can see your typing, then you are successfully going out the serial port, down your cable, then looping back up the cable and back into your port.. You get the idea. Having one male and one female "loopback" will let you test ALMOST every possible cable, connection, and software configuration. |
||
+ | |||
+ | Desperate times: If you don't have any "spare" connectors or a soldering iron, a small paper clip can be used instead of a male loopback connector.. Just bend the clip and insert the ends into pins 2 and 3 of the cable end, and connect the other end to the serial port being tested. If the clip does not fit into the cable end, don't force it, find a smaller paper clip. |
||
+ | |||
+ | The one thing that a loopback can NOT test is whether your cable is a "Null Modem" cable or not. |
||
+ | The best way to check a cable is with a multimeter. Set it so that when you touch wires on different sides you will heard a "beep" if it connected. That setting usually looks like a little speaker. Check that all of the connections are as they should be. If you use null modem adapter on top of "straight" serial cable, then check it anyway, just in case, with the same meter. The meter lead probably won't fit inside the female connector pins. Another small paper clip helps with that. |
||
+ | |||
+ | To work properly, (describe a null modem cable, assuming 9 pin to 9 pin): |
||
+ | * Pin 2 on end A should connect to pin 3 on end B. |
||
+ | * Pin 3 on end A should connect to pin 2 on end B. |
||
+ | * Pin 5 on end A should connect to pin 5 on end B. |
||
+ | |||
+ | If these three connections work, it should be enough to get you going. |
||
= Final words = |
= Final words = |
||
+ | While this topic is more or less an easy one, there wasn't a guide, until now, which describes everything from the beginning. What kind of cable you can use, how to build it, how to use USB to serial adapters, what settings should be used and what to do with it all. We hope that this guide will at least cover all the gaps and any developers told to "use serial debugging" will just read that article and will have no questions. Anyway, if you have any more info to add, or just found a wrong part somewhere, just send an email to kas1e@yandex.ru or use the [http://www.amigaos.net/Contact AmigaOS Contact Form] and we can update article. |
||
− | While the whole topic we describe is more or less easy one, there wasn't normall guide till now which describe from the begining evertyhing: i.e. what kind of cable you can use, |
||
− | how to build it, how to use usb2serial adapters, what settings should be used and what to do with all of this. We hope that this guide will at least cover all the gaps in that |
||
− | terms, and any developer who ever will head "use serial debugging" will just read that article, and will have no questions. Anyway, if you have any more info to add, or |
||
− | just found a wrong part somewhere, just send me mail on kas1e@yandex.ru and i can udate article. |
||
= Links = |
= Links = |
||
Line 238: | Line 221: | ||
[1.] http://en.wikipedia.org/wiki/Serial_port |
[1.] http://en.wikipedia.org/wiki/Serial_port |
||
[2.] http://en.wikipedia.org/wiki/Null_modem |
[2.] http://en.wikipedia.org/wiki/Null_modem |
||
− | [3 |
+ | [3.] [[Debug_Kernel|Debug Kernel]] |
− | [4.] |
+ | [4.] [[Exec_Debug|Exec Debug]] |
Latest revision as of 19:52, 26 December 2020
Contents
Author
Roman Kargin and Lyle Hazelwood
Copyright © 2013 Roman Kargin and Lyle Hazelwood
Proofreading and grammar corrections by the AmigaOS Wiki team.
Introduction
While AmigaOS has "hi-level" capabilities to help debug problems (e.g. redirecting debug outputs to memory and displaying the log with DumpDebugBuffer or using serial redirection tools like Sashimi) it is sometimes still not enough. For example, there is no protection for areas like input and Intuition so we can get into a situation where the GUI is not operational but the OS is still working. Intuition, input and any other necessary components can crash and then the GrimReaper utility has no way to spawn itself. Meanwhile, the kernel, still can output debug information about the crash on serial.
To begin with, you should know that AmigaOS has 2 reapers. One is a user friendly utility from SYS:System called GrimReaper. The GrimReaper can be called a "hi-level" one. Another reaper is called Reaper which is a part of the kernel itself. The kernel's Reaper actually launches the user-friendly GrimReaper when a required. So, you can imagine that when things get nasty, the kernel's reaper not all the time can spawn a GrimReaper, but still can catch some information and output it to the serial. Visually, when such a nasty things happens and input and/or intuition die, you just see a "freeze" of the OS and may think that everything is freezes, while it not: you just can't operate with OS anymore as necessary parts of OS crashes, but OS itself still working and kernel's reaper already throw all the info into the serial.
That means that when you want to do some serious work and you need any way to catch your bugs and/or debug any of your problematic code, then serial debugging is the best and only one way. Of course it's still possible to hope that the system friendly GrimReaper will popup for you and that there will be nothing so hardcore which it will crash Intuition and "freeze" the OS but that's just not enough when it come to doing real work.
You may ask now why the serial port is used at all? Why not parallel or something else? Why does everyone keep telling you to use serial debugging as if there is nothing else you can connect a cable to? The answer is in simplicity and reliability. Serial was chosen because it is simple to transfer data, bit by bit, not like for example done with a parallel port. There are different interfaces which also can transfer information bit by bit (like Ethernet, Firewire and USB) but the standard serial port is common to all platforms and far less complex. Because of that it should come as no surprise that the old AmigaOS 3 which works on classic Amigas throw all the debug information via serial port as well. Today, we have different kinds of hardware, where for example USB is pervasive, but USB is more complex and still not as reliable for debugging purposes.
Serial and Null Modem
Serial
Serial ports (often called RS-232 but it's really RS-232C) have disappeared as a standard option on many user level computers and have been replaced by USB. You can still find many business level x86 motherboards with serial ports. There are solutions for PC hardware without a serial port like USB to serial converters but we will talk about that later. Right now, all we need to know is that all our PowerPC based Amigas, classic Amigas and even the AmigaOne-X1000 have a serial port and the AmigaOS kernel's reaper outputs debug information over that serial port.
Serial ports most often come in two pin outs: 9 pins and 25 pins.
The 25 pin one, which is usually called DB25, was the first one and is used on the classic Amigas. After some time, software was simplified to use only half of the pins and then 9 pin connector (usually called DB9 but in reality it is DE9) was created. While classic Amigas have the older serial connectors with 25 pins, the Pegasos2, X1000 and Sams all have 9 pin connectors. In general, it makes no differences for our purposes. This is just information in case you decide to build your cable from scratch.
While the information given there is enough for our article, you still can check out Wikipedia for more information about serial ports and the RS232C standard itself at http://en.wikipedia.org/wiki/Serial_port.
Null Modem
In the good old days, when Modems/Teletypes were used to connect over the serial port, it was expected that one side is the Data Terminal Equipment (DTE) (usually a computer/terminal) and the other side is Data Circuit-terminating Equipment (DCE) (usually a modem). One side which is an output on a DTE is an input on a DCE and vice versa. Because of that DCE can be connected to a DTE with a straight wired cable.
Today things are different. Terminals and modems have mostly disappeared and computers have the same kind of serial port that terminals used to have: DTE. As a result, we can't connect them with a straight, pin to pin cable because it will connect the data transfer pins (TX to TX and RX to RX) like it was when we connect a serial port with a modem and that will not work. The solution is to swap the data transfer wires: TX to RX. That's what is simply called a Null Modem Cable (though without ground connected which is always better to do).
Usually when you go into a shop and find a modem cable it is most often not a null modem cable. You need to ask for a null modem cable where the data pins have been crossed over. Visually, the cables look exactly the same. Only the wires inside are not cross over and thus it will not transfer any serial debug output.
A null modem cable can one of 4 types:
- No hardware handshaking
This cable has only the data and signal ground wires connected. I.e. RX, TX and ground. - Loop back handshaking
Just some "cheat" cable to create fake hardware flow control. - Partial handshaking
Advanced "cheat" cable. - Full handshaking
No cheats, just everything that can be in null modem cable.
In general, to create a basic null modem cable (that one, with "no hardware handshaking") it is enough to cross over pins 2 and 3 (RxD with TxD) and connect the ground pin. Even with such a simple null modem cable of just 3 wires, you will be able to output debug information and everything will work. You can of course build a cable with full handshaking and it will also work but the hardware may or may support it. For example, the X1000 does not support hardware handshaking and even if you have such a cable, the terminal software where you will capture your debug output you still need to choose the "no handshaking" option. Classic Amiga serial ports support hardware h handshaking. For example, AmigaExplorer from AmigaForever transfers data between Amiga and Windows computers via serial and handshaking helps in that case. So it's better to have a full-handshaking cable and to test it with your hardware. But if you need a null modem cable just for capturing debug output, a simple 3 wire null modem cable will allow up to 115200 and it's more than enough.
Note |
---|
If you have 2 computers which you want to connect via serial ports you need a null modem cable and not a straight serial cable. |
Since serial ports can be only of 2 types (DB25 and DB9) there are 3 possible pin outs for null modem cables with full handshaking: DB25 to DB25, DB9 to DB9 and DB9 to DB25.
DB9 to DB9 serial cables are fairly easy to find in stores today but they are not likely to be null modem cables and you will need to work on them. DB25 are more rare and you may need to build a cable yourself. Just buy connectors and connect the necessary wires as shown above.
You can also build a cable which has 2 connectors on either side (i.e. DB9 and DB25 on one side and DB9 and DB25 on the other) so you can use either connector type as needed. This can be handy when you have a classic Amiga and modern PowerPC hardware and connected to a PC for example. To build such a cable just follow the same pin logic as shown below and just double them where needed.
Another way to solve the problem would be to buy a straight serial cable and add a small connector-adapter which will change the wiring from straight to null modem like in the screenshot below:
You can find even more information about null modem cables on Wikipedia.
Connect them now!
Serial<->Serial
There is nothing else you need except a working null modem cable. It must be a real null modem cable or a straight serial cable with a null modem adapter; doesn't matter which one.
Serial<->USB
This section is important and interesting for anyone who works with AmigaOS. The reason is that it is more difficult to find x86 hardware (which most of us have use as a necessary part of life) with built-in serial ports. It is even more difficult to find a notebook with a serial port. The solution is to use commonly available USB to serial adapters. There are plenty of them from all sorts of different companies. Despite the fact that they are common, some adapters can be better than others. Although most will work without problems and in practice all of the tested ones works fine, you still may found some adapters which can give you some problems. The reason is that USB does not directly translate to serial and data must be buffered between the two while at the same time keeping accurate timing. There is software inside the adapters and more than one way to implement the necessary hardware buffering thus not all adapters are equal and some are better than others. For serious serial work, nothing beats an actual UART which is why they are still an available option on industrial, laboratory and business PCs.
If you in interested in building a Serial to USB adapter yourself, you can find plans on the Internet. One example is this USB to serial adapter.
The look of the adapter can be different of course since it depends on what connectors are used when building a cable. I use one from Gembird based on the PS2303 chip on my notebook with Windows XP, where after installing of drivers it shows ups as COM17:
After you have the USB to serial adapter connected in your system, everything will be the same as if you connected Serial with Serial. A null modem cable is still required or a "straight" cable with a null modem adapter.
Serial<->Anything
You can connect serial to any port in a computer. You just need the correct adapter and cable. There are serial to USB (either purchased or made yourself), serial to Firewire adapters, serial to Ethernet, etc.
What I am trying to point here is that it does not matter how but you still need to make a real serial port in your system. USB to serial adapters are most popular because they are readily available, easy to find, inexpensive and well tested.
Terminal Software and port settings
Now, after you have your cable connected between 2 machines, you need software which will catch the data from one side. The "receiver" side can be an x86 system with Windows, Linux, Mac OS or whatever else. You could also use an Amiga with AmigaOS, pOS, Unix or whatever else runs on classic Amiga hardware or any kind of another hardware. The software is called "Terminal" software and since many of us use x86 systems to capture debug output from our Amigas, we will start with x86.
One of the best terminal software packages for x86 is PuTTY. You can get PuTTY from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. Be sure that you get latest/full version because there are some stripped versions around with no support of serial connections. The normal version of PuTTY with working serial support will looks like this:
On Amiga (if you connect 2 Amigas by serial) you can use the old 68k Term 4.8:
On Linux you can also use PuTTY or the well-known minicom.
Whatever software is used, it is all about getting the debug data from your Amiga. Debug output is ASCII text data, so anything which can just grab information from your serial port and redirect it where you need it (console or file) will work. You can even write your own simple code which will receive data without the need for any terminal programs. But that's in theory, in practice it is better to use something which is already done.
The settings which you need to use and which always works on any Amiga hardware from which you want to get your serial output are:
baud: 115200 data bits: 8 stop bits: 1 parity: none flow control: none
It may work with other settings (like different parity and flow control), but as it was pointed out before, on some hardware it may not work at all, on another it will not work as intended, so just these setting to do your first test. After all, you can always change your settings later and experiment after everything works.
How to redirect debug output to serial
By default, AmigaOS debug output is sent to a memory debug buffer and not to serial. This is done for simplicity. If something happens, especially bugs, then just type "DumpDebugBuffer" in a shell and it shows you what the debug output was. This is similar to using the Sashimi tool which redirects serial output to the console.
For developers, it is usually best to output everything to the serial port so you need to switch the output to serial. There are 2 ways to do this: boot option in the firmware (U-Boot for Sams/Eyetech AmigaOnes, OpenFirmware for Pegasos2 and CFE for X1000) and the "KDebug" utility.
Firmware method
Given there are so many different hardware platforms on which to run AmigaOS today, it should come as no surprise that they use different boot firmwares. AmigaOne-XE/MicroA1-C/Sam uses U-Boot, Pegasos2 uses OpenFirmware and the AmigaOne X1000 uses CFE. For all of them the boot menu options can be a bit different and you need to refer to the documentation which comes with the hardware. But in all cases you have a common variable called os4_commandline which you need to set. The name of that variable is the same for all the hardware platforms which support AmigaOS. Just the way the variable is setup varies.
For example on Pegasos2 OpenFirmware, to redirect output to serial with the "munge" debug kernel option and debug level 7 in OF you do:
Pegasos BIOS Extensions Copyright 2001-2004 by bplan GmbH. All rights Reserved. Auto-boot in 1 seconds - press ESC to abort, ENTER to boot: aborted ok# ok# setenv os4_commandline serial munge debuglevel=7
and then boot AmigaOS.
On AmigaOne X1000/CFE set munge, debuglevel to 4 and output to serial:
setenv -p os4_commandline "serial munge debuglevel=4"
and then boot AmigaOS. For CFE if you are not using -p, then the variable is only saved for that session, not permanently.
On Sam/AmigaOne U-Boot with the same munge, debuglevel=7 and serial redirect:
setenv os4_commandline "serial munge debuglevel=7" saveenv
On X5000 it's the same U-Boot as with Sam/AmigaOne, so as example set serial, munge and debuglevel to 5:
setenv os4_commandline serial munge debuglevel=5 saveenv
In other words, use SetEnv to set the os4_commandline variable and then boot the OS. You can also verify what the variable is using the "printenv" command.
Just so you are not confused, "amigaboot.of" (the code which first boots) is the component which parses the os4_commandline firmware variable and didn't parse any command line arguments. It only parses firmware variables and then passes them on to the kernel. If you try something like amigaboot.of os4_commandline = "serial", it will not work and will be ignored, the same as any other extra parameters you provide. So be sure that you use "setenv" and check via "printenv" that you set the variable correctly.
KDebug method
KDebug is command line utility found in SYS:C which communicates with the AmigaOS kernel. With this utility you can redirect your output to serial or memory. It will override whatever you do with the os4_commandline firmware variable. This is very handy for setting different debug levels at the time you need it. For example, you may also put a command in S:User-Startup
run >NIL: kdebug "debuglevel 5" run >NIL: kdebug "console serial"
This will set the debug level to 5 and output via the serial port.
To note ,that in firmware method we use '=' for debuglevel, i.e. 'debuglevel=5'. But when we use 'kdebug", then instead of '=' we put space, i.e. 'debuglevel 5'.
Note |
---|
Quotation marks are mandatory when using the KDebug tool. What KDebug does is send whatever string you enter directly to the AmigaOS kernel for interpretation. The KDebug command itself does not parse the string. |
Note |
---|
KDebug method have higher priority. I.e. if you set your environment variable to some values, and then after os is boots use KDebug to change the settings, then they will be taken in account and previous one will be forgotten. The only thing that you can't enable/disable by KDebug is 'munge'. |
Getting the Most out of Serial Debugging
To start with, you need to read the following articles:
To get the most out of serial debugging, developers should use what is called the debug kernel (named kernel.debug). The debug kernel provides you with more functionality compared with the release kernel at the cost of some execution speed. One thing provided is the ability to play with debug levels where you can choose how much "system" debug output you want to see. It's pretty easy to miss the fact that debug levels only work on debug kernels. You can play with levels, see no change, and you then wonder "Why doesn't it work?". It works, it is just that the kernel should be the debug one.
And while the debug kernel does give you some debug functionality, it still may not cover everything. For example, tools like the old MungWall tool can do a bit more: debug kernel has only the "munge" feature but not the "wall" feature. Another example is MemGuard (which can be found on OS4Depot) adds additional debug capabilities on top of what the debug kernel provides and catches more difficult to find bugs.
So, to get most of serial debugging, you need to use a combination: debug kernel with "munge" option enabled, MemGuard running in the background and set debug level to the value you find most informative. Usually 5 or 7 is enough but sometimes, when a bug is behaving very strangely, you can raise the value in the hope that you see something interesting.
If nothing works
Now on to troubleshooting. If you build/buy a cable, adapters and all the stuff, connect everything, fire up the terminal software, set up everything correctly and still nothing works, then:
- Check the cable
- Check the ports.
- Check the cable again :)
- Check program's settings and settings of the port if it USB to serial one.
Be sure that for you have right settings and in the terminal software (especially the baud, flow control and parity).
If you have a few spare connectors that you can use for troubleshooting, just solder a jumper between TX and RX (pins 2 and 3 on DB9). Then open a terminal program on the computer, set it up as described above, and turn "Local Echo" OFF. When Local Echo is OFF it does NOT show what you are typing, it only shows what comes in over the serial port.
The "loopback" connector has TX and RX connected, so it will loop whatever you send back to you. Plug a female loopback directly into the serial port connector and you should see whatever you type, because it is being "looped back" through your test plug. Now take the loopback off, connect your cable, and attach a male loopback at the other end of the cable. If you can see your typing, then you are successfully going out the serial port, down your cable, then looping back up the cable and back into your port.. You get the idea. Having one male and one female "loopback" will let you test ALMOST every possible cable, connection, and software configuration.
Desperate times: If you don't have any "spare" connectors or a soldering iron, a small paper clip can be used instead of a male loopback connector.. Just bend the clip and insert the ends into pins 2 and 3 of the cable end, and connect the other end to the serial port being tested. If the clip does not fit into the cable end, don't force it, find a smaller paper clip.
The one thing that a loopback can NOT test is whether your cable is a "Null Modem" cable or not. The best way to check a cable is with a multimeter. Set it so that when you touch wires on different sides you will heard a "beep" if it connected. That setting usually looks like a little speaker. Check that all of the connections are as they should be. If you use null modem adapter on top of "straight" serial cable, then check it anyway, just in case, with the same meter. The meter lead probably won't fit inside the female connector pins. Another small paper clip helps with that.
To work properly, (describe a null modem cable, assuming 9 pin to 9 pin):
- Pin 2 on end A should connect to pin 3 on end B.
- Pin 3 on end A should connect to pin 2 on end B.
- Pin 5 on end A should connect to pin 5 on end B.
If these three connections work, it should be enough to get you going.
Final words
While this topic is more or less an easy one, there wasn't a guide, until now, which describes everything from the beginning. What kind of cable you can use, how to build it, how to use USB to serial adapters, what settings should be used and what to do with it all. We hope that this guide will at least cover all the gaps and any developers told to "use serial debugging" will just read that article and will have no questions. Anyway, if you have any more info to add, or just found a wrong part somewhere, just send an email to kas1e@yandex.ru or use the AmigaOS Contact Form and we can update article.
Links
[1.] http://en.wikipedia.org/wiki/Serial_port [2.] http://en.wikipedia.org/wiki/Null_modem [3.] Debug Kernel [4.] Exec Debug