-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
248 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
TARGET = pisugar_3_battery | ||
|
||
obj-m += pisugar_3_battery.o | ||
|
||
KERN_VER=$(shell uname -r) | ||
KERN_VER = $(shell uname -r) | ||
|
||
SOURCEDIR = $(shell pwd) | ||
BUILDDIR = $(shell pwd)/build | ||
|
||
all: | ||
make -C /lib/modules/$(KERN_VER)/build M=$(shell pwd) modules | ||
make -C /lib/modules/$(KERN_VER)/build M=$(SOURCEDIR) modules | ||
|
||
clean: | ||
rm -f *.cmd *.ko *.o Module.symvers modules.order *.mod.c | ||
|
||
rm -f *.cmd *.ko *.o Module.symvers modules.order *.mod.c .pisugar_3_battery.* .modules.* .Module.symvers.* pisugar_3_battery.mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,63 @@ | ||
# PiSugar Linux kernel modules | ||
|
||
Make kernel modules: | ||
Linux kernel modules for PiSugar 3. | ||
|
||
## Preparing for building RPI kernel module | ||
|
||
### Linux distributions with kernel symbols | ||
|
||
Congratulations if your PI is running a linux distribution that has `/lib/modules/$(uname -r)/build/` directory, e.g. ubuntu-server, you don't need to manually build RPI kernel, and that will save a lot of time. | ||
|
||
Install linux-headers | ||
```shell | ||
sudo apt install linux-headers-$(uname -r) | ||
``` | ||
|
||
### Raspberry Pi OS | ||
|
||
As kernel symbols is not included in Raspberry Pi OS (no `/lib/modules/$(uname -r)/build`), so you need to compile the kernel and generate the kernel symbols by youself. | ||
|
||
To build the kernel, see official doc: https://www.raspberrypi.com/documentation/computers/linux_kernel.html | ||
|
||
** It seems like the precompiled symbols could be downloaded from [here](https://github.com/raspberrypi/firmware), but I could not figure out the correct steps. ** | ||
|
||
First, get RPI OS tag, e.g. 1.20230405 | ||
```shell | ||
dpkg -l | grep kernel | ||
``` | ||
|
||
Clone kernel repository, and create a symbol link | ||
```shell | ||
git clone --depth 1 --branch <PI_OS_TAG> https://github.com/raspberrypi/linux.git | ||
sudo ln -s "$(pwd)/linux" /usr/src/linux | ||
``` | ||
|
||
Build RPI kernel. | ||
|
||
When it is done, copy and rename `linux` folder to PI `/lib/modules/$(uname -r)/build`. | ||
|
||
## Compiling kernel module | ||
|
||
Clone this repository, make kernel modules: | ||
|
||
make | ||
|
||
Load module: | ||
|
||
sudo insmod pisugar_3_battery.ko | ||
# or | ||
sudo insmod pisugar_3_battery.ko i2c_bus=1 i2c_addr=0x57 | ||
|
||
Then you will see extra battry files in `/sys/class/power_supply` | ||
|
||
ls /sys/class/power_supply | ||
|
||
Remove module: | ||
|
||
sudo rmmod pisugar_3_battery.ko | ||
|
||
Now, you can enable [battery monitor plugin](https://github.com/raspberrypi-ui/lxplug-ptbatt). | ||
|
||
## License | ||
|
||
GPL |
Oops, something went wrong.