Тёмный
No video :(

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

Johannes 4GNU_Linux
Подписаться 15 тыс.
Просмотров 96 тыс.
50% 1

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.

Опубликовано:

 

24 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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 17 дней назад
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. RU-vid 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
@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 :)
@samjohnson5044
@samjohnson5044 3 месяца назад
Thank you very much for this. I look forward to going through the entire playlist.
@Components-qu3zs
@Components-qu3zs 2 года назад
Hi Johannes, thanks for sharing these videos. They're very informative and great to follow along.
@timothypulliam2177
@timothypulliam2177 7 месяцев назад
Thank you for this excellent video. The whole world should see it!
@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 :)
@ABHISHEKSINGH-nv1se
@ABHISHEKSINGH-nv1se 3 года назад
Very Informative Videos. I am going to see and work along side of your videos.
@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.
@c.n.crowther438
@c.n.crowther438 7 месяцев назад
Thanks, steep learning curve for me but I just want to get my keyboard backlight to work
@techtheguy5180
@techtheguy5180 2 года назад
You are a very inspiring person. Thanks
@zetaconvex1987
@zetaconvex1987 Год назад
Many thank. I really appreciate this tutorial.
@Nik__._.
@Nik__._. 2 года назад
Thank you this was really useful to get a starting grasp! :)
@pratikpatil6438
@pratikpatil6438 2 года назад
It helped me, thanks for the videos
@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 ?!
@duralikiraz
@duralikiraz 3 года назад
Really useful video, thank you.
@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.
@anch83
@anch83 Год назад
Great tutorial.
@suparnaprasad8187
@suparnaprasad8187 5 месяцев назад
I followed everything, but under output instead of the Hello Kernel i'm getting - can someone help?
@ColdRooster
@ColdRooster 2 года назад
Thanks for this video buddy
@lowmax4431
@lowmax4431 Год назад
I keep getting missing separator errors even though I am using proper tabs (no spaces).
@shubhamkandekar4723
@shubhamkandekar4723 Год назад
how to Add a Linux kernel module, which is loaded dynamically and also load statically??
@mihiradarsh7604
@mihiradarsh7604 Год назад
Thanks for this video
@tzgardner
@tzgardner 11 дней назад
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 5 дней назад
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.
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-x1Y203vH-Dc.html But it is also good to mention it here.
@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.
@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.
@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?
@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.
@tahaberk3067
@tahaberk3067 2 года назад
It was so explanatory
@user-sy4yg3dy6m
@user-sy4yg3dy6m Год назад
Thanks!
@madhutamilnadu8663
@madhutamilnadu8663 Год назад
Thanks 👍
@preetamdas4048
@preetamdas4048 10 месяцев назад
Nice 😃👍🏻
@tahaberk3067
@tahaberk3067 2 года назад
Thanks
@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.
@manojchavva5869
@manojchavva5869 3 месяца назад
Hi Johannes ,Is this tutorial work for RPI 5?
@johannes4gnu_linux96
@johannes4gnu_linux96 3 месяца назад
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.
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RJr0c4dpKxI.html
@handsome616
@handsome616 Год назад
thx
@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 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RJr0c4dpKxI.html This should solve the problem
@meoDomicio
@meoDomicio 2 года назад
Thanks for this videos, wiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
@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.
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RJr0c4dpKxI.html 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.
@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 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RJr0c4dpKxI.html This should solve the problem
@markyerger
@markyerger 2 года назад
bro how to overclock
@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
@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: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RJr0c4dpKxI.html
@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!
Далее
Demonstração sobre uso de python com MQTT
12:01
Просмотров 3,1 тыс.
How Linux Kernel Prints Text on Screen
12:46
Просмотров 65 тыс.
How Do Linux Kernel Drivers Work? - Learning Resource
17:02
Linus Torvalds Guided Tour of His Home Office
4:25
Просмотров 1,6 млн