Skip to content

Commit

Permalink
eudyptula
Browse files Browse the repository at this point in the history
  • Loading branch information
rscampos committed Sep 27, 2015
0 parents commit 28de53e
Show file tree
Hide file tree
Showing 24 changed files with 964 additions and 0 deletions.
9 changes: 9 additions & 0 deletions task01/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ifneq ($(KERNELRELEASE),)
obj-m := task01.o
else
KDIR ?= /lib/modules/`uname -r`/build

default:
$(MAKE) -C $(KDIR) M=$$PWD

endif
38 changes: 38 additions & 0 deletions task01/task 01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
This is Task 01 of the Eudyptula Challenge
------------------------------------------

Write a Linux kernel module, and stand-alone Makefile, that when loaded
prints to the kernel debug log level, "Hello World!" Be sure to make
the module unloadable as well.

The Makefile should build the kernel module against the source for the
currently running kernel, or, use an environment variable to specify
what kernel tree to build it against.

Please show proof of this module being built, and running, in your
kernel. What this proof is is up to you. I'm sure you can come up with
something. Also be sure to send the kernel module you wrote, along with
the Makefile you created to build the module.

Remember to use your ID assigned in the Subject: line when responding to
this task, so that I can figure out who to attribute it to. You can
just respond to the task with the answers and all should be fine.

If you forgot, your id is "4f92b3aee379". But of course you have not
forgotten that yet, you are better than that.


Some points
------------------------------------------
- Write a Linux Kernel Module (LKM) which prints “Hello World!” to the kernel debug log (when loaded)
- Stand-alone Makefile
- Make the module unloadable as well
- Makefile - make to the current running kernel.
- Send the LKM and the Makefile
- Put "4f92b3aee379" in the subject or just respond the task

Reference
------------------------------------------
http://www.acm.uiuc.edu/sigops/lkm_tut/pratap-lkm.txt
http://www.thegeekstuff.com/2013/07/write-linux-kernel-module/
https://www.kernel.org/doc/Documentation/kbuild/
25 changes: 25 additions & 0 deletions task01/task01.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This lkm is modified from:
* http://www.tldp.org/LDP/lkmpg/2.6/html/x121.html
*/

/* linux/module.h - for the module
* linux/kernel.h - macros for printk
*/
#include <linux/module.h>
#include <linux/kernel.h>

/* Entry point of the lkm.
* This is executed as soon as the lkm is loaded.
* Priority of printk - from linux/kernel.h
* http://web.cecs.pdx.edu/~jrb/ui/linux/driver4.txt
*/
int init_module(void)
{
printk(KERN_DEBUG "Hello World!\n");
}
/* Exit point of the lkm.
* This is executed as soon as the lkm is unloaded and undo
* everthing did in init_module.
*/
void cleanup_module(void)
{}
20 changes: 20 additions & 0 deletions task02/references.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'make menuconfig' - menu para configuração do .config antes de compilar o kernel.
apt-get install libncurses5 ncurses (ou libncurses5-dev)

Sobre algumas configurações do kernel
http://www.tldp.org/HOWTO/SCSI-2.4-HOWTO/kconfig.html

Instalação completa []

0) git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
1) make localmodconfig - configurações padrão e compila baseado nelas
2) make
3) make modules
4) make modules_install
5) make install

Referencias:
[1] http://www.wikihow.com/Compile-the-Linux-Kernel
[2] http://www.cyberciti.biz/tips/compiling-linux-kernel-26.html
[3] http://www.thegeekstuff.com/2013/06/compile-linux-kernel/
[4] http://kernelnewbies.org/KernelBuild
41 changes: 41 additions & 0 deletions task02/response_task02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Hello, this is the proof...

Linux mint using real machines

==[ OLD LINUX KERNEL

user-pc ~ # uname -a
Linux user-pc 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

user-pc ~ # dmesg
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.11.0-12-generic (buildd@allspice) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu7) ) #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 (Ubuntu 3.11.0-12.19-generic 3.11.3)

