Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adam8157 committed Apr 4, 2012
0 parents commit 783fed8
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
busybox
linux
kernel.img
rootfs.img
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
run: kernel.img rootfs.img
qemu-system-x86_64 -kernel kernel.img -append "root=/dev/ram rdinit=/sbin/init" -initrd rootfs.img

debug: kernel.img rootfs.img
qemu-system-x86_64 -kernel kernel.img -append "root=/dev/ram rdinit=/sbin/init kgdboc=ttyS0,115200 kgdbwait" -initrd rootfs.img -serial tcp::1234,server &
gdb linux/vmlinux

install: linux/.config busybox/.config
./install

kernel.img: linux/arch/x86/boot/bzImage
make -C linux bzImage -j4
cp linux/arch/x86/boot/bzImage kernel.img

rootfs.img: busybox/_install/bin/busybox
make -C busybox install -j4
./mkrootfs

.PHONY: run debug install
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# kernel-dev

Setup the kernel developing environment automatically.

## requirements

* gdb
* gcc
* make
* QEMU

## install

make install

## run testing system

make run

## run debugging system

make debug

## warning

Before everything, do read and get through each file.
21 changes: 21 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

LINUX=linux
BUSYBOX=busybox

[ -d $LINUX ] || git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git $LINUX

make -C $LINUX defconfig

${LINUX}/scripts/config --file ${LINUX}/.config --enable CONFIG_EXPERIMENTAL
${LINUX}/scripts/config --file ${LINUX}/.config --enable CONFIG_DEBUG_INFO
${LINUX}/scripts/config --file ${LINUX}/.config --enable CONFIG_KGDB
${LINUX}/scripts/config --file ${LINUX}/.config --enable CONFIG_KGDB_SERIAL_CONSOLE
${LINUX}/scripts/config --file ${LINUX}/.config --disable CONFIG_DEBUG_RODATA

[ -d $BUSYBOX ] || git://git.busybox.net/busybox $BUSYBOX

make -C $BUSYBOX defconfig

${LINUX}/scripts/config --file ${BUSYBOX}/.config --enable CONFIG_STATIC
${LINUX}/scripts/config --file ${BUSYBOX}/.config --enable CONFIG_INSTALL_NO_USR
48 changes: 48 additions & 0 deletions mkrootfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

CWD=$(pwd)
BUSYBOX=busybox

TMPDIR=$(mktemp -d .tmp.XXXXXXXX)

cd $TMPDIR

mkdir -p dev etc/init.d mnt proc root sys tmp
chmod a+rwxt tmp

cp -rf ${CWD}/${BUSYBOX}/_install/* ./

cat << EOF > etc/profile
echo
echo "Let's hack the kernel!"
echo
EOF

cat << EOF > etc/fstab
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
EOF

cat << EOF > etc/inittab
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
tty2::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
EOF

cat << EOF > etc/init.d/rcS
#!bin/sh
/bin/mount -a
/sbin/mdev -s
EOF

chmod 755 etc/init.d/rcS

find ./ | cpio -o -H newc | gzip > $CWD/rootfs.img

cd $CWD

rm -rf $TMPDIR

exit 0

0 comments on commit 783fed8

Please sign in to comment.