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

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 96

  • @linux_with_anakin
    @linux_with_anakin Рік тому +14

    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 3 місяці тому +1

    Finally started with driver development, thanks Johannes, you make concepts easily understandable!

  • @chainer22
    @chainer22 2 роки тому +20

    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 Рік тому +3

      Monkey see monkey do. I wish the Linux people would learn this. UA-cam 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 Рік тому +6

    You are awesome, you make it look so easy and simple. Thank you so much!!

  •  Рік тому

    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.

  • @samjohnson5044
    @samjohnson5044 7 місяців тому

    Thank you very much for this. I look forward to going through the entire playlist.

  • @timothypulliam2177
    @timothypulliam2177 10 місяців тому

    Thank you for this excellent video. The whole world should see it!

  • @Components-qu3zs
    @Components-qu3zs 3 роки тому +3

    Hi Johannes, thanks for sharing these videos. They're very informative and great to follow along.

  • @Dmv-635
    @Dmv-635 2 роки тому +2

    Thank you for your contribution.
    Your video helped me a lot in starting my journey in this domain.👍

  • @king_james_official
    @king_james_official 2 роки тому +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 :)

  • @pradeepatchgal439
    @pradeepatchgal439 3 роки тому +2

    I really liked your video, very informative and would love to see more from you :)

  • @bdon7825
    @bdon7825 2 роки тому +1

    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 роки тому +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.

  • @zetaconvex1987
    @zetaconvex1987 Рік тому

    Many thank. I really appreciate this tutorial.

  • @techtheguy5180
    @techtheguy5180 2 роки тому

    You are a very inspiring person. Thanks

  • @c.n.crowther438
    @c.n.crowther438 10 місяців тому

    Thanks, steep learning curve for me but I just want to get my keyboard backlight to work

  • @pc4ever782
    @pc4ever782 3 роки тому

    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 ?!

  • @anch83
    @anch83 Рік тому

    Great tutorial.

  • @pratikpatil6438
    @pratikpatil6438 3 роки тому

    It helped me, thanks for the videos

  • @mihiradarsh7604
    @mihiradarsh7604 2 роки тому

    Thanks for this video

  • @OthmanAlikhan
    @OthmanAlikhan 2 роки тому

    Thanks for the video, awesome tutorial =)

  • @Nik__._.
    @Nik__._. 2 роки тому

    Thank you this was really useful to get a starting grasp! :)

  • @ColdRooster
    @ColdRooster 2 роки тому

    Thanks for this video buddy

  • @duralikiraz
    @duralikiraz 3 роки тому

    Really useful video, thank you.

  • @tzgardner
    @tzgardner 3 місяці тому +1

    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  3 місяці тому +1

      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.

  • @madhutamilnadu8663
    @madhutamilnadu8663 Рік тому

    Thanks 👍

  • @vibhatha
    @vibhatha 10 місяців тому

    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  10 місяців тому +1

      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 10 місяців тому

      Thanks a lot @@johannes4gnu_linux96
      Please add more content, your tutorials are really neat and easy to follow.

  • @AchuthVPretrymp3
    @AchuthVPretrymp3 Рік тому

    Hey, really informative video. Is the module run with ring 0 permissions.

  • @shubhamkandekar4723
    @shubhamkandekar4723 Рік тому

    how to Add a Linux kernel module, which is loaded dynamically and also load statically??

  • @suparnaprasad8187
    @suparnaprasad8187 8 місяців тому

    I followed everything, but under output instead of the Hello Kernel i'm getting - can someone help?

  • @CapitaineBleuten
    @CapitaineBleuten 2 роки тому

    You're amazing!

  • @tahaberk3067
    @tahaberk3067 2 роки тому

    Thanks

  • @stefantapavica5180
    @stefantapavica5180 2 місяці тому

    Which Linux you booted on your Raspberry Pi?

  • @rabiahussain4953
    @rabiahussain4953 3 роки тому +1

    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 роки тому +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 3 роки тому

      ​@@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?

  • @preetamdas4048
    @preetamdas4048 Рік тому

    Nice 😃👍🏻

  • @Jonathan-ru9zl
    @Jonathan-ru9zl 2 роки тому +1

    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 роки тому +1

      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 роки тому +1

      @@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 роки тому +1

      Update: it produces .ko file. i had spelling error in make file

    • @johannes4gnu_linux96
      @johannes4gnu_linux96  2 роки тому

      @@Jonathan-ru9zl Good to hear it works.

    • @rokasbarasa1
      @rokasbarasa1 Місяць тому

      @@johannes4gnu_linux96 My Raspberry pi 4 2Gb had problems with this command: sudo apt-get install linux-headers-$(uname -r)
      The problem was that even if the 32 bit raspberry pi operating system is installed it is still trying to use the 64 bit kernel or something. I needed edit"/boot/firmware/config.txt" and in the "ALL" section add "arm_64bit=0". After reboot it the command worked fine.

  • @manojchavva5869
    @manojchavva5869 6 місяців тому

    Hi Johannes ,Is this tutorial work for RPI 5?

    • @johannes4gnu_linux96
      @johannes4gnu_linux96  6 місяців тому +1

      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.

  • @meoDomicio
    @meoDomicio 2 роки тому

    Thanks for this videos, wiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

  • @denisrosas
    @denisrosas 3 роки тому +1

    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  3 роки тому +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:
      ua-cam.com/video/x1Y203vH-Dc/v-deo.html
      But it is also good to mention it here.

  • @tahaberk3067
    @tahaberk3067 2 роки тому

    It was so explanatory

  • @handsome616
    @handsome616 Рік тому

    thx

  • @lowmax4431
    @lowmax4431 Рік тому

    I keep getting missing separator errors even though I am using proper tabs (no spaces).

  • @techwithtreveen
    @techwithtreveen Рік тому

    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  Рік тому

      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: ua-cam.com/video/RJr0c4dpKxI/v-deo.html

  • @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.

  • @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 роки тому +1

      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: ua-cam.com/video/RJr0c4dpKxI/v-deo.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.

  • @Garfield_Minecraft
    @Garfield_Minecraft 2 місяці тому +1

    3:05 wait did you just use multiline comment for 1 line comment?

  • @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 роки тому

      ua-cam.com/video/RJr0c4dpKxI/v-deo.html
      This should solve the problem

  • @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.

  • @imranrajjad7028
    @imranrajjad7028 3 роки тому

    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  3 роки тому +1

      Thank you.
      Run this Commando:
      sudo apt install raspberrypi-kernel-headers
      This should solve the problem.

    • @imranrajjad7028
      @imranrajjad7028 3 роки тому

      @@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

  •  2 роки тому

    make: * [Makefile:4: all] Error 2

    • @johannes4gnu_linux96
      @johannes4gnu_linux96  2 роки тому

      ua-cam.com/video/RJr0c4dpKxI/v-deo.html
      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: ua-cam.com/video/RJr0c4dpKxI/v-deo.html

  • @ДаниилРоманович-р7ф

    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

  • @Eric66Eric
    @Eric66Eric Рік тому

    Thanks!