Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions 01_git/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
NAME = scissors

SRC = scissors.c

CFLAGS = -Wall -Wextra -Werror

OBJ_DIR = obj
OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:.c=.o))

.PHONY = all clean re

all: $(OBJ_DIR) $(NAME)

$(NAME): $(OBJ)
gcc $(CFLAGS) $^ -o $(NAME)

$(addprefix $(OBJ_DIR),/%.o): %.c
gcc $(CFLAGS) $(DDFLAGS) -c $^ -o $@

clean:
rm -rf $(OBJ_DIR) $(NAME)

re:
make clean
make all

$(OBJ_DIR):
mkdir -p $@
38 changes: 38 additions & 0 deletions 01_git/scissors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
char com;
int r;

srand(time(NULL));

printf("Please choose: rock (r) - paper (p) - scissors (s)");
com = getchar();
r = rand()%3;

if (com == 'r') printf("You choose rock, I choose " );
if (com == 'p') printf("You choose paper, I choose " );
if (com == 's') printf("You choose scissors, I choose ");

if (r == 0) printf("rock.\n" );
if (r == 1) printf("paper.\n" );
if (r == 2) printf("scissors.\n");

if (com == 'r' && r == 0) printf ("Draw game.\n" );
if (com == 'p' && r == 1) printf ("Draw game.\n" );
if (com == 's' && r == 2) printf ("Draw game.\n" );

if (com == 'r' && r == 1) printf ("I win: paper beats rock.\n" );
if (com == 'p' && r == 2) printf ("I win: scissors beats paper.\n" );
if (com == 's' && r == 0) printf ("I win: rock beats scissors.\n" );

if (com == 'r' && r == 2) printf ("You win: rock beats scissors.\n" );
if (com == 'p' && r == 0) printf ("You win: paper beats rock.\n" );
if (com == 's' && r == 1) printf ("You win: scissors beats paper.\n" );

getchar();
return 0;
}
22 changes: 22 additions & 0 deletions 02_bash/devices.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

ttyUSB :{

}
mmcblk :{

}
i2c :{
i2c-0
i2c-1
i2c-2
i2c-3
i2c-4
i2c-5

}
sd :{
sda
sda1
sda2

}
36 changes: 36 additions & 0 deletions 02_bash/hwdetech.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

USB_UART="ttyUSB"
MMCBLK="mmcblk"
I2C="i2c"
SD="sd"

check_device()
{
printf "\n$1 :{\n" >> devices.txt
ls /dev/ | grep $1 >> devices.txt
printf "\n}">> devices.txt
}


touch devices.txt
touch tmp_devices.txt

while [ 1 ]
do
rm devices.txt
touch devices.txt
check_device $USB_UART
check_device $MMCBLK
check_device $I2C
check_device $SD
CHK_DVC=$(diff tmp_devices.txt devices.txt)

if [ "$CHK_DVC" != "" ]
then
cp devices.txt tmp_devices.txt
cat devices.txt
fi

sleep 1
done
22 changes: 22 additions & 0 deletions 02_bash/tmp_devices.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

ttyUSB :{

}
mmcblk :{

}
i2c :{
i2c-0
i2c-1
i2c-2
i2c-3
i2c-4
i2c-5

}
sd :{
sda
sda1
sda2

}
16 changes: 16 additions & 0 deletions 03_module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module home work: create a simple loadable module with parameters

Create a loadadle kernel module which should accept two integer parameters and provide:

A sum of parameters upon driver load
A substration of parameters upon driver unload

Info about module parameters can be found at: https://devarea.com/linux-kernel-development-kernel-module-parameters/#.YZfWcpFByV4

Task should be performed using buildroot+qemu approach

The task results should contain:

The module code
The Makefile
Dump of the kernel logs from the target system
16 changes: 16 additions & 0 deletions 03_module/my_modul/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#KERNELDIR ?= ~/soft/buildroot-2021.11-rc2/output/build/linux-5.15/
#KERNELDIR ?= ~/soft/buildroot-2021.02/output/build/linux-5.10.10/
# KERNELDIR ?= ~/soft/buildroot-2021.02/output/host/bin/
# KERNELDIR ?= ~/soft/buildroot-2021.11-rc2/output_oranj/build/linux-5.12.2/

KERNELDIR ?= ~/soft/buildroot-2021.02/temp_imeg/build/linux-5.10.10/
ifneq ($(KERNELRELEASE),)
obj-m := modul_add.o
else

