No video

Let's code a Linux Driver - 1: Hello World Linux Kernel Module

  Рет қаралды 96,107

Johannes 4GNU_Linux

Johannes 4GNU_Linux

Күн бұрын

Let's leave userspace and head towards Kernelspace!
In this series of videos I will show you how to write your own Linux Driver. In this video, I will create a simple Hello World Linux Kernel Module Enjoy!
Here is the link to my git-repo:
github.com/Joh...
You want to support my work? You can buy me a coffee here: www.buymeacoff...
Here are some of my sources:
Mike Netz. Eigener linux-gpio-treiber für raspberry pi 3 model b. mike-netz.biz/?..., 2018. letzter Aufruf: 19.12.2020.
Jürgen Platte. Linux Hardware Hackz. Carl Hanser Verlag, 2007.
Martin Züger Usr Graf, Andreas Kalberer. Einführung in die Linux Treiberentwicklung. FHO Hochschule Ostschweiz, 2015.

Пікірлер: 91
@linux_with_anakin
@linux_with_anakin Жыл бұрын
For anyone struggling to get this working on a raspberry pi 4. I struggled to get mine compiling because there wasn't a build folder in /lib/module/$(shell uname -r). The solution, I switched from a headless 32bit OS to a headless 64bit OS. Thank you Johannes for the awesome playlist and channel!
@creataKulkarni
@creataKulkarni 14 күн бұрын
Finally started with driver development, thanks Johannes, you make concepts easily understandable!
@chainer22
@chainer22 2 жыл бұрын
read a few documentations and still no clue how do i start. found your video and managed to get to a basic start! thank you!
@mithrandirthegrey7644
@mithrandirthegrey7644 Жыл бұрын
Monkey see monkey do. I wish the Linux people would learn this. KZbin is full of great presentations by the Linux foundation on various interesting things but when you sit down to actually test the stuff they presented you are immediately stuck. They spend 1h talking about something that 1 % of the listeners can apply. If they just did what they are trying to present live it would be a thousand times more useful.
@minarady4632
@minarady4632 Жыл бұрын
You are awesome, you make it look so easy and simple. Thank you so much!!
@dukeelma7ala
@dukeelma7ala Жыл бұрын
eh ya zmeely
@Components-qu3zs
@Components-qu3zs 2 жыл бұрын
Hi Johannes, thanks for sharing these videos. They're very informative and great to follow along.
@samjohnson5044
@samjohnson5044 3 ай бұрын
Thank you very much for this. I look forward to going through the entire playlist.
@timothypulliam2177
@timothypulliam2177 7 ай бұрын
Thank you for this excellent video. The whole world should see it!
@king_james_official
@king_james_official 2 жыл бұрын
hi man! (or whatever you prefer to be called) i really appreciate the series. it was really hard for me to get into making my own driver, but now i feel a little bit more confident. thanks again :)
@Dmv-635
@Dmv-635 2 жыл бұрын
Thank you for your contribution. Your video helped me a lot in starting my journey in this domain.👍
10 ай бұрын
Super - exactly what I was looking for! I tried it on Jetson AGX Xavier and x86 PC - both Ubuntu 20.04. Works like a charm.
@pradeepatchgal439
@pradeepatchgal439 3 жыл бұрын
I really liked your video, very informative and would love to see more from you :)
@bdon7825
@bdon7825 2 жыл бұрын
Fantastic video. I've seen so many different ways to do this, so it would be a nice addition if you added how to build the module when not on the target machine. Use if depmod and other tool, etc.
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
Thank you. Yes, maybe later this year I want to do a session about Cross Compiling. But therefore I would like to use an industrial grade SoC on an evaluation board. And I am still looking for an affordable candidate.
@ABHISHEKSINGH-nv1se
@ABHISHEKSINGH-nv1se 3 жыл бұрын
Very Informative Videos. I am going to see and work along side of your videos.
@techtheguy5180
@techtheguy5180 2 жыл бұрын
You are a very inspiring person. Thanks
@zetaconvex1987
@zetaconvex1987 Жыл бұрын
Many thank. I really appreciate this tutorial.
@vibhatha
@vibhatha 7 ай бұрын
This is a very nice intro, really simple easy to tackle. Could you please recommend some books to learn more about the core concepts of Linux kernel development?
@johannes4gnu_linux96
@johannes4gnu_linux96 7 ай бұрын
Thank you. Yes, I can recommend Linux Device Drivers 3rd edition. It is a little bit old, bit the concepts still apply. makelinux.net/ldd3/ There are more recent books available, but I haven't read them, so I can't really recommend them. Embetronix also has a great series of written tutorials to Linux Drivers. embetronicx.com/tutorials/linux/device-drivers/linux-device-driver-part-1-introduction/
@vibhatha
@vibhatha 7 ай бұрын
Thanks a lot @@johannes4gnu_linux96 Please add more content, your tutorials are really neat and easy to follow.
@Nik__._.
@Nik__._. 2 жыл бұрын
Thank you this was really useful to get a starting grasp! :)
@OthmanAlikhan
@OthmanAlikhan 2 жыл бұрын
Thanks for the video, awesome tutorial =)
@pc4ever782
@pc4ever782 2 жыл бұрын
Thank You For Your Great Effort 💗 Please 🙏 Can You Make Preif Introduction On How To Contribute To The Linux Kernel And And Make Customisation From It ?!
@pratikpatil6438
@pratikpatil6438 2 жыл бұрын
It helped me, thanks for the videos
@anch83
@anch83 Жыл бұрын
Great tutorial.
@duralikiraz
@duralikiraz 3 жыл бұрын
Really useful video, thank you.
@c.n.crowther438
@c.n.crowther438 7 ай бұрын
Thanks, steep learning curve for me but I just want to get my keyboard backlight to work
@ColdRooster
@ColdRooster 2 жыл бұрын
Thanks for this video buddy
@CapitaineBleuten
@CapitaineBleuten 2 жыл бұрын
You're amazing!
@denisrosas
@denisrosas 2 жыл бұрын
Johannes, thanks for this video. I followed the exact steps but I run a problem. /usr/src don't have the linux-header files as it already does in your tutorial. I'm using raspbian on my Raspberry Pi 3+. It took me a while to figure it out. But basically I could solve it with 2 commands: sudo apt install raspberrypi-kernel sudo apt install raspberrypi-kernel-headers The first one will update the kernel (if not updated) and the second will download the headers of the last kernel version, that are required to compile a module. Hope this info helps someone.
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
Thank you for our feedback and the info :) I mentioned this "preparation steps" in the first video, I have done on this "Let's code a Linux Driver" session: kzbin.info/www/bejne/rmK8Y2Npq61gesU But it is also good to mention it here.
@Jonathan-ru9zl
@Jonathan-ru9zl 2 жыл бұрын
Hello! I've got makefile error: make -C /home/jonathan/Linux_Kernel/5.3.0-28-generic/build M=/home/jonathan/Linux_Kernel modules make[1]: *** /home/jonathan/Linux_Kernel/5.3.0-28-generic/build: No such file or directory. Stop. Makefile:4: recipe for target 'all' failed make: *** [all] Error 2 i am using ubuntu 18.04 without board for now. but it should compile, right?
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
Have you installed the Kernel headers? On Ubuntu run: sudo apt-get install linux-headers-$(uname -r) Are You using the same makefile as I do? The path /home/Jonathan/Linux_Kernel/5.* Looks wrong.
@Jonathan-ru9zl
@Jonathan-ru9zl 2 жыл бұрын
@@johannes4gnu_linux96 Cool it seems to work! but i didn't get .ko file : make -C /lib/modules/5.3.0-28-generic/build M=/home/jonathan/Linux_Kernel modules make[1]: Entering directory '/usr/src/linux-headers-5.3.0-28-generic' Building modules, stage 2. MODPOST 0 modules make[1]: Leaving directory '/usr/src/linux-headers-5.3.0-28-generic'
@Jonathan-ru9zl
@Jonathan-ru9zl 2 жыл бұрын
Update: it produces .ko file. i had spelling error in make file
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
@@Jonathan-ru9zl Good to hear it works.
@mihiradarsh7604
@mihiradarsh7604 Жыл бұрын
Thanks for this video
@suparnaprasad8187
@suparnaprasad8187 5 ай бұрын
I followed everything, but under output instead of the Hello Kernel i'm getting - can someone help?
@preetamdas4048
@preetamdas4048 9 ай бұрын
Nice 😃👍🏻
@rabiahussain4953
@rabiahussain4953 3 жыл бұрын
thanks for the tutorials, i noticed that you have just burned the image in sd card and put that sd card on rpi board and access the board by ssh. and then just start writing the module on it ... i have found other videos where people first setup the yocto project under that they setup the QEMU and on that they start writing the device driver(this method is difficult). my main question is what method is used for which purpose because in both methods the goal is to write the device deriver.? please reply me as soon as possible.
@johannes4gnu_linux96
@johannes4gnu_linux96 3 жыл бұрын
Well, both methods have their advantages and disadvantages. I choose to use a raspberry pi, because of the following reasons: - a lot of people have RPis and know how to use them - Good documentation - Powerful computers (Mine has a Quad core A53 and 1GB of memory, which is a lot for an embedded device!) - Full featured linux distro (with package manager, python, compiler, ... already available) - RPi has all the important interfaces (SPI, GPIO, I2C, ...) So, I choose the RPi because I wanted to use a comfortable computing platform, where I could just start to develop my Kernel Modules. I didn't want to use *Cross-Compiling* or *Virtualization with QMENU* because this are quite difficult topics and I just want to focus on the Kernel-Module-Programming. I believe for a beginner this approach is more straight forward and easier. But if your target for your project is not a RPi, using your hardware, which is maybe not as powerful as the RPi, Yocto and Cross-Compiling is the way to go. Using Yocto has the advantages you can compile everything yourself (and apply some Kernel-Patches you are interested in, e.g. Realtime patches), you only have the programs onboard, you really need, you can use a custom Device Tree and your SD-Card Image will be a lot smaller then Raspbian. But going this way you loose a lot of comfort from the RPi, e.g. most Yoctos don't have a package manager as powerfull as apt, most of them don't have python or a compiler installed, ... With Yocto you really get a minimal Linux for an embedded system with all up- and downsides. You have to cross compile, because the compilation is to resource heavy for your tiny hardware, etc. I would only use Virtualization with QMENU, if you don't have the hardware available and you want to start developing or if you have to debug a lot and you don't have a good (and most of the time expensive) JTAG-HW-Debugger. So, for beginners, I would recommend to use a RPi. It will offer you a lot of comforts and a lot of interfaces. But if you don't mind the interfaces, you can develop Kernel modules on a normal x86-PC too! All of my tutorials, where I do not need I2C, SPI or GPIOs will work fine there too! Then, when you are more familiar with the Kernel-Programming and you have a project with a different Target-HW, then go the next step and start using Yocto, Cross-Compiling and Virtualization.
@rabiahussain4953
@rabiahussain4953 2 жыл бұрын
​@@johannes4gnu_linux96 Thanks for your detailed answer which cleared my mind a lot, till now I have learned all of your device driver videos and from other channels, so I have written GPIO, USB, I2C and many more drivers. i have noticed that in all of that i just take any hardware attached with my rpi and start writing code. For example, In USB driver I attached my mobile phone with usb to rpi, and got the vendor id, product id with lsusb , and then wrote a driver to probe, disconnect and table, and get a minor number of device in output. and the same goes with the other drivers also. But I am unable to understand the need of writing drivers, in GPIO driver we can simply write c code or anything, what is the need of writing kernel device drivers. i have read my articles but I don't understand them completely, so I decided to ask you because your previous reply helped me a lot.
@lorishofer2889
@lorishofer2889 2 жыл бұрын
Hello! On my system (postmarketOS edge), /lib/modules//build is absent. On my laptop however (x86_64), the directory exists. Does anyone here know how to resolve this issue?
@gregoryfenn1462
@gregoryfenn1462 3 жыл бұрын
One thing not obvious to me first time is that the file name my_module.c has to match the module name as my_module.o in the Makefile. I thought you could name the module something different to the c file and the Makefile was smart enough to collect all the *.c files in the $(PWD) folder.
@johannes4gnu_linux96
@johannes4gnu_linux96 3 жыл бұрын
It depends on your makefile. In the makefile, I am using in the video, I just set some variables and then call another makefile located in /lib/modules/$(shell uname -r)/build. Here everything about how to build the module is defined. The makefile is only smart enough to build every c file it finds in the folder, if you specify it in the makefile. In the case of our makefile it isn't.
@user-go9dn9be6b
@user-go9dn9be6b Жыл бұрын
Hey, really informative video. Is the module run with ring 0 permissions.
@lowmax4431
@lowmax4431 Жыл бұрын
I keep getting missing separator errors even though I am using proper tabs (no spaces).
@meoDomicio
@meoDomicio 2 жыл бұрын
Thanks for this videos, wiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
@tzgardner
@tzgardner 8 күн бұрын
9:16 What exactly are you pointing to when you have the following path -C /lib/modules/$(shell uname -r)/build? I'm getting a "no such file or directory"
@johannes4gnu_linux96
@johannes4gnu_linux96 2 күн бұрын
It resovles to something similar like this: /lib/modules/6.10.5-arch1-1/build If you are missing the build folder, you have to install the linux kernel headders, e.g. with "sudo apt install raspberrypi-linux-headers" on a raspberry pi.
@user-sy4yg3dy6m
@user-sy4yg3dy6m Жыл бұрын
Thanks!
@shubhamkandekar4723
@shubhamkandekar4723 Жыл бұрын
how to Add a Linux kernel module, which is loaded dynamically and also load statically??
@tahaberk3067
@tahaberk3067 2 жыл бұрын
It was so explanatory
@madhutamilnadu8663
@madhutamilnadu8663 Жыл бұрын
Thanks 👍
@tiagooliveira2815
@tiagooliveira2815 2 жыл бұрын
I see that he works with a Raspberry Pi, I can follow the videos and do the practices in my coputer x86_64 with Linux?, or it is necessary to use a Raspberry? Thanks for sharing these videos.
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
Most of the videos should work except for those in which I access pheripherals Like GPIOs, I2C, SPI, ... These are normally not so easy accessable on a Standard PC Like on the Raspberry Pi.
@tiagooliveira2815
@tiagooliveira2815 2 жыл бұрын
@@johannes4gnu_linux96 Thank you very much, I will continue watching your videos.
@techwithtreveen
@techwithtreveen 10 ай бұрын
Great Video! Can you make one on hooking write syscall on a file and instead of writing it direct the text to /dev/null or something similar causing the person not able to write to the file?
@johannes4gnu_linux96
@johannes4gnu_linux96 10 ай бұрын
I don't understand what you mean here.But you can find videos where I am overloading syscalls for device files in my playlist.
@General_Li_Shin
@General_Li_Shin 2 жыл бұрын
make[1]: *** /lib/modules/4.19.94-ti-r42/build: No such file or directory. Stop. could not insert module main.ko: Invalid module format, any idea on how to deal with this error
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
It look like the kernel modules are not installed. Are you using a TI EVM or beaglebone with (Yocto) Linux? For the raspberry pi maybe this helps: kzbin.info/www/bejne/iHvVYZZqmdV-rqs
@tahaberk3067
@tahaberk3067 2 жыл бұрын
Thanks
@BangBang-te3mi
@BangBang-te3mi 2 жыл бұрын
Hey, first of all, thanks very much for the playlist. I have a problem when I try to insert the same module you have shown in the video. I am getting the error "Invalid module format" from insmod, any help is appreciated, thanks!
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
You are welcome. To help you, I need more information: - What is your target (Raspberry Pi)? - Are you doing the compiling on the target (on the RPi) or are you using cross compiling? - If you are on a RPi, have you followed the tips shown here: kzbin.info/www/bejne/iHvVYZZqmdV-rqs I know this error from doing cross compiling and the Kernel Version on my Target didn't match with the Kernel I used to compile my sources.
@BangBang-te3mi
@BangBang-te3mi 2 жыл бұрын
@@johannes4gnu_linux96 Oh okay, I am actually on Ubuntu virtual machine. I looked around before I commented here, I am sure the kernel I am running and the target kernel during compilation is the same, because the output of uname -r command matches.
@MyFluteMyMusic
@MyFluteMyMusic 2 жыл бұрын
having error make -C /lib/modules/5.10.63-v7+/build M=/home/pi/Programming/Linux_Driver_Tutorial modules make[1]: *** /lib/modules/5.10.63-v7+/build: No such file or directory. Stop. make: *** [Makefile:3: all] Error 2
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
kzbin.info/www/bejne/iHvVYZZqmdV-rqs This should solve the problem
@handsome616
@handsome616 Жыл бұрын
thx
@manojchavva5869
@manojchavva5869 3 ай бұрын
Hi Johannes ,Is this tutorial work for RPI 5?
@johannes4gnu_linux96
@johannes4gnu_linux96 2 ай бұрын
Yes, all of my driver tutorial videos (if they are not outdated like the first SPI and I2C videos) should be compile-able on any Linux system. That's one of the tasks of an operating system to give us a hardware abstraction layer. When you come to drivers accessing hardware (e.g. accessing GPIOs) maybe you have to change something (e.g. pin numbers), but in general it should work.
@imranrajjad7028
@imranrajjad7028 2 жыл бұрын
good video however I was not able to go beyond compiling the module ------------- make -C /lib/modules/5.10.63-v7+/build M=/home/pi/kernel_work modules make[1]: *** /lib/modules/5.10.63-v7+/build: No such file or directory. Stop. make: *** [Makefile:4: all] Error 2 ----------- Apparently headers do not exist for my raspbian kernel
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
Thank you. Run this Commando: sudo apt install raspberrypi-kernel-headers This should solve the problem.
@imranrajjad7028
@imranrajjad7028 2 жыл бұрын
@@johannes4gnu_linux96 thanks Reading package lists... Done Building dependency tree Reading state information... Done raspberrypi-kernel-headers is already the newest version (1:1.20210831-3~buster). 0 upgraded, 0 newly installed, 0 to remove and 51 not upgraded.
@MyFluteMyMusic
@MyFluteMyMusic 2 жыл бұрын
@@imranrajjad7028 i m having same problem help me
@MyFluteMyMusic
@MyFluteMyMusic 2 жыл бұрын
make -C /lib/modules/5.10.63-v7+/build M=/home/pi/Programming/Linux_Driver_Tutorial modules make[1]: *** /lib/modules/5.10.63-v7+/build: No such file or directory. Stop. make: *** [Makefile:3: all] Error 2
2 жыл бұрын
@@johannes4gnu_linux96 error still continue :( make -C /lib/modules//build M=/home/pi/hello modules make[1]: *** /lib/modules//build: No such file or directory. Stop. make: *** [Makefile:4: all] Error 2
@johnnydevvn
@johnnydevvn 3 жыл бұрын
Hello sir, Thanks for your sharing. I'm a newbie, and I'm facing this error while building the driver. Could you please help me? root@beaglebone:~/Lesson_1# ls hello_world.c Makefile root@beaglebone:~/Lesson_1# make make -C /lib/modules/4.19.94-ti-r42/build M=/root/Lesson_1 modules make[1]: *** /lib/modules/4.19.94-ti-r42/build: No such file or directory. Stop. make: *** [Makefile:4: all] Error 2 I think my lib should be updated with something, could you please share me a command to update, I try to google but cannot find the result. Thank you very much.
2 жыл бұрын
make: * [Makefile:4: all] Error 2
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
kzbin.info/www/bejne/iHvVYZZqmdV-rqs This should solve the problem
@markyerger
@markyerger 2 жыл бұрын
bro how to overclock
@liendatt8347
@liendatt8347 2 жыл бұрын
hii, i'm getting this kind of error. dani@raspberrypi:~/ldd$ make -C /lib/modules/5.15.32+/build/ M=$PWD modules make: Entering directory '/usr/lib/modules/5.15.32+/build' make: *** No rule to make target 'modules'. Stop. make: Leaving directory '/usr/lib/modules/5.15.32+/build' please help
@johannes4gnu_linux96
@johannes4gnu_linux96 2 жыл бұрын
Looks Like the Kernel headers are not installed correctly. Watch this: kzbin.info/www/bejne/iHvVYZZqmdV-rqs
@user-qx1jf8pf5z
@user-qx1jf8pf5z 10 ай бұрын
I try to do the same action, but in respond of 'dmesg | teil' I recieve an audit messages, that type=1400, apparmer='denied' and something
@hangdong2374
@hangdong2374 Жыл бұрын
Hello, can I put your video on a Chinese website blibli ? I would indicate the source of your course
@johannes4gnu_linux96
@johannes4gnu_linux96 Жыл бұрын
Yes, if you indicate the source it is ok from my side.
@hangdong2374
@hangdong2374 Жыл бұрын
@@johannes4gnu_linux96 thank you , no problem!
Let's code a Linux Driver - 2: Device Numbers and Files
16:43
Johannes 4GNU_Linux
Рет қаралды 38 М.
🩷🩵VS👿
00:38
ISSEI / いっせい
Рет қаралды 18 МЛН
الذرة أنقذت حياتي🌽😱
00:27
Cool Tool SHORTS Arabic
Рет қаралды 10 МЛН
Pool Bed Prank By My Grandpa 😂 #funny
00:47
SKITS
Рет қаралды 19 МЛН
Understanding the Structure of a Linux Kernel Device Driver
58:30
Sergio Prado
Рет қаралды 40 М.
QEMU for Linux kernel developers
13:56
Johannes 4GNU_Linux
Рет қаралды 8 М.
How Do Linux Kernel Drivers Work? - Learning Resource
17:02
LiveOverflow
Рет қаралды 545 М.
Linus Torvalds Guided Tour of His Home Office
4:25
Barbara
Рет қаралды 1,6 МЛН
Linux Kernel Programming 01: Compile and Boot
51:57
Write your own Operating System
Рет қаралды 103 М.
Torvalds Speaks: Rust's Impact on the Linux Kernel
3:50
Mastery Learning
Рет қаралды 587 М.
Custom Linux Kernel | Walkthrough Guide
11:42
Chris Titus Tech
Рет қаралды 85 М.
Richard Stallman Talks About Ubuntu
6:10
TFiR
Рет қаралды 1,4 МЛН
🩷🩵VS👿
00:38
ISSEI / いっせい
Рет қаралды 18 МЛН