which "arch" subdirectory to use?

Hey, I’m open to any and all ideas. It seems so strange that I’m getting a seg fault in the client code, though…that does make me suspicious of the compiler version vs. the headers, etc.

How do people go about debugging kernel code, anyway? I gather that gdb isn’t much of an option. Do we just litter the code with printk statements like we did when we were freshmen in college?

mz

Naw, theres a special way to compile a kernel that will allow it to be run
as though it's just another executable. This way, you can run the kernel on
top of the Linux you're already running in order to debug it.

You need a kernel aware JTAG debugger like Lauterbach. This will allow you to debug u-boot, kernel code, including all the drivers as they are loaded, etc. It is expensive, but it is the gold standard for kernel/driver debugging.

TI have Code Composer Studio that will do some debugging of the kernel using a blackhawk JTAG adapter, but CCSV7 has several limitations as they no longer support kernel aware debugging (dropped after CCSV4). It is somewhat helpful and a lot less expensive ($99) than Lauterbach.

I hope this helps.

Regards,
John

Hi, John - thanks for the reply. I don’t believe, however, that I’ll need to use JTAG, at least not for this specific example.

Here’s my current thinking: I already have a cross-development platform (Qt Creator) set up for the BBB, so I’m going to try to use it to build kernel modules. I know that at a minimum, I’ll need the kernel header files, which I can get from RCN’s repository. I just have to figure out where to put them on my host so I don’t overwrite anything (my host isn’t the same Debian version as my BBB).

I welcome any feedback on this idea.

The way I work is to have the BBB mount rootfs over NFS which resides on my desktop. When I create a Kernel Module, I do the following:

  1. I clone Robert’s kernel repo

  2. I build the kernel

  3. I add my kernel module code

  4. I rebuild the kernel

  5. I modify Robert’s deploy script to copy the kernel/kernel modules to my NFS share directory

  6. I run modprobe

  7. If there is a problem; modprobe -r

  8. Modify my code an goto step 4

  9. Once everything is working, I create a patch and add it to the patches folder and modify Robert’s build script.

By using Robert’s build scripts, you don’t have to worry about kernel headers, compiler versions, etc. It all just works.

No need for any special tools, just use your favorite editor. I tend to use Eclipse as I can index the entire kernel source code so I can just click on any function and it will switch to that function. left arrow returns to your previous location. This link will show you how to make Eclipse work.

https://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source

I hope this helps.

Regards,
John

Thanks for all the details, John. I’ll look into that approach when I get around to more serious kernel programming. Right now, I just want to figure out why this example isn’t working for me.

I need to download Robert’s header files for the BBB to my host. If I just add a file to sources.list.d, and run apt, will this work, or am I at risk of overwriting my host’s files?

I don’t do this, but I believe you can do this using Multiarch:

https://wiki.debian.org/Multiarch/HOWTO

Now you can install the headers using dpkg -i

I have copied Robert as he is the best person to answer your question.

Regards,
John

One thing I forgot, you would use

dpkg —add-architecture armhf

as Robert builds with Hardware Floating point.

Regards,
John

Hi, John - thanks for all the information. I’ve been reviewing each item in your list to better understand what I’ll be doing, and more importantly, why. I’m curious why you’d clone Robert’s repository, though, instead of just checking out the latest (stable) copy. Do you really need all the versions/history/etc that comes with a complete clone?

Also, about how much space does that clone need? I’m running on limited resources (my Debian build boots off of a 64GB SSD).

Thanks again.

To modify the kernel, you always have to clone one of Robert’s repos, either the ti-linux-kernel or the bb-kernel. The repo allows you to update the kernel as Robert adds fixes/patches. Using GIT, you can see what was changed (gitk) and by whom (git blame ). If you are looking for how a function was used or how it is defined (git grep ). GIT is your friend and I advise you to take the time to learn how to use this tool. I have my own development branch and then I merge in changes added by Robert from time to time.

Regarding your second question, the cloned repo is on your development machine, not on your BB sdcard. When you finish building your kernel, you copy the kernel/modules, etc to your sdcard or nfs share. During development, I include debug symbols, so my kernel is larger than normal.

One other tool you should learn to use is ftrace. This allows you to trace/log function calls in the kernel/modules. This is very handy when learning how other device drivers work.

Regards,
John

OK, I was really hoping to figure this out for myself, but…how do I clone the bb-kernel repository? Here’s what I tried:

  • went onto GitHub
  • found the URL for Robert’s bb-kernel repository
  • copied the URL into a “git clone” command and executed it

All I get is a .git subdirector and a few small text files: .gitignore, LICENSE, and README.md. So, I gather that I’m not in the right place…can someone please tell me where I went wrong?

Well there's 35 branchse:

https://github.com/RobertCNelson/bb-kernel/branches/all

so you pick the one you want to use

git checkout origin/<branch> -b tmp

Regards,