user-pc ~ # ls -la /boot/ | grep `uname -r`
-rw-r--r-- 1 root root 1005798 Out 9 2013 abi-3.11.0-12-generic
-rw-r--r-- 1 root root 163251 Out 9 2013 config-3.11.0-12-generic
-rw-r--r-- 1 root root 26635969 Jan 21 10:20 initrd.img-3.11.0-12-generic
-rw------- 1 root root 3285893 Out 9 2013 System.map-3.11.0-12-generic
-rw-r--r-- 1 root root 5600016 Jan 20 11:51 vmlinuz-3.11.0-12-generic

==[ NEW LINUX KERNEL

The kernel downloaded from kernel.org git, downloaded in July 10th.

user-pc user # uname -a
Linux user-pc 3.16.0-rc4-00042-g4f440cd-dirty #2 SMP Thu Jul 10 13:07:00 BRT 2014 x86_64 x86_64 x86_64 GNU/Linux

user-pc ~ # dmesg
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.16.0-rc4-00042-g4f440cd-dirty (root@user-pc) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9) ) #2 SMP Thu Jul 10 13:07:00 BRT 2014

user-pc user # ls -la /boot/ | grep `uname -r`
-rw-r--r-- 1 root root 110645 Jul 10 13:09 config-3.16.0-rc4-00042-g4f440cd-dirty
-rw-r--r-- 1 root root 20405424 Jul 10 13:09 initrd.img-3.16.0-rc4-00042-g4f440cd-dirty
-rw-r--r-- 1 root root 3397420 Jul 10 13:09 System.map-3.16.0-rc4-00042-g4f440cd-dirty
-rw-r--r-- 1 root root 5774704 Jul 10 13:09 vmlinuz-3.16.0-rc4-00042-g4f440cd-dirty

60 changes: 60 additions & 0 deletions task02/task02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
This is Task 02 of the Eudyptula Challenge
------------------------------------------

Now that you have written your first kernel module, it's time to take
off the training wheels and move on to building a custom kernel. No
more distro kernels for you. For this task you must run your own
kernel. And use git! Exciting, isn't it? No? Oh, ok...

The tasks for this round are:
- Download Linus's latest git tree from git.kernel.org (you have to
figure out which one is his. It's not that hard, just remember what
his last name is and you should be fine.)
- Build it, install it, and boot it. You can use whatever kernel
configuration options you wish to use, but you must enable
CONFIG_LOCALVERSION_AUTO=y.
- Show proof of booting this kernel. Bonus points if you do it on a
"real" machine, and not a virtual machine (virtual machines are
acceptable, but come on, real kernel developers don't mess around
with virtual machines, they are too slow. Oh yeah, we aren't real
kernel developers just yet. Well, I'm not anyway, I'm just a
script...) Again, proof of running this kernel is up to you, I'm
sure you can do well.

Hint, you should look into the 'make localmodconfig' option, and base
your kernel configuration on a working distro kernel configuration.
Don't sit there and answer all 1625 different kernel configuration
options by hand, even I, a foolish script, know better than to do that!

After doing this, don't throw away that kernel, git tree, and
configuration file. You'll be using it for later tasks. A working
kernel configuration file is a precious thing, all kernel developers
have one they have grown and tended to over the years. This is the
start of a long journey with yours. Don't discard it like was a broken
umbrella, it deserves better than that.

Remember to use your ID assigned in the subject line when responding to
this task, so that I can figure out who to attribute it to.

If you forgot, your id is "4f92b3aee379". But why do I repeat myself?
Of course you know your id, you made it through the first task just fine
with it.


Some points
------------------------------------------
- Build a custom kernel using Linus's latest git tree from git.kernel.org.
- Build it, install it, and boot it. Use CONFIG_LOCALVERSION_AUTO=y
- If I install in real machine, I'll gain extra points
- Look into the 'make localmodconfig'
- Don't throw away the kernel, it'll be using for later tasks.

