These are records of my codes, reports and what I've learned in NYCU Embedded Operating System.
- Only those who pass the pretest can take this course.
- This lab is about setting up environment on Raspberry Pi.
- What I've learned:
- NAT
- Bridge
- This lab is about Building kernel.
- We are required to meet the goals.
- Q1: Shrink the size of your kernel image.
- Q2: Benchmark your kernel, revise it, and improve its performance. Rerun the benchmark to prove your performance.
- Q3: Patch your kernel to support real-time tasks.
- This lab is about creating my own driver based on GPIO driver.
- It's suggested that you check Lab 4 first, as I completed it earlier. More details are recorded there.
- Notes:
Here are some basic GPIO commands.- Each GPIOs imformaiton are under /sys/class/gpio, you should see those GPIOs which have been exported.
$ echo 17 > /sys/class/gpio/exportto export GPIO17 for example. Use$lsto check.$ echo "out" > /sys/class/gpio/gpio17/directionto make gpio17 output mode.$ echo 1 > /sys/class/gpio/gpio17/valueto set value.$ cat /sys/class/gpio/gpio17/valueto see the value of GPIO17.
$ sudo insmod lab3-1_driver.koto insert kernel object.$ ls -l /devto check whether the device has been created or not. For more imformation, use$ dmesg|tail.$ sudo chmod 777 /dev/etx_deviceas I name my driver etx_device.- lab3-1_writer.c
- Usage:
$ ./lab3-1_writer <student ID>
- Usage:
$ sudo insmod lab3-2_driver.koto insert kernel object.$ ls -l /devto check whether the device has been created or not. For more imformation, use$ dmesg|tail.$ sudo chmod 777 /dev/seg_deviceas I name my driver seg_device.- lab3-2_writer.c
- Usage:
$ ./lab3-2_writer <student ID>
- Usage:
- In this homework, I will create seg_driver and led_driver.
- Create kernel object
- make sure you've already set the
$(PWD)to the correct file. In my case,$ PWD=/home/wang/linux. $ makewith Makefile$ scp <xxxxxx>.ko pi@ipaddr:~/to send .ko file to Rpi.
- make sure you've already set the
- Insert module in Rpi
$ sudo insmod led_driver.koand$ sudo insmod seg_driver.koto insert module.$ sudo chmod 777 /dev/led_deviceand$ sudo chmod 777 /dev/led_deviceto change usage permission.
- Hw1_app.c
- This is the main application.
$ ./Hw1_appto run the main program.
- Hw1_app_fork.c
- Ths is another version of the main application.
- use
waitpid()to implement multitasking so that 7seg and led can run simultaneously.
- This lab is about creating my driver.
- Create kernel object(.ko) then insert module.
- make sure you've already set the
$(PWD)to the correct file. In my case,$ PWD=/home/wang/linux. $ makewith Makefile
- make sure you've already set the
$ scp mydev.ko pi@ipaddr:~/to send .ko file to Rpi.- Insert module and create device node.
$ sudo insmod mydev.koandsudo rmmod mydev.koto insert and remove.$ sudo mknod /dev/my_device c 255 0to make device node. c stands for character device, 255 and 0 for major num and minor num.$ sudo rm /dev/my_deviceto delete device node.$ dmesgto see any information for kernel info.$ ls -l /devto see if device node created or not.$ echo "A">/dev/my_devicefor testing. You should see more information afterdmesg. Make sure you have sufficient permissions to read and write, if not, use$ sudo chmod 666 /dev/my_device
- writer.c
- Usage:
$ ./writer <name>
- Usage:
- reader.c
- Usage:
$ ./reader <server ip> <port> </dev/my_device>
- Usage:
- run reader and writer at the same time.
$ sudo ./demo.shto run reader and writer at the same time.
- seg.py
- Usage:
$ python3 seg.py <port>
- Usage:
- What I've learned:
- cross compile set up in Makefile.
- uniform APIs which are defined in /include/linux/fs.h.
- basic driver.c structure and compile into .ko file.
- Copy_from_user(), Copy_to_user()
- driver table, device table
- Notes:
- A major number is a unique identifier assigned to a device driver in the Linux kernel. On the other hands, A minor number is a smaller identifier that is used in conjunction with the major number to uniquely identify a specific device within a class of devices. For example, mojor number for a disk driver is 8, minor number for /dev/sda, /dev/sdb, /dev/sdc is 0, 1, 2.
- To create more devices from the same driver, just
mknod. For example,$ mknod /dev/my_device1 c 255 0and$ mknod /dev/my_device2 c 255 1to create different device instances.
- This lab is about processes and threads.
- Make sure you have downloaded "sl" and "tmux". Use
$ sudo apt install sl tmux. - To run the lab5 program, use
$ ./demo.sh. UseCtrl+Band:kill-sessionto close the session. - To check if any zombie processes left or not, use
$ ps aux | grep defunct | grep -v grep. - What I've learned:
🌟 For more details, you are recommanded to take a look at "Lab5_report.pdf".- Processes
- fork(): child process "inherits" all resources from the parent process, pid() and ppid().
- harvest: How parent process receive value from child process with wait() and waitpid().Otherwise, there might be a zombie process.
- nice(): Use for priority of a process.
- exec()
- zombie process
- Threads
- master thread and worker thread
- pthread_create()
- attach and detach. Beware of pointer type.
- Processes
- Use
$ ./Hw2_app <port>to run with the program hw2_checker $ hw2_checker <ip> <port>
- Lab6_server.c
- Usage
$ ./server <port>
- Usage
- Lab6_client.c
- Usage
$ ./client <ip> <port> <deposit/withdraw> <amount> <times>
- Usage
- demo.sh
- Use
$ demo.shto run the program
- Use
- Note:
- There are two versions, the first method involves parsing times on the client side, which sends out 500 packets. The second method parses times on the server side, where the server runs a loop to handle deposits and withdrawals. The results(./demo.sh) from the first method are more interleaved, while the results from the second method are more organized.
- game.c
- Usage
$ ./game <shm key> <guess>
- Usage
- guess.c
- Usage
$ ./game <shm key> <Upper bound> <game's PID>
- Usage