Ah, OK…I missed the “branches” button on the web page. A few follow-up questions, please:

  • I neglected to mention that I’m looking for the source code; am I in the correct location?
  • it seems that branches are maintained for each version and patch level. Do I need to concern myself with finding the right stuff for the sublevel as well?
  • my BBB is currently running 4.4.48. In my brief browsing, I didn’t find mention of this particular version. Would it be advisable to move up to a new version as long as I’m going through this exercise?

Thanks.

Ah, OK...I missed the "branches" button on the web page. A few follow-up
questions, please:

- I neglected to mention that I'm looking for the source code; am I in the
correct location?

Yes/No

- it seems that branches are maintained for each version and patch level. Do
I need to concern myself with finding the right stuff for the sublevel as
well?

Yeap

- my BBB is currently running 4.4.48. In my brief browsing, I didn't find
mention of this particular version. Would it be advisable to move up to a
new version as long as I'm going through this exercise?

Actually you are running "4.4.48-ti-r88" so you are in the wrong git project..

Just use yakbuild:

git clone GitHub - RobertCNelson/yakbuild: Yet Another Kernel BUILD script
cd ./yakbuild/
cp recipe.sh.sample recipe.sh

open recipe.sh and edit:

kernel_tag="4.4.68-ti-r106" -> kernel_tag="4.4.48-ti-r88"

then run:

./build_kernel.sh

Regards,

I see Robert has answered all your question. Here are some suggestions that might help once you complete the first build.

After you build, you will find the kernel on the yakbuild/KERNEL folder. This is where you edit your code. Do not “build_kernel.sh” again as this will overwrite any code you edited. Use yakbuild/tools/rebuild.sh to rebuild the kernel with your changes. The output of the build is placed in the yakbuild/deploy folder. You will find an yakbuild/deploy/update.sh which you can customize to copy the files to your NFS share or use yakbuild/deploy/updateSD.sh to update your BBB SDcard.

I recommend that you place your kernel module/driver under the yakbuild/KERNEL/drivers folder. If you create a custom folder, then you need to edit the Makefile and Kconfig files in the drivers folder. Your custom folder must also have a Makefile and Kconfig file. Look at other folders in the drivers folders for examples.

Alternatively, you could also use the yakbuild/KERNEL/samples folder for your source code.

Regards,
John

Hi, John -

I was indeed able to successfully execute Robert’s instructions, so I know how to make the kernel. Useful information for when the time comes for it. I will also note your advice above. Very much appreciated.

This thread has drifted a bit, and so I think I’ll close it out. I’ll pursue my original question (how to cross build and debug an LKM) in another forum, since I think I’ve bugged everyone here enough for now.

Thanks to all who participated in this thread…

Well the purpose of my advise what to show you how to cross compile kernel modules without having to worry about kernel version, kernel headers and compiler versions. By using Robert’s build tool, he does all that for you. Better still, if you use source indexing with Eclipse, you get function code completion and can jump to those function using "ctrl left mouse click” and “alt left arrow” to return to your code. There are also lots of example in the Kernel/samples folder.

Regards,
John

Hi John -

I understand, and your advice was excellent, and much appreciated. I think that part of the reason I’m spinning my wheels is that I don’t know enough about what I’m doing to even properly word the questions. In this particular example, despite everyone’s help, I’m no closer to solving the original problem than I was at the outset. It’s my lack of knowledge in this area that’s the culprit, not the assistance I’m getting.

In any event, it’s pretty clear that this isn’t a BBB problem. I’ve tried running it on my host, and the test program blows up on the write statement. So, I’m going to quit pestering the people here about a problem that’s proven to be somewhat off-topic.

Thanks again.

mz,

You know what I’d do in your shoes ? I’d just setup a development sdcard for your bb, and compile modules natively. on the bb. Much simpler, no hassle, no pain in the butt. Compiling a kernel on a bb may take a few days, but a kernel module should not take very long.

Another thing you should be aware of when it comes to DR Molloy’s book. Is that the information is dated, and not how one would go about doing things with current versions of Debian. For instance, with Jessie there are some mechanisms built in now. That allow for much easier cross compiling. With that said, asking anyone on the group here to help you with that process, would be asking too much. But suffice it to say, multi arch on Debian is much better than with previous versions of debian. The best way to start learning with that in my mind is to create, and use an x64 debian virtual machine from something like virtual box. Then just start experimenting with instructions off the web. Until you find a process that works.

Anyway, you just start getting your hands dirty, and experimenting. Then things should eventually start working out. google “cross compile kernel module deb” Then just start reading guides that only talk about armhf, and Debian Jessie. Things to be aware of, is that you’ll need to apt-get install , and you’ll need to be able to compile those sources from your version of gcc ( gcc --version). The only additional package you’ll need to install on that image aside from the kernel headers is build-essential. Unless you need something specific like libusb-dev for USB development, or the like.

Then later, once you understand native module development much better, you’ll be able to apply that information towards cross compiling much easier. Just be aware, this is not an overnight sort of situation. It could take years to grasp, but if you apply yourself, it’ll probably take a lot less time.