Reference
------------------------------------------
http://www.acm.uiuc.edu/sigops/lkm_tut/pratap-lkm.txt
http://www.thegeekstuff.com/2013/07/write-linux-kernel-module/
https://www.kernel.org/doc/Documentation/kbuild/

Compilando kernel com suporte a dpkg
http://www.youtube.com/watch?v=bSS7oJ7n6f0
http://www.youtube.com/watch?v=3Pf9D9hvlb0
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From f60e32cd71c1f3018a42ed3429b16299f1e191b1 Mon Sep 17 00:00:00 2001
From: Raphael Campos <[email protected]>
Date: Tue, 15 Jul 2014 08:10:17 -0300
Subject: [PATCH 1/1] Makefile: Modification for Eudyptula Challenge task03

EXTRAVERSION field modification to show "-eudyptula" in the version
string.

Signed-off-by: Raphael Campos <[email protected]>
---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index f3c543d..28be911 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
VERSION = 3
PATCHLEVEL = 16
SUBLEVEL = 0
-EXTRAVERSION = -rc5
+EXTRAVERSION = -eudyptula
NAME = Shuffling Zombie Juror

# *DOCUMENTATION*
--
1.8.3.2

34 changes: 34 additions & 0 deletions task03/references.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Dar uma olhada rápida nas referências a seguir. Referências obtidas em Documentation/SubmittingPatches

http://www.ozlabs.org/~akpm/stuff/tpp.txt
http://linux.yyz.us/patch-format.html

[url:http://www.linuxchix.org/content/courses/kernel_hacking/lesson9
] - básico sobre patch e diff
Referencia que ensina de forma rápida a usar os comandos 'diff' e 'patch'.

[url:http://linux.koolsolutions.com/2011/02/26/howto-create-and-submit-your-first-linux-kernel-patch/] - sobre git/patch
# git config --add user.name "Raphael Campos"
# git config --add user.email "[email protected]"
# git branch task03 -- cria um novo branch que irá conter as alterações
# git checkout task03 -- muda para este branch
# git branch -- lista para ver se esta no branch correta
... realiza as alterações necessárias ...
# git commit -a
... comentar sobre o patch: linha 1 será o subject, linha em branco, linha 2 será a descrição.
# git diff -- verificar alteração antes de criar o patch
# git format-patch -s -n master..task03 -- criar um patch e salva no ./ baseado nas alterações realizadas.
# scripts/checkpatch.pl 0001-x86-Fix-reboot-problem-on-VersaLogic-Menlow-boards.patch

# make M=drivers/staging/comedi/ -- compilando os arquivos de um dir especifico. No qual o arquivo foi alterado

# git log -- mostra as alterações
# git show -- mostra o patch.
#./scripts/get_maintainer.pl --file drivers/hid/hid-ezkey.c -- mostra os manteners.
# git blame drivers/hid/hid-ezkey.c
# git show f425458e

Referência muito boa sobre o assunto. Tudo sobre patch.
https://www.youtube.com/watch?v=LLBrBBImJt4

Ponto de partida - Documentation/HOWTO
50 changes: 50 additions & 0 deletions task03/response_task03.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Hello, this is the proof...

Linux mint (with kernel from task02) using real machine

==[ OLD LINUX KERNEL

user-pc ~ # uname -a
Linux user-pc 3.16.0-rc4-00042-g4f440cd-dirty #2 SMP Thu Jul 10 13:07:00 BRT 2014 x86_64 x86_64 x86_64 GNU/Linux

user-pc ~ # dmesg
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.16.0-rc4-00042-g4f440cd-dirty (root@user-pc) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9) ) #2 SMP Thu Jul 10 13:07:00 BRT 2014

