Debug Linux kernel in a board without GDB - c

I am totally a fresh on an assignment of developing a driver on a board, which uses a "small" Linux. Every time I make everything and get a ".bin" file on PC and then ftp ".bin" to the board, the system will just work.
Now the problem come. I checked the system, it can not use gdb. So when the system crash, it will just provide a core dump file, which gives messy address info (seems not helping or at least I have no idea how to use this).
Any experienced embedded developer can kindly give some suggestions? How you debugging in your work?
By the way, if the console print crash info includes stack info and Call Trace, no epc and ra (I just learnt that). Can the epc(crashed address) be found still?

Many kernel developers, including myself, do not use a debugger when developing device drivers. For many years, Linux did not support kernel debugging. Even now, not all CPU architectures support kernel debugging.
One of the easiest things you can do is to use printk to log events to the console. Also, increase the console UART speed. I often use 115200 baud.
The Linux kernel does support kgdb now, for some CPU architectures.
https://www.kernel.org/doc/htmldocs/kgdb/index.html
I also highly recommend Linux kernel developers read these two books:
Linux Device Drivers, by Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman
Understanding the Linux Kernel, by Daniel P. Bovet, Marco Cesati

Related

How to debug Bootloader Qemu ARM?

I'm trying to boot a kernel (extracted from a firmware) using QEMU.
Qemu emulation seems to start at 0x0.
The problem is that the memory from 0x0 to 0x04000000 is only filled with 0.
How can i debug the bootloader?
You don't say what your command line is. The address where QEMU starts execution depends on many things:
the guest CPU architecture
which board model you are emulating
whether you passed QEMU a BIOS image file
the file format of any file passed to -kernel (ELF, plain kernel image, uImage, etc)
In general, though, you should not expect to be able to pull a random kernel image out of a firmware dump for a piece of Arm hardware and run it under QEMU. This is because every Arm board or machine is different -- RAM may be in different places, the devices such as the serial port are at different addresses, and so on -- and the kernel will only boot on systems which it has been compiled to support. The chances are very high that (a) QEMU does not have a specific emulation of the bit of hardware that the firmware dump is for and (b) the kernel from the firmware has not been built to also run on any of the board types that QEMU does support. So it will almost certainly simply crash very early on in bootup without producing any output.
If you want to debug what's going on in early bootup, the best approach is probably to use QEMU's built in gdbstub, and attach a guest-architecture-aware gdb to it. You may also find QEMU's internal logging via the '-d' option useful, though it requires some familiarity with how QEMU works to make sense of the output.

What can I use to debug/trace step-by-step Freebsd kernel booting process on Pandaboard?

To start with - I don't have JTAG hardware debugger.
What I have:
Pandaboard and serial-USB cable to connect to console and my computer with Freebsd and GNU/Linux distribution.
What I'm looking for
- convinient way to trace/debug bootprocess inside FreeBSD kernel ( I'm mostly interested in this fragment: https://github.com/freebsd/freebsd/blob/master/sys/arm/arm/locore-v6.S and https://github.com/freebsd/freebsd/blob/master/sys/arm/arm/mp_machdep.c as I'm, going to modyfy those files ).
Based on my experience, there are few ways:
KDB / DDB: add call kdb_enter("A", "XYZ") to stop processing and enter interactive debug mode of DDB via serial.
printf-s in machine dependent (mach_dep) code
bootverbose, BUSDEBUG, VERBOSE_SYSINIT in machine independent code
Also it's worth to mention that DDB code contains functions to print registers, stack trace and etc.

Running MMU-less Linux on ARM Cortex-R4

