Geeks With Blogs
Kate Moss' Open Space

The Share Source Program in Windows CE provides many modules in %_WINCEROOT%\Private\ tree, and the kernel is one of them! Although it is not full source of kernel but good enough for tracing and even up to tweak the kernel.
Tracing the kernel and see how it works is lots of fun, but it is fascinated to modify and verify the change you made.

So first comes first, where is the source of kernel? It's in your %_WINCEROOT%\private\winceos\COREOS\nk\
And next question will be "How do I build it?", Some of you may say just "build -c" there and it should be good.
If you are the owner of kernel and got full source, that is definitely the right answer, but none of them are applied to our case though. So what should I do? Let's dig deeper into the coreos\nk folder, there are a couples of subfolder, CELOG, KDSTUB, KERNEL and etc. KERNEL\ is the main component of kernel.dll, in the other word, most of the modify to kernel is going to happen here. And the good thing is, you could "build -c" in %_WINCEROOT%\private\winceos\COREOS\nk\kernel\ with no error at all. But before doing that, remember to backup eveything you are going to modify, including the source and binaries; remember, this is not something belong to you, and if you didn't restore them back later, it could end up confuse the subsequence QFE updates!

Here is the steps

  1. Backup the source code, I will suggest the whole %_WINCEROOT%\private\winceos\COREOS\nk\
  2. Backup the binaries in common\oak\lib\, and again if you are not sure which files, backup the whole %_WINCEROOT%\common\oak\lib\ is the safest way.
  3. Do whatever modification you want in %_WINCEROOT%\private\winceos\COREOS\nk\kernel\
  4. build -c in %_WINCEROOT%\private\winceos\COREOS\nk\kernel
  5. If everything went well so far, you should get a new nkmain.lib,nkmain.pdb, nkprmain.lib and nkprmain.pdb in
  6. Basically, you just rebuild your new kernel, the rest is to "blddemo clean -q" to have your new kernel SYSGEN'd and include in your OS Image. Or just "set WINCEREL=1" then "sysgen -p common nk nkprof" and "makeimg" if you can't wait another minutes for "blddemo clean -q"

That sounds good, but some of you may not like the idea to alter any code in private folder, and not to mention how annoying to backup/restore files every time. Better idea? Yes, Microsoft provides a tool SYSGEN_CAPTURE ( for detail and usage) to creates Sources files for public drivers that you want to modify and build in your platform directory. In fact, not only public drivers, virtually anything in the %_WINCEROOT%\public\<project name>\cesysgen\makefile can be captured, and of course including kernel. So I am going to introduce a second way to build your own kernel by using SYSGEN_CAPTURE tool.

Again the steps

  1. Create a folder in your BSP for building kernel, says %_TARGETPLATROOT%\SRC\Kernel.
  2. Use "SYSGEN_CAPTURE -p common nk" and then you will get a SOURCES.KERN, you could also "SYSGEN_CAPTURE -p common nkprof" to generate profiler enabled kernel.
  3. rename the SOURCE.KERN to SOURCES and copy one of the sample makefile into your kernel directory. For example the one in PRIVATE\WINCEOS\COREOS\NK\KERNEL\NKNORMAL.
  4. Copy the source files you want to modify from private\winceos\coreos\nk\kernel\ into your kernel directory.
  5. Modifying the SOURCES= macro to the source files you addes in step 4. For example, if you copied the vm.c, it is going to be SOURCES=vm.c
  6. Refer to the private\winceos\COREOS\nk\kernel\ and add macro defines and proper include path in your SOURCES file.
  7. "set WINCEREL=1", "build -c" in your kernel directory and "makeimg", voila!

Here is an example for the MACROS you need to add in x86

Here are the macros for x86


# Machine independent defines



Posted on Friday, April 2, 2010 8:54 AM | Back to top

Comments on this post: Build Your Own CE6 Kernel

# re: Build Your Own CE6 Kernel
Requesting Gravatar...
How do I build my own CE6 user mode coredll?
Left by BK on Aug 09, 2010 8:01 PM

# re: Build Your Own CE6 Kernel
Requesting Gravatar...
You should be able to use the SYSGEN_CAPTURE to create a sources template for coredll (user) or kcoredll (kernel)

SYSGEN_CAPTURE -p common [coredll | kcoredll]

But unlike kernel, most of the source of coredll is not available.
Left by KMOS on Sep 28, 2010 6:41 AM

# re: Build Your Own CE6 Kernel
Requesting Gravatar...
I've tried this using Windows Compact 7. I've managed to copy the Kernel code from the private folder to my BSP folder. I can also build this kernel however any changes I make do not show up in my final image. The nkmain.lib and nkmain.pdb files are not placed in the Common\Oak\Lib folder, but rather in TGTPLATFORMROOT folder... The NK.BIN still links with the old nkmain.lib from the private folder. I've tried modifying the SOURCES folder to specify a custom output folder however my build now fails with the error "don't know how to make nkmain.lib".

How can I make my local copy of the kernel lib be used for linking instead of the one contained in Common\OAK\lib?

Left by SJS on Aug 28, 2014 3:09 AM

Your comment:
 (will show your gravatar)

Copyright © Kate Moss' Open Space | Powered by: | Join free