user-pc ~ # ls -la /boot/ | grep `uname -r`
-rw-r--r-- 1 root root 3397420 Jul 10 13:09 System.map-3.16.0-rc4-00042-g4f440cd-dirty
-rw-r--r-- 1 root root 110645 Jul 10 13:09 config-3.16.0-rc4-00042-g4f440cd-dirty
-rw-r--r-- 1 root root 20405424 Jul 10 13:09 initrd.img-3.16.0-rc4-00042-g4f440cd-dirty
-rw-r--r-- 1 root root 5774704 Jul 10 13:09 vmlinuz-3.16.0-rc4-00042-g4f440cd-dirty

==[ NEW LINUX KERNEL

The kernel downloaded from kernel.org git, downloaded in July 15th.

user-pc user # uname -a
Linux user-pc 3.16.0-eudyptula-dirty #2 SMP Tue Jul 15 08:51:07 BRT 2014 x86_64 x86_64 x86_64 GNU/Linux

user-pc ~ # dmesg
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 3.16.0-eudyptula-dirty (root@user-pc) (gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9) ) #2 SMP Tue Jul 15 08:51:07 BRT 2014

user-pc linux # ls -al /boot/ | grep `uname -r`
-rw-r--r-- 1 root root 110710 Jul 15 08:54 config-3.16.0-eudyptula-dirty
-rw-r--r-- 1 root root 20406948 Jul 15 08:55 initrd.img-3.16.0-eudyptula-dirty
-rw-r--r-- 1 root root 3397539 Jul 15 08:54 System.map-3.16.0-eudyptula-dirty
-rw-r--r-- 1 root root 5774160 Jul 15 08:54 vmlinuz-3.16.0-eudyptula-dirty


==[ PATCH

The patch was build using git, as show below:

user-pc user # git branch task03
user-pc user # git checkout task03
... Makefile changes ...
user-pc user # git commit -a
user-pc user # git format-patch -s -n master..task03
36 changes: 36 additions & 0 deletions task03/task03.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is Task 03 of the Eudyptula Challenge
------------------------------------------

Now that you have your custom kernel up and running, it's time to modify
it!

The tasks for this round are:
- Take the kernel git tree from Task 02 and change the Makefile to
modify the EXTRAVERSION field. Do this in a way that the
running kernel (after modifying the Makefile, rebuilding, and
rebooting) has the characters "-eudyptula" in the version string.
- Show proof of booting this kernel. Extra cookies when you provide
creative examples, especially if done in interpretive dance at your
local pub.
- Send a patch that shows the Makefile modified. Do this in a manner
that would be acceptable for merging in the kernel source tree.
(Hint, read the file Documentation/SubmittingPatches and follow the
steps there.)

Remember to use your ID assigned in the subject line when responding to
this task, so that I can figure out who to attribute it to.

If you forgot, your id is "4f92b3aee379". Surely I don't need to keep
saying this right? I know, _you_ wouldn't forget, but someone else, of
course they would, so I'll just leave it here for those "others."

Some points
------------------------------------------
- Take the kernel git tree from Task 02
- Change the Makefile to modify the EXTRAVERSION field (-eudyptula)
- Show a proof of booting the kernel
- Extra cookies when you provide creative examples, especially if done in interpretive dance at your local pub. (?!)
- Send a patch that shows the Makefile modified (read Documentation/SubmittingPatches)

Reference
------------------------------------------
40 changes: 40 additions & 0 deletions task04/coding_style.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/slab.h>

int do_work(int *my_int, int retval)
{
int x;
int y = *my_int;
int z;

for (x = 0; x < *my_int; ++x)
udelay(10);

if (y < 10)
/* That was a long sleep, tell userspace about it */
pr_warn("We slept a long time!");

z = x * y;

return z;
}

int my_init(void)
{
int x = 10;

x = do_work(&x, x);

return x;
}

void my_exit(void)
{
return 0;
}

module_init(my_init);
module_exit(my_exit);

Loading

0 comments on commit 28de53e

Please sign in to comment.