Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hello assignment in skels #11

Merged
merged 3 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/labs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ copy: $(YOCTO_IMAGE)
mkdir $(TEMPDIR)
sudo mount -t ext4 -o loop $(YOCTO_IMAGE) $(TEMPDIR)
find skels -type f \( -name *.ko -or -executable \) | xargs sudo cp --parents -t $(TEMPDIR)/home/root || true
find skels -type d \( -name checker \) | xargs sudo cp -r --parents -t $(TEMPDIR)/home/root || true
sudo umount $(TEMPDIR)
rmdir $(TEMPDIR)

Expand Down
14 changes: 14 additions & 0 deletions tools/labs/templates/hello_assignment/checker/hello-world-checker
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

[ $# -ne 1 ] && { echo "Usage: $0 path-hello-world.ko"; exit 1; }

/bin/dmesg -c > /dev/null 2>&1
/sbin/rmmod hello-world > /dev/null 2>&1
/sbin/insmod $1
/bin/dmesg | grep 'Hello, World!' > /dev/null 2>&1
if test $? -eq 0; then
echo "Test PASSED."
else
echo "Test FAILED."
fi
/sbin/rmmod hello-world > /dev/null 2>&1
3 changes: 3 additions & 0 deletions tools/labs/templates/hello_assignment/sol/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EXTRA_CFLAGS = -Wall -g -m32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the extra sol directory?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be called hello-world.
I assumed this as the source directory, it can have any name. checker directory is supposed to exist in order to be recursively copied to vm disdk


obj-m = hello-world.o
13 changes: 13 additions & 0 deletions tools/labs/templates/hello_assignment/sol/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
KDIR=/usr/src/linux-so2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Makefile is not needed anymore, the top level makefile should take care of building


kbuild:
make -C $(KDIR) M=`pwd`

clean:
make -C $(KDIR) M=`pwd` clean

pack:
zip -r hello-world-solution.zip hello-world.c Makefile Kbuild

deploy: pack
scp hello-world-solution.zip [email protected]:res/current/teme/
21 changes: 21 additions & 0 deletions tools/labs/templates/hello_assignment/sol/hello-world.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <linux/kernel.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run ./scripts/checkpatch.pl -f --strict hello.c to verify for coding style problems

#include <linux/init.h>
#include <linux/module.h>

MODULE_DESCRIPTION("Hello World");
MODULE_AUTHOR("Psoru Lesfo Rever");
MODULE_LICENSE("GPL");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are here I think we should also find a better name for module author. I don't have good names now, but I think kernel people recommend to use real names here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. It should still be a generic name. I recommend we use "Linux Kernel Labs [email protected]", or we can create a new e-mail address.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the same author for all modules. I suggest changing this for all modules in a future commit.


static int hello_init(void)
{
printk(KERN_DEBUG "Hello, World!\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to avoid using printk where possible, it is now recommended to use pr_debug, pr_info, etc. I think we can replace this with pr_info.

Also, I think we should add a TODO comment here so that this line is removed when the skel is generated.

return 0;
}

static void hello_exit(void)
{
}

module_init(hello_init);
module_exit(hello_exit);