Giter Club home page Giter Club logo

raspberrypi-dev's Introduction

Rapid Linux Kernel Driver Development

See also Raspbian Kernel Versions, and Information about LibreELEC, Volumio and Berryboot. and Customizing Berryboot with additional drivers.

The information in this repo came largely as a collection of notes and experiences from fixing raspberrypi/linux#427 (more background respeaker/seeed-voicecard#290).

Unload / Reload without rebooting

Apparently, this useful tips is not well-known : that it is possible to unload / reload linux kernel modules by using modprobe. You can repeatedly do modprobe -r to unload, modify, modprobe -v (-v for verbose) to reload indefinitely, to test new code changes without rebooting.

Using respeaker as an example. Firstly, you need to make sure that no applications or background processes (like pulseaudio ...) are using the devices. Then you remove the devicetree overlay, before you unload the individual drivers. The steps need to be done according to dependency orders.

What depends on what, can be found by lsmod; and lsof if an application is keeping a device opened.

$ sudo /opt/vc/bin/dtoverlay -d /boot/firmware/ -R seeed-8mic-voicecard
$ sudo modprobe -r snd_soc_ac108
$ sudo modprobe -r snd_soc_seeed_voicecard
$ sudo modprobe -r snd_soc_simple_card_utils

Then you modify and build your kernel modules (in respeaker, by just doing make). uname -r shows 5.4.0-1016-raspi, my currently running kernel. You copy the newly built kernel modules into the place where they would be found, updating the kernel dependencies with depmod -a, clear the kernel ring buffer, and re-load them:

$ sudo cp *.ko /lib/modules/5.4.0-1016-raspi/updates/dkms/
$ sudo depmod -a
$ sudo dmesg -c > /dev/null
$ sudo /usr/bin/seeed-voicecard

/usr/bin/seeed-voicecard more or less just reloads the device tree overlay, which also has the side-effect of probing for all the individual drivers.

Tracing kernel driver execution

Many simple facilities are not available within the kernel. You cannot do assert(), and you cannot do printf(). Also, by its own nature, many kernel routines are executed asynchronously, triggered by external events happening somehwhat simultaneously, processed by different CPU cores, too.

  • dump_stack() does what it says: dump the call stack to the kernel ring buffer (i.e. to what dmesg shows). Useful when you cannot work out what calls what.

  • pr_info() works like printf(), but like dump_stack(), writes to the kernel ring buffer. dev_info() is a variant which prepends device name. Other variants of pr_*() and dev_*() exist. See man 2 syslog for details.

  • In kernel code, the equivalent of assert() in normal application code, is BUG_ON(). A full abort with BUG_ON(), immediately killing the current kernel thread, is very seldomly used though; instead, WARN_ON() let you do a more controlled abort. Both run dump_stack(), in addition to dumping registers' content.

  • There are more advanced technique with dynamic debugging, like kernelshark / trace-cmd (Ftrace), and dtrace (Systemtap) .

  • The idea of "attaching a debugger" to a debug-enabled kernel, requires a second machine connected by a serial (RS-232) connection, with KGDB.

Linux Device Drivers, Third Edition is the authoritative though somewhat dated reference.

raspberrypi-dev's People

Contributors

hintak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

tswizly admyly

raspberrypi-dev's Issues

Raspberry pi zero 2

Hello again sorry for the inconvenience if any

is it possible to update your berryboot version for the PI4 or the PI0123 to work with the newest raspberry pi zero 2 ??

any of the older versions i tried did not work

thanks

Request 32bit kernel Rpi4

Hello,is it possible to release a 32bit kernel for Raspberry pi 4 for berryboot since many things are not working in the 64bit kernel

thank you

BB repo update

Hello there all good ??

Sorry i dont know were else to post so i can contact you,

Im trying to build berryboot from your github repo without success

I understand that some files are outdated in your github/berryboot

is it possible to update/upgrade your github repo/files of berryboot: https://github.com/HinTak/berryboot

so the building/compiling of Berryboot wont fail???

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.