

Breaking Into The World Of Kernel Hacking? 202
crow_t_robot asks: "In
the past couple of months I have become increasingly interested in
kernel programming and have finally decided to take the leap and
'get my hands dirty.' I have searched around the web and read a few
docs and FAQs on getting started with the kernel but I was wondering
what kind of personal experiences those in the Slashdot crowd have
had that are so bold as to start goofing with the kernel code. For
those that have become competent kernel programmers, how did you
'break in' and what advice would you give beginners?"
Haven't tried it myself, but... (Score:4, Informative)
Re:Haven't tried it myself, but... (Score:3, Insightful)
Think about it dude, he has spent time reading the FAQ's and such, he wants personal stories, so that is what he should get, sadly though, I don't have that many, well not of the type he wants.
I wish people would read the Ask
Take care - RL
Re:Haven't tried it myself, but... (Score:2)
I especially liked the 0.01 kernel walkthrough [kernelnewbies.org]
Re:Haven't tried it myself, but... (Score:2)
Mod tip #666 "Never smoke crack when using them five points"
In honor of all the linux newsgroups... (Score:4, Insightful)
Seriously, though. Try and find FRIENDLY help. Once you have that, you should be good to go. A lot of kernel hackers are very elitest, and don't take too kindly to newbies, so find yourself a good support group and go from there.
Re:In honor of all the linux newsgroups... (Score:1)
Re:In honor of all the linux newsgroups... (Score:1)
I guess when I called it the linux "kernal" on my first question (I got *railed* for that!), I was marked for life...
Re:In honor of all the linux newsgroups... (Score:5, Funny)
RTFM!!!
Thanks for the set-up!
Re:In honor of all the linux newsgroups... (Score:2)
Re:In honor of all the linux newsgroups... (Score:1)
Re:In honor of all the linux newsgroups... (Score:2, Insightful)
RTFM means (Score:1)
Yes, I know I can say "fucking" on slashdot, but I prefer not to.
Re:RTFM means (Score:2)
Yes, I know I can say "fucking" on slashdot, but I prefer not to.
Good, because we don't need that shit around here, goddamn it
Re:RTFM means (Score:2)
Perhaps "Read the friendly manual"
or "Read the full manual" or maybe even
"Really tasty fruit mix?!"
It's best to avoid swearing like a fucking trooper.
Re:In honor of all the linux newsgroups... (Score:4, Funny)
Yeah, Microsoft [hardware.no] can. Great knowledge base article.
Re:In honor of all the linux newsgroups... (Score:2)
Despite what you may read anywhere else, RTFM always stood for "Read The Manual" in the past. The F was always implied, never given explicitly. It's only recently that people have started spelling it out for the hard of perceiving (or worse, trying to substitute politically correct alternatives such as "fine"). Sigh. Such is the price of progress :-(
That's easy (Score:4, Funny)
(Now taking bets on whether this first hits -1 Troll or +5 Funny).
Re:That's easy (Score:3, Funny)
Re:That's easy (Score:2, Funny)
Oh wait
Re:That's easy (Score:2)
I love how arrogant programmers tell their users to do things themselves. Yes, I know those programmers are volounteers. No, that doesn't change anything.
Re:That's easy (Score:2)
If somebody yelled, "LINUS! 2.4.15 CAUSES FILE CORRUPTION!!! YOUR IDIOT WAYS F***ED UP MY FILESYSTEM!!!" on the lkml, Linus *should* take the knowledge gained and apply it, rather than griping about how the person reported a major kernel flaw.
The other think is that when you are using public forums (mailing lists, etc), your attitude will scare away other people who could have been very helpful.
Summary: I'm not justifying these people's attitudes, but their crappy attitude doesn't justify yours.
kernel docs? (Score:5, Informative)
cd
wget ftp://ftp.kernel.org/pub/linux/kernel/v2.4/linux-
tar -jxvf linux-2.4.17.tar.bz2
cd linux/Documentation
ls |more
and start reading all the documentation in there. It would probably make a good starting point.
Plus you should read Kernel Traffic and get on the Linux Kernel Mailling List.
Re:kernel docs? (Score:3, Informative)
Linux Device Drivers (Score:5, Informative)
One of the best sources of information is the O'Reilly book on Linux Device Drivers. It contains a lot of good information to get a kernel hacker up and running.
Re:Linux Device Drivers (Score:5, Informative)
Re:Linux Device Drivers (Score:1)
Index of Documentation for People Interested... (Score:5, Informative)
http://jungla.dit.upm.es/~jmseyas/linux/kernel/ha
The info was compiled by Juan-Mariano de Goyeneche after folks on the kernel list asked the same questions time & time again.
Take it straight from the man... Just Do It (Score:5, Insightful)
"Ignore everyone who tells you kernel hacking is hard, special or different. It's a large program, and bug fixing or driver tweaking can be a best starting point. It is however not magic, nor written in a secret language that only deep initiates with beards can read.
Play with it, try things, break it horribly and enjoy yourself. I started on the networking code because it didn't work very well. Everything I knew about TCP/IP I had downloaded the same day I started hacking the net code. My first attempts were not pretty but it was *fun*."
Re:Take it straight from the man... Just Do It (Score:3, Insightful)
Ignore everyone who tells you kernel hacking is hard, special or different. It's a large program, and bug fixing or driver tweaking can be a best starting point. It is however not magic, nor written in a secret language that only deep initiates with beards can read.
That's great advice for everything in the world, actually. There's nothing so difficult that people can't figure it out, unless you listen to guys in Rome with pointy hats.
Re:Take it straight from the man... Just Do It (Score:5, Insightful)
Two cases in point: (the first one isn't a linux story). Someone gave me a joystick for a macintosh. I already possessed a flight simulator for the machine, but much to my chagrin, the joystick didn't have the right drivers. So, I spent the next few weeks writing a device driver (modifying Apple produced code, mostly.)
Second: I owned a DVD drive with broken firmware-- the capacity wasn't reported correctly, and so oms would stop in the middle of the movie. With the (very) extensive help of "Andrew Ebling" (of kernelhacking.org, I was able to solve my problems.
Moral of the story: it helps to have good developer documentation, and example code (provided, for the most part, by the kernel source itself) It also helps to have a reason to code.
Re:Take it straight from the man... Just Do It (Score:5, Informative)
For the past two and a half years, I've been putting some logging code into various parts of the filesystem (ext2, vfs and block device driver.
This has involved creating new syscalls and user level code to transmit logged data to a remote machine via UDP so we won't adversly affect the FS by logging _and_ writing log data to the same FS. Really trivial stuff in retrospect: the hard part was figuring out where to put what and how to do it without crashing (I worked via ssh and if I hosed something, I was out of luck until I could physically return to campus - which could be as long as a week).
My favourite book for this has got to be "Linux Kernel Internals": consice, precise with decent examples (IMHO).
Funny, I worked on module device drivers for a VHDL class _after_ I worked with the kernel directly, so I won't say to you: play with device drivers first to get your feet wet (although, load/unload kernel sure beats the hell out of rebooting). Try doing something simple like changing the messages (printk) within the kernel as a way to gain a small understandinig of what's happening under the hood. And another thing... the source tree I played with was owned by me (so I could cvs, nfs, coda it to my laptop without fear while playing with code (on an OSX PB) on the road
Cheers.
Tools for breaking in (Score:1, Funny)
To protect against modern DNA evidence collection, wrap youself completely in saran wrap except for breathing holes also.
If you get desperate, cut yourself with something sharp lying around the house and sue the owners. Works every time. Good luck on your new career!
--KingPrad
Two fish are in a tank. One says to the other, "I'll drive. You man the guns."
My understanding of Kernel hacking. (Score:1)
1: You need to have a clear goal of what you want to accomplish,
2: Understand the important concept of Operating Systems,
3: Know a bit of basic algorithms.
Then you are good to go.
Alan Cox's Columns (Score:5, Informative)
Their web site [linux-mag.com] should have archives.
Sumner
very easy... 10 steps to kernel coding: (Score:5, Interesting)
2. Learn to code in C.
3. Figure out what YOU want to add to the source.
4. Read the kernel source.
5. Understand what you read.
6. Make changes/additions to the source, per step #3.
7. Test out the changes/additions on your own system.
8. Make it work for you.
9. Send in your contribution.
10. Have it accepted/rejected.
Re:very easy... 10 steps to kernel coding: (Score:4, Funny)
Re:very easy... 10 steps to kernel coding: (Score:3, Funny)
Re:very easy... 10 steps to kernel coding: (Score:3, Funny)
The butler does it, in the library with the scheduler code.
Use a kernel debugger (Score:1, Funny)
Oh wait, you need a kernel debugger...
Nevermind.
start with something simple (Score:1, Funny)
VMware? (Score:5, Informative)
It also means that when you screw things up (if you don't, I'd be surprised; I bet even Alan Cox screws up now and again), you won't lose anything. And don't give me anything about ext3; if you screw up enough in the wrong place, your filesystem is hosed.
Re:VMware? (Score:2)
Kernel Janitors (Score:5, Informative)
Device Drivers (Score:5, Interesting)
Working on it during part of an 8 hour work day, in about 1 month I was able to hack tab support into the s390 vm console driver with nothing more than reading code, searching the net, and using that book. And that was probably a little on the slow side. (see here http://www.eagle7.org/ibmlinux.html [eagle7.org]
And like Alan Cox said in the interview posted to
Re:Device Drivers (Score:3, Interesting)
From there, you can decide to either move into the kernel itself, or stick with device drivers. If you want to practice on a device driver, stick with a simple ISA device. If you can find the hardware, a driver that displays some text on a Monochrome Display Adapter (MDA) is an easy one.
Try this (Score:2, Redundant)
Lurk on this for a little while (be prepared for 200+ messages per day):
http://www.tux.org/lkml/
Watch for to do lists or bug reports to go flying by on the list and start there. Its probably best if you don't try to implement something from scratch your first time out. Start slow and learn the inner workings first.
Writing Kernel Modules (Score:4, Interesting)
It doesn't go into all that much detail, but I found it a good starting point for messing around on my linux machine at home.
Hth =)
Have an special motivation... (Score:2, Informative)
Well I think you just dont go into the kernel to be wandering and looking for inspiration. Think about something specific you want to do and get in to it, you'll allways find you have to mess around with several modules or at least get to know 'Where the hell iz thiz thing going??' ;-).
There are some books at amazon which can helps, I like 'Linux Kernel Internals' by Michael Beck [amazon.com]
Re:Have an special motivation... (Score:1)
Buy crappy hardware.... (Score:5, Informative)
You become very familiar with code that might be close, get to pour over specs that may or may not help, and find a small comunity of others who saved a buck or two.
The best part - when it breaks, you get to keep both peices. When if finally works, ahhhh....
Re:Buy crappy hardware.... (Score:2)
But when you've completely hosed your system after getting a new piece of hardware or tinkering an obscure file, you learn a lot about how your system used to work. A recent example of this happening to me what when I tried to install Mandrake over my old installation. I soon learned of the wide world of bootloaders, and why you should never install LILO twice.
Make your own system call (Score:4, Interesting)
The assignment was to add a system call that would return the number of processes created and killed up to that point. The only difficult thing was to grok the system call table. Please look at this option as a good introduction to the kernel.
Just Do IT.... (Score:4, Interesting)
I also highly suggest the IRC channel
#kernelnewbies
I went there today for the first time looking for Rik van Riel I had some qustions about the rmap 11b patch and Guess what he was there and told me the 11c is coming today , REAL time info from people that really know their stuff.....
Kernel hacking can be fun if youre not in a rush IMHO, doing it against a dealine can be
Im assuming you know huw to extract the source tree and apply a patch , if not start there. Im also assuming you know C if you dont
One last point DO IT OFTEN !, Dont let yourself get rusty, Set a goal, a kernel hack a month, or at least a patch and compile a week if youre not cutting code....
First Rule (Score:1)
Best advice (Score:1, Informative)
Linux Internals, by Moshe Bar.. (Score:5, Informative)
Linux Journal reviewed [linuxjournal.com] it.
- j
Something simple (Score:2, Informative)
That's how I rolled into the business..
(And if you get me those module parameters, I'll big you the best hug you've ever had
Kernel Projects for Linux (Score:2)
Consider VSTa... (Score:2)
If you're decided to go with Linux, though, just pick something and do it. My first kernel driver was a network driver for a NIC (don't remember the model, it was quite a while ago; Don Becker ended up writing a better driver that was accepted into the official kernel, but it was an interesting experience anyhow). If you have access to any interesting hardware that isn't supported (which may be hard to find on x86), writing drivers or porting to new hardware (not whole new architectures, mind you -- that's a bit much) is a good starting place.
Find a small kernel project and tinker (Score:2)
If you're a Windows kernel guy wanting to break into the Linux kernel, thats even easier. Get a job doing a Windows driver for some device, then write a Linux driver for it in your spare time. That's what I did [sourceforge.net].
another starting point (Score:1)
http://www.linuxfromscratch.org
i think it helps understand how the whole system works together.
good luck!
Kernel trashing :) (Score:5, Interesting)
Probably the best place to start is to find some definite itch you want to scratch, and so badly that you won't stop until it's done. For me, that was getting use[ful|less] features into the kernel. As many as I could cram in, without the hard disk exploding. And then fixing all the incompatibilities, as best I could. (Phew!! There are generally a lot!! That's why many of the FOLK patches I produce are unstable.)
What you do next depends on the "itch":
Oh well. (Score:1, Redundant)
The best way to get your hands dirty with any programming project is to get the code, study it for a while, and try to change and improve things. The kernel contains a little bit (or a lot) of everything. Try to fix bugs, improve performance or lower memory usage, if you're skilled at that kind of stuff.
The most important thing to remember is: Don't be intimidated by the kernel. Think of it as a really big program, because that's what it is. The only difference is that it doesn't get loaded by the operating system... it is the operating system!
XINU is golden for learning about internals of OSs (Score:3, Interesting)
it is a very simple OS with multithreading and a bunch of other stuff.
the full source is available and only like 8000 lines or something. it steps you through it in the book, and it is EXTREMELY easy to read.
this was what was used to teach my OS classes in college. you can actually get in and hack the thing away and know what you are changing right from the start.
Comment removed (Score:5, Funny)
Already done (Score:2, Funny)
Re:Find a need.... (Score:2)
This is built in in debug-mode in the Symbian [symbian.com] operating system - if you want. It helps in checking where you've written sloppy code that doesn't handle out-of-memory correctly (about 100% of all code written for desktop-systems actually, but since the Symbian platform is targeting smartphones and communicators it's a lot more important there)
BSD (Score:2, Informative)
Kernelnewbies.org (Score:2, Redundant)
Happy Hacking!
Starter projects... (Score:3, Interesting)
A good starter project is a device driver for something simple. Even easier is if you find a device Net/Free/OpenBSD supports and Linux doesn't, port the driver, that way there is somewhat less code to write.
That could be harder for you then me since Linux has so many drivers now (I started with 386BSD 0.0, so there were maybe 15 supported devices...my friend and I ported the MACH SoundBlaster driver). If all else fails, write a driver for something that already has a driver.
After that you can wonder off into the kernel proper and do some "real" stuff. I did IP traffic shaping, but someone seems to have done that to Linux already...
Re:Starter projects... (Score:2)
In any case, I would think it'd be easier the other way, that Linux has more drivers than BSD. Maybe he should try your suggestion in the opposite direction?
Re:Starter projects... (Score:2)
Simpler with a parallel port (and a bunch of LEDs, like a volume meter)...still there is a problem with debugging both a new driver and new hardware at the same time....
Well, if he wants to be a Linux kernel hacker starting with the BSD kernel isn't going to be the most helpful thing in the world...of corse BSD could use more kernel hackers, and it might be easier to make it "big time" in the less competitave BSD world (except some of the BSD hackers have been doing this for a very long time and are very good at it...like since the early 80s...which is why they can do so much with so many fewer people...)
If he really wants to be a Linux kernel hacker, he'll be better off taking a driver from *BSD, even if it is for a device Linux already has, and porting it. He will learn more about Linux that way then the other way around (I use BSD machines more frequently, so it would benifit me more for him to become a BSD kernel hacker, but...)
Linux Core Kernel Commentary (Score:3, Insightful)
The publisher has a sample chapter [coriolis.com] online (though their HTML looks weird to me; I hope it looks better in your browser). Also, you can read a little more about the book, find links to online reviews, get errata listings, and so on, at its support site [scottmaxwell.org].
Oh, and I, er, happen to know the author. :-)
The Academic Answer (Score:2, Informative)
This might not be the sort of answer you're looking for because it's expensive and will take a few months (at least) but if you haven't already, look at taking a formal course in operating systems. At my university it's a 300 level course and has some heavy pre-reqs but I've seen it offered at other universities with only the requirement of prior programming experience.
The course I took in opiples that make an operating system "go" -- scheduling, physical and virtual memory management, we touched on sockets and pipes (it was a *nix-centric course but we discussed other operating systems including Windows, as well).
If you dont want to spend the time or money on a formal course, I'd at least reccomend the dinosaur book. While lacking in code examples (it doesn't try to show you how to write a *nix-like OS in C, it tries to explain concepts that can be applied to any platform, any language, etc.), it is extremely thorough and makes hard concepts easier to learn. [amazon.com]
While I haven't actually read it (yet), I hear Tanenbaum's Modern Operating Systems [amazon.com] is also excellent.
I was forced to do it (Score:3, Interesting)
We were given a problem to solve: build a kernel patch to any version of the linux kernel that allowed a third party who is writing is driver to have the driver interact with a software emulator instead of real hardware. The end goal was to enable people to write drivers based only on the hardware specs and an emulator. The emulator would instruct the kernel to route certain hardware calls to it. After the driver was written the real hardware could be dropped in place and the driver would not have to be re-written, it could be used out of the box. Essentially it was hardware abstraction without knowing what hardware to abstract before hand.
Personally, if you are just looking at getting into it just find yourself a problem and solve it. It doesn't matter what problem it is, any problem, useful to the world or not. Remember that the end result of this step is to learn, not solve 2.4 VM problems, or to build a better SMP design. (That's the next step!)
Testing... (Score:3, Informative)
Linux desperately needs more serious testers.
LTP - http://ltp.sf.net/
Finding help on this subject is hard... (Score:2, Informative)
a)The elitist attitude of some, who will tell you to go RTFM. And unless you are willing to write code for a really old kernel, you won't find much documentation. And even so, the little free documentation you will find, is not that helpful for newbie kernel hackers (and I don't mean to piss on the efforts of those who have written docs, but they're complex to digest for real newbies).
b)The recipe-minded newbie. Let's face it, you won't find a connect-a-b-and-c-shake-bake-and-wham!-You-have-a
My experience: I was an absolute newbie to kernel programming, so I started reading the code for the tty driver on kernel 2.4.0, which seems to me is one of the simpler parts. After a lot of reading, I wrote my own module (it was just for fun, so don't think it was anything useful...) as a simple device you could write data to, then read it back. Try it on a machine you don't mind screwing up, though, because you will have tons of oopses and kernel panics.
x86 Emulators, etc. (Score:2, Informative)
If you really want to get gritty on the emulation level, I highly recommend Bochs [sourceforge.net]. It's a fully functional x86 emulator, and since it's open source, it comes with some nifty options, and the source code is on hand if you really need to get tricky.
I think the key to working efficiently with an x86 emulator/virtualizer is having a significant amount of RAM, and a RAM disk to mount your virtual drives on. Since RAM is so cheap these days, there's no excuse not to have at least a gig of it in a development box. It makes rebooting the virtual machine (which happens a lot) a bearable process.
If you need to work with hardware, you can build yourself a test platform for around $300 now, including a cheap monitor - unless you need exotic hardware.
My experience kernel hacking is in on the VFS level, inserting and modifying a few core routines to report through a
The kernel is complex, but so is any major piece of software. Thankfully, lots of bits in the kernel are well engineered and compartmentalized, so chances are you won't have to worry about screwing up the TCP stack if you're in the midst of inode.c
have fun!
Do as I did (Score:4, Insightful)
This taught me a lot about lkml politics, which is probably the first skill (and some larrikins would say, the only skill you need) you must master to be a successful long term kernel hacker. First lkml hint: don't slag off anyone. Don't piss off a few people in the know until you get to know them, and then...
Then, don't talk - do. Respect is directly based upon your skills with patches, and their acceptance rate.
Patch submission. Follow the standard guidelines (found elsewhere), but know now that Linus sucks at code control. The mainline kernel development process is slow, prone to serious lossage, allows regression, and is irreparably harmed by Linus' refusal to adopt modern code control practices. So when you submit a patch, don't worry if it's not accepted. Every time the kernel is revved, re-do your patch and re-submit. It'll eventually be accepted, particularly if it helps the kernel boot. For example, it took nearly a month of my submitting a two line patch to allow the alpha to boot before it was accepted into mainline 2.4.0pre development. That's why I ditched Linux for a while - dickheads in charge. All the *BSDs have better kernel development practices, and their bleeding edge kernels are far more stable than any stable Linux kernel. However, for various reasons, I get attracted back to Linux on a regular basis, like a fly to a pus-filled boil.
Anyway, the things that need desperate attention are:
the kernel janitor project (clean out the cruft!)
the linux kernel testing project
These are far more important than any single feature you might want to add, and in particular the kernel janitor project will help you get familiarized with the kernel the quickest.
http://sourceforge.net/projects/ltp/
http://sourceforge.net/projects/kernel-janitor/
Major stumbling block: debugging (Score:3, Informative)
Let me say that, at least for me, this was not like debugging any of the userspace programs that I had done before. If you're like me, when your program crashes, you first up gdb, load the core, and backtrace/step from there. First of all, there's no core dump. In this case I didn't even have the luxury of an oops readout; as I would find out later this particular bug was locking the computer even before the kernel could flush its output buffers and print to the screen.
So I had to start meticulously reconstructing the function call stack using printk(). It took me awhile before I figured out why none of these were getting printed (for the reason I just mentioned.) So that didn't work either.
I searched high and low but never did find a way to debug the kernel that was as easy as using gdb to debug a userspace program, and that's not saying much. No stepping, no backtraces, nada. The "bug" in my particular driver consisted of a single offending line which wrote an 8-bit register and was not to spec. I would have never ferreted it out if I hadn't "stumbled" across the NDA'd specs myself.
Anyways, moral of the story: kernel debugging sucks for really hard bugs. If anyone knows of better tools to use kindly inform me of them.
HOWTO at http://www.kernelhacking.org (Score:3, Informative)
Start with the MBR... (Score:2, Informative)
That's how I started on the FreeBSD kernel and the Linux kernel.
Sure at the first there's some dependencies - and you are sent on a journey through about 20 H files just to find one #define ition, and to know A you need to know B, which requires C, but it worked for me.
--jq
Embedded Systems and Linux... on a Sega Dreamcast (Score:2)
You'll have linux up and running on the thing in no time, and you'll be able to play around with writing device drivers and fixing kernel scheduler bugs and stuff. All on the SH4 processor, which is much simpler than the x86 you're probably using.
Cryptnotic
Before you dive in, read this!!!! (Score:5, Funny)
Ok, now you can go back to read all these good advices that other
Dual keyboards with seperate keyboard mappings! (Score:5, Interesting)
When I had time, I went and fixed the old keyboard, and rearranged the keys as a Devorak keyboard while I was at it. Unfortunately, the USB-PS/2 dongle that came with my IBM keyboard doesn't work with my Dell PS2 keyboard. However, I currently have the IBM keyboard hooked up to my USB port and my old Dell keyboard (with rearranged keys) as my PS/2 keyboard.
Luckily, keybdev.c (both the one in drivers/input and the one in drivers/usb) is astonishingly short. There's all of about 5 functions in there and most of the complexity is hidden in other modules.
The USB keyboard driver interfaces the PS/2 subsystem IIRC (don't know where I read this, maybe the hid.c documentation on linux-usb [usb-linux.org]) so you can't have seperate keyboard mappings, unless you munge the keycodes inside the USBdriver. As long as you don't lock up your USB keyboard driver or have a buffer overun, you should always be able to restart.
I have LILO (GRUB, actually) setup to boot me into either a 2.2.20 kernel or a 2.4.17 kernel. That way, I can ensure that my hacked module won't be loaded by hotplug if I screw it up.
The Steps I took /usr/src/linux (after untarring the 2.4.17 source) and changed the line near the to from "EXTRAVERSION = " to "EXTRAVERSION = -maxmodular"
this changes the name of the kernel from vmlinuz-2.4.17 to vmlinuz-2.4.17-maxmodular and
makesa seperate directory in /lib/modules for your hacked modules. (I called it maxmodular because I even made the "misc binary support", "a.out binary support" and "floppy drive support" as modules.) Potential Gottcha: IDE support is no enabled by default, and comes after the IDE-parport questions in the config menu, so I must have recompiled 10 times trying to figure out why it couldn't mount the root partition.
Downloads I downloaded the 2.4.17 source code and used apt-get to install kernel-package (makes Debian kernel packages, so your nightly apt-get upgrades won't destroy your work).
Renaming I went into
Snooping arroundI poked around the drivers/usb/ kernel source and documentation some to try and figure out what needed to be hacked. I incorreclty identified drivers/usb/keybdev.c and after none of my printk's worked, I tried drivers/input/keybdev.c (this does not affect the PS/2 keyboard).
Printk() is your friend. Add printk()s (printk() works just like printf(). Make sure to do your kernel module insertion from a non-X virtual terminal to minimize the time it takes prints to get to you in the case of an impending crash.) to the beginning of every function in the driver, letting you know that it's being called (and optionally the arguments). Then recompile and load your module. This gives you a feel for how the driver works and confirms that you have the right driver.
Trim prink()s to only print out the information you need. In my case, I got rid of the printks from everything but the keyboard event handling function and the emulate_raw function kalled by the event handler. I printed out every keycode that was pressed (but not it's release) so that I could write down the keycode for each key I needed to remap. (And some of the neat colorful buttons IBM added above the funtion keys. I later used these to turn on and off the devorak remapping and turn on and off the printks in my module.
After that, what you do is pretty specific to your module. For keyboards, they send a 16-number, called a scancode that is one of the arguments to the keyboard event hadler function. All of the normal keys have scancodes less than 256, so I just made an unsigned char[256] usb_key_remap_table and did something like
if (code < 256 && code >= 0) {code = usb_key_remap_table[code];}
The more astute amoung you will remeber that I'm only remapping the USB keyboard, which is my good keyboard and therefore unmodified. Oh well, I figure having the incorrect letters written on the keys discourages me from looking down.
Anyway, the USB subsystem seems very readable for the higher level drvers and USB keeps getting more and more devices, so I'd recomed starting with a USB subsystem... too bad RadioShack is out of USB cue:cats :-D
Article on this in online Linux Journal (Score:2, Informative)
I can't believe nobody mentioned MINIX! (Score:2)
MINUX was never designed as a real-world system, although it did inspire at least one person, namely Linus Torvalds, to write one...
-p.
Be adventurous (Score:2, Insightful)
I started programming in the linux kernel many years ago. I think the thing that helped me the most is that at first I just stuck to one thing. I didn't try to get it all at once. Kernels are very large, and there are a few tricks to kernel programming that aren't as intuitive as applications programming. After playing around in the TCP/IP stack I just branched out a bit. After a while whenever I encountered some new routines or structure, I tried to read every bit of code involved with it.
Some years later I decided to switch to *BSD. I have found their source to be much cleaner and their debugging tools are far more useful for me. After I felt comfortable enough with BSD I started contributing code back. At first small things, and then gradually larger projects. Now I do custom FreeBSD kernel code for a living. I do everything from new file systems to device drivers and custom TCP/IP code. I enjoy it much more than user space programming.. I always joke that I did it all to get away from getopt(3) though.
There are a variety of books you can read on the topic. Don't restrict yourself to linux books, please. Learn that there is more than one way to solve a problem. I'll list some of my favorite kernel books here:
"The Design and Implementation of the 4.4BSD Operating System"
"UNIX Internals: New Frontiers"
"Solaris Internals"
"UNIX Systems for Modern Architectures: Symmetric Multiprocessing and Caching for Kernel Programmers"
After you get a rough idea of how the kernel works, the only way to really learn it is to read code and research papers.
Good luck.
which kernel? (Score:2)
Gearheads section of Linux Mag (Score:2)
http://www.linux-mag.com/depts/gear.html
different kinds of "nerds" (Score:2, Offtopic)
I think slashdot is particularly well suited to "shepherding naive kernel-hacker wannabees," simply for the fact that each of us brings unique viewpoints to each subject. (For instance, I've never even seen the kernel code for Linux, and yet I'm responding to this post.
Re:different kinds of "nerds" (Score:1)
Re:different kinds of "nerds" (Score:5, Funny)
That is true, but in the spirit of open source, we just borrow somebody else's car.
Re:different kinds of "nerds" (Score:1)
now that is "open source"
Re:Is /. becoming the champion fighter of the newb (Score:1)
Re:Is /. becoming the champion fighter of the newb (Score:1, Insightful)
Re:Is /. becoming the champion fighter of the newb (Score:1)
Re:Is /. becoming the champion fighter of the newb (Score:1)
Umm, the "average /. reader" uses Windows. Of the Linux users, I'd guess 1-2% make any contribution to the free software codebase. There probably aren't more than 10 or 20 "kernel hackers" among the posters.
C'mon -- at this writing there are 33 comments at or above zero, not one of which is offering any personal experience with kernel hacking. At least it's not yet another qquestion that would do better as an Ask Google.
Re:Sorry dude, but ... (Score:4, Funny)
dude, don't take the bait! he's just trying to get someone to write a driver for his mp3 player.
Re:Sorry dude, but ... (Score:4, Funny)