I'm using ARM Cortex-R4 for my system. It has a Memory Protection Unit instead of a Memory Management Unit. Effectively, this means that there's dedicated hardware for memory protection but that there's a one-to-one mapping between physical and virtual addresses. I'm a little confused about which Linux I should go for - standard Linux kernel with MMU disabled or uCLinux.
On ARM's evaluation board, I have run the standard kernel compiled with MMU disabled. I used the cramfs filesystem which is available on the official ARM website. After the kernel boots up, I'm in the shell, but I couldn't do much experimentation as I found that, most of the time, the shell stops responding (particularly when I press "tab" for auto-completion).
So I'm still not sure whether the MMU-less kernel should run smoothly if I use the correct filesystem. Also, which distro (buildroot?) should I use for the no-VM Linux?
Any idea or suggestion is welcome.
It's been more than 2 years since I asked this question. Now is the time I should write what I found for myself.
ucLinux was a project forked from the Linux kernel long back with the aim to develop Kernel for MMU less systems. However, after a certain while, it was merged to the parent Linux branch. So, today there doesn't exist any active ucLinux distribution.
So, if you disable MMU from the mainline kernel configuration, you'll get an MMU-less version. In fact, now there are configuration options provided in the kernel itself whereby a user can specify the memory layout and the access permissions.
Cheers!
uClinux is a Linux distribution which uses the Linux kernel with the MMU "turned off" and adds some applications and libraries on top of it. You wont choose one or the either as they are best one on top of the other.
If you got to a point where you have a shell running, you've managed to boot Linux sans MMU on your board but ran into a bug.
I believe ucLinux was built for something just like this [mmu less systems]
http://www.uclinux.org/description/

embedded uclinux footprint on cortex M3

I am having trouble with this question, somebody (hopefully mistakenly) moved the previous question to Unix/Linux list which has zero uclinux tagged questions. This is more of a embedded linux question..
I have a question about the footprint of uClinux. I have looked around to find a breakdown of requirements, there is no nice info on the net. The modules under interest are:
Core kernel TCPIP stack Serial Driver DHCP WiFi Support (any of the stack from vendors is ok) I am looking for RAM/Flash breakdown. I don't need a filesystem however there is a chance that I need it due to the driver model of Linux.
Bonus question: - Porting drivers from Linux to uClinux. I know the memory architecture is different. Considering driver doesn't do anything special wrt memory, could I just recompile the driver and expect it to work under uClinux?
I understand the drivers work pretty well. This driver has been ported to uClinux on Blackfin and STM32. http://www.sagrad.com/index.php?option=com_content&view=article&id=130&Itemid=130
The are running a sale on the ICs, Most of their modules that support WiFi and linux work with uClinux.

NASM accessing sound card directly (No OS)

I'm attempting to write a very simple OS in ASM and C. (NASM assembler)
I would like to access the sound card directly, with or without drivers.
If I don't need drivers, how could I access and send a sample audio file
to the sound card? (An example would be nice)
If I do need drivers, is there anyway to interface them and call functions
from the drivers? And how do I access and send a sample audio file to the
sound card? (Another example would be nice)
I hate to discourage you, but modern sound card drivers are extremely complicated, and as you probably know, OS-specific. This is one of the difficult challenges in OS development - driver support. It's not something that can be achieved with a simple code snippet.
In order to load a file, you need a file system. Have you implemented that yet? The fact that you used the "kernel" flag suggests that your OS is still in its infancy. I'm not sure I would want to put sound support into the kernel of an operating system.
That being said, there is a good emulator called Bochs that has Sound Blaster 16 emulation. And some really old documentation for how to program it. This might be your best bet. Accessing sound hardware was much easier back in the day.
Your best bet is probably to look at either the Linux or FreeBSD sound drivers and see what they do. You're not likely to get much better implementation documentation for any but the simplest sound card...
This is a hard problem. Be warned :-p
Of course you need a driver, and of course there's no easy way to interface with existing ones (there was some proposal for a unified OS-agnostic "Uniform Driver Interface" - but I don't think it got anywhere).
So, after you've written the code to read a file from your hard drive, you'll need to roll your own audio driver.
Now, I haven't done this in a while, so this may be outdated, but in the 90's you'd configure your sound card with a few 'out dx, al' (details varied across soundcards), and then setup DMA to send data from a memory buffer to your card. The card (or was it the DMA controller?) would fire off an interrupt when it reached the end of the buffer, which you'd use to fill the buffer with new data.
If your card has a working linux driver I'd start by looking at its code. Otherwise, you'll have to reverse engineer the windows driver, Soft-Ice's bpio (break on io port access) logging used to be good for that iirc.
Good luck.
Here is a free open-sourced operating system written in all assembly. It is great reference for assembly kernel programming if you are new to it.
http://www.menuetos.net/index.htm

Resources