Monday, June 2, 2008

Build Linux Kernel/Module in Fedora Core 9

# Build Linux Kernel
[ ]# yum install yum-utils
[ ]# yumdownloader --source kernel

# Download Linux Kernel Source RPM
[ ]# yum install kernel-headers

# Install Linux Kernel source and patch files to "/usr/src/redhat/SOURCES/"
[ ]# rpm -ivh kernel-2.6.25.3-18.fc9.src.rpm

# Prepare to build Linux Kernel
[ ]# cd /usr/src/redhat/SPECS
[ ]# rpmbuild -bp --target=i686 kernel.spec
[ ]# cd ../BUILD/kernel-2.6.25/linux-2.6.25.i686/
[ ]# cp configs/kernel-2.6.25.3-i686.config .config

# Edit "EXTRAVERSION" in "/usr/src/redhat/BUILD/kernel-2.6.25/linux-2.6.25.i686/Makefile" file
# (example)
-EXTRAVERSION = .3
+EXTRAVERSION = .3-18.fc9.i686

# Build Linux Kernel
[ ]# make
[ ]# make modules
[ ]# make modules_install
[ ]# make install

# Check "GRUB" configuration file "/etc/grub.conf"
# (example)
+title Fedora (2.6.25.3-18.fc9.i686)
+ root (hd0,1)
+ kernel /vmlinuz-2.6.25.3-18.fc9.i686 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
+ initrd /initrd-2.6.25.3-18.fc9.i686.img

# reboot.

# Check Linux Kernel Version
[ ]# uname -a

# Compile module - via-rhine NIC
(example)
1. via-rhine.c
2. Makefile
============================================================
ifneq ($(KERNELRELEASE),)
obj-m := via-rhine.o

else
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
rm -r -f .tmp_versions *.mod.c .*.cmd *.o *.symvers

endif

clean:
rm -rf via-rhine.ko

============================================================
3. [ ]# make

# Install module
4. [ ]# insmod via-rhine.ko

# Remove module
5. [ ]# rmmod via-rhine

Troubleshot
1Q:
[ ]# insmod via-rhine.ko
insmod: error inserting 'via-rhine.ko': -1 Unknown symbol in module

1A:
1A.1 - Check module dependence
[ ]# modinfo via-rhine.ko
filename: via-rhine.ko
license: GPL
description: VIA Rhine PCI Fast Ethernet driver
author: Donald Becker
srcversion: 8158094F4B64FDC36073DA7
alias: pci:v00001106d00003053sv*sd*bc*sc*i*
alias: pci:v00001106d00003106sv*sd*bc*sc*i*
alias: pci:v00001106d00003065sv*sd*bc*sc*i*
alias: pci:v00001106d00003043sv*sd*bc*sc*i*
depends: mii
vermagic: 2.6.25.3-18.fc9.i686 SMP mod_unload 686 4KSTACKS
parm: max_interrupt_work:VIA Rhine maximum events handled per interrupt (int)
parm: debug:VIA Rhine debug level (0-7) (int)
parm: rx_copybreak:VIA Rhine copy breakpoint for copy-only-tiny-frames (int)
parm: avoid_D3:Avoid power state D3 (work-around for broken BIOSes) (bool)

1A.2 - Check "depends" field for other modules
[ ]# insmod /lib/modules/2.6.25.3-18.fc9.i686/kernel/drivers/net/mii.ko
[ ]# insmod via-rhine.ko

Download Sample Code

Great site: http://www.mjmwired.net/resources/mjm-fedora-f8.html

No comments: