{"id":17968968,"url":"https://github.com/hintak/raspberrypi-dev","last_synced_at":"2025-04-03T21:41:06.002Z","repository":{"id":108512625,"uuid":"293633703","full_name":"HinTak/RaspberryPi-Dev","owner":"HinTak","description":"Notes and tips about kernel driver development on Raspberry Pi, much of which relates to the Seeed Studio Respeaker mic-array. Please feel free to donate at https://hintak.github.io/ if you find it useful.","archived":false,"fork":false,"pushed_at":"2023-09-28T23:07:04.000Z","size":69,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T15:51:14.414Z","etag":null,"topics":["kernel","kernel-modules","respeaker"],"latest_commit_sha":null,"homepage":"https://hintak.github.io/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HinTak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-07T21:14:24.000Z","updated_at":"2025-02-03T12:26:06.000Z","dependencies_parsed_at":"2024-10-29T15:03:58.917Z","dependency_job_id":null,"html_url":"https://github.com/HinTak/RaspberryPi-Dev","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HinTak%2FRaspberryPi-Dev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HinTak%2FRaspberryPi-Dev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HinTak%2FRaspberryPi-Dev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HinTak%2FRaspberryPi-Dev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HinTak","download_url":"https://codeload.github.com/HinTak/RaspberryPi-Dev/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247085985,"owners_count":20881157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kernel","kernel-modules","respeaker"],"created_at":"2024-10-29T14:42:00.791Z","updated_at":"2025-04-03T21:41:05.972Z","avatar_url":"https://github.com/HinTak.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rapid Linux Kernel Driver Development\n\nSee also [Raspbian Kernel Versions](Raspbian-Kernel-Releases.md), and Information about [LibreELEC, Volumio and Berryboot](LibreELEC-and-Volumio.md).\nand [Customizing Berryboot with additional drivers](Customizing-Berryboot.md).\n\nThe information in this repo came largely as a collection of notes and experiences from fixing [raspberrypi/linux#427](https://github.com/raspberrypi/linux/issues/4279) (more background [respeaker/seeed-voicecard#290](https://github.com/respeaker/seeed-voicecard/issues/290)).\n\n## Unload / Reload without rebooting\n\nApparently, this useful tips is not well-known : that it is possible to unload / reload linux kernel modules by using `modprobe`.\nYou can repeatedly do `modprobe -r` to unload, modify, `modprobe -v` (`-v` for verbose) to reload indefinitely, to test new code changes\nwithout rebooting.\n\nUsing [respeaker](https://github.com/respeaker/seeed-voicecard) as an example. Firstly, you need to make sure that\nno applications or background processes (like `pulseaudio` ...) are using the devices. Then you remove the devicetree\noverlay, before you unload the individual drivers. The steps need to be done according to dependency orders.\n\nWhat depends on what, can be found by `lsmod`; and `lsof` if an application is keeping a device opened.\n\n```\n$ sudo /opt/vc/bin/dtoverlay -d /boot/firmware/ -R seeed-8mic-voicecard\n$ sudo modprobe -r snd_soc_ac108\n$ sudo modprobe -r snd_soc_seeed_voicecard\n$ sudo modprobe -r snd_soc_simple_card_utils\n```\n\nThen you modify and build your kernel modules (in [respeaker](https://github.com/respeaker/seeed-voicecard), by just doing `make`).\n`uname -r` shows `5.4.0-1016-raspi`, my currently running kernel. You copy the newly built kernel modules into the place where\nthey would be found, updating the kernel dependencies with `depmod -a`, clear the kernel ring buffer, and re-load them:\n\n```\n$ sudo cp *.ko /lib/modules/5.4.0-1016-raspi/updates/dkms/\n$ sudo depmod -a\n$ sudo dmesg -c \u003e /dev/null\n$ sudo /usr/bin/seeed-voicecard\n```\n\n`/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.\n\n## Tracing kernel driver execution\n\nMany simple facilities are **not** available within the kernel. You cannot do `assert()`, and you cannot do `printf()`. Also, by its own nature,\nmany kernel routines are executed **asynchronously**, triggered by external events happening somehwhat simultaneously, processed by different CPU cores, too.\n\n- `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.\n\n- `pr_info()` works like `printf()`, but like `dump_stack()`, writes to the kernel ring buffer. `dev_info()` is a variant which prepends device name.\nOther variants of `pr_*()` and `dev_*()` exist. See `man 2 syslog` for details.\n\n- In kernel code, the equivalent of `assert()` in normal application code, is `BUG_ON()`. A full abort with `BUG_ON()`, immediately killing\nthe current kernel thread, is very seldomly used though; instead, `WARN_ON()` let you do a more controlled abort. Both run `dump_stack()`,\nin addition to dumping registers' content.\n\n- There are more advanced technique with dynamic debugging, like `kernelshark` / `trace-cmd` (Ftrace), and `dtrace` (Systemtap) .\n\n- The idea of \"attaching a debugger\" to a debug-enabled kernel, requires a second machine connected by a serial (RS-232) connection, with [KGDB](http://kgdb.wiki.kernel.org).\n\n[Linux Device Drivers, Third Edition](https://lwn.net/Kernel/LDD3/) is the authoritative though somewhat dated reference.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhintak%2Fraspberrypi-dev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhintak%2Fraspberrypi-dev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhintak%2Fraspberrypi-dev/lists"}