all:
$(MAKE) CFLAGS_MODULE="-DDEBUG -DORANGE_PI_ZERO" -C $(KERNELDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
endif

15 changes: 15 additions & 0 deletions 03_module/my_modul/Makefile_old
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ifneq ($(KERNELRELEASE),)
# kbuild part of makefile
obj-m := modul_add.o
else
# normal makefile
KDIR ?= /lib/modules/`uname -r`/build

default:
$(MAKE) -C $(KDIR) M=$$PWD
move:
cd ../ && sudo cp -r 03_module /srv/nfs/busybox/tmp/
clean:
$(MAKE) -C $(KDIR) M=$$PWD clean
endif

23 changes: 23 additions & 0 deletions 03_module/my_modul/kernel-log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# Simple script for generating logs for kernel module
# with different parameters

echo '[Hello it`s test for first Kernel module]'
echo ' '
echo '[With parameters]'
sleep 0.1s
insmod modul_add.ko znach_1=122 znach_2=133
rmmod modul_add.ko

echo ' '
echo '[With one parameters]'
sleep 0.1s
insmod modul_add.ko znach_1=-10
rmmod modul_add.ko

echo ' '
echo '[Without parameters]'
sleep 0.1s
insmod modul_add.ko
rmmod modul_add.ko
17 changes: 17 additions & 0 deletions 03_module/my_modul/log_mod.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Hello it`s test for first Kernel module]

[With parameters]

[With one parameters]

[Without parameters]

dmesg | grep 'znach'

[ 3230.039347] znach_1 + znach_2 = 255
[ 3230.042907] znach_1 - znach_2 = -11
[ 3230.164680] znach_1 + znach_2 = 0
[ 3230.168207] znach_1 - znach_2 = -20
[ 3230.302357] znach_1 + znach_2 = 15
[ 3230.305929] znach_1 - znach_2 = -5

27 changes: 27 additions & 0 deletions 03_module/my_modul/modul_add.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <linux/kernel.h>
#include <linux/module.h>

static int znach_1 = 5;
static int znach_2 = 10;

module_param(znach_1, int, S_IRUSR | S_IRGRP);
MODULE_PARM_DESC(znach_1, "the first module's parameter");
module_param(znach_2, int, S_IRUSR | S_IRGRP);
MODULE_PARM_DESC(znach_2, "the second module's parameter");

int init_module(void)
{
printk(KERN_INFO "znach_1 + znach_2 = %d\n", znach_1 + znach_2);

return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "znach_1 - znach_2 = %d\n", znach_1 - znach_2);
}

MODULE_DESCRIPTION("My simple kernel module");
MODULE_AUTHOR("Valentin S.");
MODULE_LICENSE("GPL");
MODULE_VERSION("0.1");
17 changes: 17 additions & 0 deletions 04_basic_srtuct/Log_basic_struct.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# insmod basic_struct.ko
# echo "123456" > /sys/kernel/basic_struct/list
# at /sys/kernel/basic_struct/list
-sh: at: not found
# cat /sys/kernel/basic_struct/list
123456
# echo "Hello world 1" > /sys/kernel/basic_struct/list
# cat /sys/kernel/basic_struct/list
123456
Hello world 1
# echo "Hello world 2" > /sys/kernel/basic_struct/list
# echo "Hello world 3" > /sys/kernel/basic_struct/list
# cat /sys/kernel/basic_struct/list
123456
Hello world 1
Hello world 2
Hello world 3
11 changes: 11 additions & 0 deletions 04_basic_srtuct/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#KERNELDIR ?= ~/Development/Embedded/exercise8/buildroot_qemu_x64_image/build/linux-5.10.7/
KERNELDIR ?= ~/soft/buildroot-2021.11-rc2/output/build/linux-5.15/
CFLAGS_basic_struct.o := -DDEBUG
obj-m += basic_struct.o

all:
make -C $(KERNELDIR) M=$(PWD) modules
clean:
make -C $(KERNELDIR) M=$(PWD) clean
test:
sh test_S_mod.sh
8 changes: 8 additions & 0 deletions 04_basic_srtuct/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Basic structure homework

Implement object with name “MyObject” which is parent of kernel_kobj.
Object should include linked_list structure.
This object should contain sysfs attribute with name “list”.
On read form attribute “list” it should show content of the objects linked list.
On write to attribute “list” it should add new string to the objects linked list.
!! Do not forget properly free all the resources during rmmod.
Loading