Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: michnixweiss on January 20, 2022, 03:35:14 PM

Title: [Solved] Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 20, 2022, 03:35:14 PM
Hey everybody

I am using a Raspi Zero W with piCore 13.1.0 - 5.10.77 Kernel
I am trying to build a driver for a waveshare wm8960 sound hat. Therefor I did the following:
Code: [Select]
tce-load -wi compiletc
tce-load -wi openssl-dev bc   #needed this cause getting failure later on
Code: [Select]
make mrproper
Code: [Select]
modprobe config
zcat /proc/config.gz > .config
Code: [Select]
make oldconfig
make prepare
make modules_prepare
so the Kernel src should be ready to start!?
Code: [Select]
git clone https://github.com/waveshare/WM8960-Audio-HAT
Code: [Select]
make -C /path/to/kernelsrc M=/path/to/driversrc modules
Code: [Select]
insmod snd-soc-wm8960.ko
Code: [Select]
invalid module format
I have done a lot of research and spend hours to get so far. Cause the wiki is kind of broken "User authentication is unavailable Permission denied" and like described here
 http://forum.tinycorelinux.net/index.php?topic=22019.0 (http://forum.tinycorelinux.net/index.php?topic=22019.0)
Its realy an obstacle challenge to get into this forum...
So now I am a little frustrated.

What am I missing / doing wrong

Thanks a lot
Title: Re: Build Kernel Modul on 5.10.77
Post by: Paul_123 on January 20, 2022, 04:26:38 PM
Its not going to work right without System.map and Module_symvers

@Bela

Can you post these files for 5.10.77?

Once you have those files, prepare the kernel source with "make modules_prepare"    (mproper cleans the tree, If you run that, make sure you add the config, System.map and Modules.symvers after you run it)
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 20, 2022, 04:34:38 PM
Hi michnixweiss
Welcome to the forum.

With regards to the Wiki, see this:
http://forum.tinycorelinux.net/index.php/topic,25220.0.html
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 21, 2022, 03:55:47 AM
Hey @Rich,
Thx for the Link.
Hey @Paul_123,
Ok I will wait for the files. Is this dokumented somewhere, cause I only found the post from @Juanito to prepare the src
http://forum.tinycorelinux.net/index.php?topic=24946.0 (http://forum.tinycorelinux.net/index.php?topic=24946.0)
and adopted it.
Title: Re: Build Kernel Modul on 5.10.77
Post by: Paul_123 on January 21, 2022, 06:37:43 AM
Yes, that works.  Notice the files are copied after mproper.
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 21, 2022, 10:06:18 AM
Hi michnixweiss
I cobbled together some instructions a while back:
http://forum.tinycorelinux.net/index.php/topic,24436.msg154978.html#msg154978
They include links to where the information came from.
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 22, 2022, 07:54:34 AM
Read the links and links in the posts. And its not clear for me...
From the links I guess this is the right order (sry if this is a stupid question)
Code: [Select]
cd /path/to/kernelsrc
make mrproper
cp ../5.10.77-piCore_.config ./.config
make oldconfig
make prepare
make modules_prepare
cp ../5.10.16-piCore_Module.symvers ./Module.symvers
cd /driver/src
make
At which point do I have to copy the System.map and cp module.symvers befor or after modules_prepare?

Will some post the files here or upload them to http://www.tinycorelinux.net/13.x/armv6/releases/RPi/src/kernel/ (http://www.tinycorelinux.net/13.x/armv6/releases/RPi/src/kernel/) ?
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 22, 2022, 03:03:30 PM
Hi michnixweiss
Sorry, I don't know why System.map is necessary.

... Will some post the files here or upload them to ...
They will be uploaded to live with the other source files.
Title: Re: Build Kernel Modul on 5.10.77
Post by: Paul_123 on January 22, 2022, 07:06:19 PM
Not sure Rich, but for sure only using the .config is not sufficient with arm.
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 22, 2022, 08:34:27 PM
Hi Paul_123
This is the message someone trying to build igb drivers received when  Module.symvers  was missing:
Code: [Select]
----- Snip -----

  WARNING: Symbol version dump ./Module.symvers
           is missing; modules will have no dependencies and modversions.

 ----- Snip -----

Title: Re: Build Kernel Modul on 5.10.77
Post by: bmarkus on January 23, 2022, 12:21:59 AM
.config, Module.symvers and System.map files uploaded to the server.
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 23, 2022, 03:34:14 AM
Thanks a lot, I will try again with the files and post the result.
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 23, 2022, 10:07:35 AM
...ok, I got an other message, but its not working anyway.
Code: [Select]
tc@box:/mnt/mmcblk0p2/BUILD/WM8960-Audio-HAT sudo insmod snd-soc-wm8960.ko
insmod: can't insert 'snd-soc-wm8960.ko': unknown symbol in module, or unknown parameter
More Details
Code: [Select]
tc@box:/mnt/mmcblk0p2/BUILD/WM8960-Audio-HAT dmesg  tail
[ 8843.200270] snd_soc_wm8960: loading out-of-tree module taints kernel.
[ 8843.201066] snd_soc_wm8960: Unknown symbol snd_soc_component_read (err -2)
[ 8843.201119] snd_soc_wm8960: Unknown symbol snd_soc_put_enum_double (err -2)
[ 8843.201172] snd_soc_wm8960: Unknown symbol snd_soc_component_write (err -2)
[ 8843.201223] snd_soc_wm8960: Unknown symbol devm_snd_soc_register_component (err -2)
[ 8843.201285] snd_soc_wm8960: Unknown symbol __devm_regmap_init_i2c (err -2)
[ 8843.201326] snd_soc_wm8960: Unknown symbol snd_soc_get_enum_double (err -2)
[ 8843.202134] snd_soc_wm8960: Unknown symbol snd_soc_info_volsw (err -2)
[ 8843.202241] snd_soc_wm8960: Unknown symbol snd_soc_unregister_component (err -2)
[ 8843.202293] snd_soc_wm8960: Unknown symbol snd_soc_dapm_put_volsw (err -2)
[ 8843.202342] snd_soc_wm8960: Unknown symbol snd_soc_add_component_controls (err -2)
[ 8843.202392] snd_soc_wm8960: Unknown symbol snd_soc_dapm_add_routes (err -2)
[ 8843.202432] snd_soc_wm8960: Unknown symbol snd_soc_info_enum_double (err -2)
[ 8843.202478] snd_soc_wm8960: Unknown symbol snd_soc_get_volsw (err -2)
[ 8843.202515] snd_soc_wm8960: Unknown symbol snd_soc_put_volsw (err -2)
[ 8843.202553] snd_soc_wm8960: Unknown symbol snd_soc_component_update_bits (err -2)
[ 8843.202590] snd_soc_wm8960: Unknown symbol snd_soc_dapm_new_controls (err -2)
[ 8843.202662] snd_soc_wm8960: Unknown symbol snd_soc_dapm_get_volsw (err -2)
[ 8843.202717] snd_soc_wm8960: Unknown symbol snd_soc_params_to_bclk (err -2)
[ 8843.204619] snd_soc_wm8960: Unknown symbol snd_soc_component_read (err -2)
[ 8843.204663] snd_soc_wm8960: Unknown symbol snd_soc_put_enum_double (err -2)
[ 8843.204699] snd_soc_wm8960: Unknown symbol snd_soc_component_write (err -2)
[ 8843.204734] snd_soc_wm8960: Unknown symbol devm_snd_soc_register_component (err -2)
[ 8843.204779] snd_soc_wm8960: Unknown symbol __devm_regmap_init_i2c (err -2)
[ 8843.204806] snd_soc_wm8960: Unknown symbol snd_soc_get_enum_double (err -2)
[ 8843.204841] snd_soc_wm8960: Unknown symbol snd_soc_info_volsw (err -2)
[ 8843.204897] snd_soc_wm8960: Unknown symbol snd_soc_unregister_component (err -2)
[ 8843.204929] snd_soc_wm8960: Unknown symbol snd_soc_dapm_put_volsw (err -2)
[ 8843.204963] snd_soc_wm8960: Unknown symbol snd_soc_add_component_controls (err -2)
[ 8843.204997] snd_soc_wm8960: Unknown symbol snd_soc_dapm_add_routes (err -2)
[ 8843.205025] snd_soc_wm8960: Unknown symbol snd_soc_info_enum_double (err -2)
[ 8843.205056] snd_soc_wm8960: Unknown symbol snd_soc_get_volsw (err -2)
[ 8843.205084] snd_soc_wm8960: Unknown symbol snd_soc_put_volsw (err -2)
[ 8843.205109] snd_soc_wm8960: Unknown symbol snd_soc_component_update_bits (err -2)
[ 8843.205135] snd_soc_wm8960: Unknown symbol snd_soc_dapm_new_controls (err -2)
[ 8843.205184] snd_soc_wm8960: Unknown symbol snd_soc_dapm_get_volsw (err -2)
[ 8843.205220] snd_soc_wm8960: Unknown symbol snd_soc_params_to_bclk (err -2)
The command is modified, cause I cannot post $ and | in code tags ...!?
Is this a problem of the kernel source, my commands or driver?
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 23, 2022, 10:45:34 AM
Hi michnixweiss
It looks like your new modules needs some dependencies loaded.

Place your driver where the system can find it:
Code: [Select]
sudo cp snd-soc-wm8960.ko /lib/modules/$KERNEL/kernelwhere  $KERNEL  is the result of  uname -r

Update the module dependencies:
Code: [Select]
sudo /sbin/depmod -a
Now try loading the module again:
Code: [Select]
sudo modprobe snd-soc-wm8960.ko
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 23, 2022, 05:05:51 PM
Hi Rich,

to get it persistent for future i created an extension
Code: [Select]
newTCZ/usr/local/lib/modules/5.10.77-piCore/kernel/sound/soc/bcm/snd-soc-wm8960-soundcard.ko
newTCZ/usr/local/lib/modules/5.10.77-piCore/kernel/sound/soc/codecs/snd-soc-wm8960.ko
mksquashfs newTCZ wm8960.tcz
mv wm8960.tcz /mnt/mmcblk0p2/tce/optional/
tce-load -i wm8960.tcz
Modified command cause I also cannot post   C o p y  or  c p
then tried your
Code: [Select]
sudo /sbin/depmod -a
which exits without any output
Modprobe also exits without output
Code: [Select]
sudo modprobe snd-soc-wm8960.ko
The same command with fullpath gives an output
Code: [Select]
sudo modprobe /usr/local/lib/modules/5.10.77-picore/kernel/sound/soc/codecs/snd-soc-wm8960.ko
modprobe: module /usr/local/lib/modules/5.10.77-picore/kernel/sound/soc/codecs/snd-soc-wm8960.ko not found in modules.dep
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 23, 2022, 05:16:30 PM
Hi michnixweiss
...
Code: [Select]
sudo /sbin/depmod -a
which exits without any output
Modprobe also exits without output ...
No output means no error.

If you want to confirm it's loaded, see if it shows up in this command:
Code: [Select]
lsmod
Quote
to get it persistent for future i created an extension ...
Kudos on figuring out how to package it.
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 23, 2022, 08:45:22 PM
Hi michnixweiss
...
Code: [Select]
----- Snip -----
tce-load -i wm8960.tcz
----- Snip -----
Code: [Select]
sudo /sbin/depmod -a
...
Just one more thing. Since you packaged the modules, you don't need to depmod. When you load your extension,
tce-load  checks the extension for modules and runs  depmod  for you.
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 29, 2022, 11:05:03 AM
Many thanks @Rich,

I build my extension with the files needed (I think so).
Now so far:
Code: [Select]
aplay -l
card 0: wm8960soundcard [wm8960-soundcard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0 [bcm2835-i2s-wm8960-hifi wm8960-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
aplay -D hw:0,0 piano2.wav
No error message, but I am getting no sound from the speaker nor the headphone...
The only thing unknown so far is where to but the asound.state so that alsa is loading it. But this is not the main problem I think!?

Can I ask this here or open a new thread for alsa?
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 29, 2022, 01:07:43 PM
Hi michnixweiss
My guess is some path(s) is/are muted.

This is a post I wrote on setting up ALSA:
http://forum.tinycorelinux.net/index.php/topic,22145.msg138620.html#msg138620
Make sure your driver is loaded first. Then, follow the instructions in the post. The extensions must be loaded in
the order listed. Rearrange their order in your  onboot.lst  and reboot. Then continue from step 4.

If you still get no audio, start the alsamixergui and try some of the controls.
Title: Re: Build Kernel Modul on 5.10.77
Post by: Paul_123 on January 29, 2022, 02:31:32 PM
Have you done everything shown on their github site.   While you cannot use the provided install and service files, you should do everything they do manually.

https://github.com/waveshare/WM8960-Audio-HAT

1) Driver built -  This appears to be ok
2) dtbo installed in /mnt/mmcblk0p1/overlays
3) in the boot config.txt did you add dtoverlay=wm8960-soundcard
4) Assume you have also enabled both i2c and i2s interfaces.
5) Add the asound.conf to /etc  (Also add etc/asound.conf to /opt/.filetool.lst)
6) Copy the provided asound.state to /var/lib/asla/asound.state  (Make sure to add this file to the backup list too)

Then during boot, you will need to wait for the card to be recognized first
Then restore the asound state.

Let me know if you need more direction, but just follow what they do on github.  And convert what they to do tinycore methodology.


Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 29, 2022, 03:11:17 PM
Thx @Rich.
Thx @Paul_123, I figured it out before reading your post.
Your point 6 was my problem. Like written before it was not clear for me where to put the asound.state and unmute with alsamixer does not do the trick.
Trial and error brings it up
Code: [Select]
sudo alsactl restore
alsactl: load_state:1683: Cannot open /var/lib/alsa/asound.state for reading: No such file or directory
For me the documentation is a bit confusing. For example: the link in the post of @Rich to alsa - which is not so old - isn't correct anymore.
There is no alsa-config.tcz (anymore). Comparing the alsa.tcz.list and alsa-config.tcz.list (from 4.x) with the alsa.tcz.list (from 13.x) seems for me, that its in one extension now. Also the described path usr/local/etc/alsa/asound.state seems to be the wrong for now.
And it is really annoying that I cannot post some things - tried to quote the "echo..." part. Is it a bug or because I am a newbie?
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 29, 2022, 04:30:14 PM
Hi michnixweiss
I think the ARM version may have been configure differently. The  .info  file for TC13 x86_64 still lists  asound.state
being saved in   /usr/local/etc/alsa/asound.state:
http://tinycorelinux.net/13.x/x86_64/tcz/alsa.tcz.info

... And it is really annoying that I cannot post some things - tried to quote the "echo..." part. Is it a bug or because I am a newbie?
It's the forum. Sometimes it doesn't like certain words or punctuation. The other day I couldn't write  /etc/hosts , today
it's perfectly fine with it.
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 31, 2022, 04:00:48 PM
Last point (I hope) to the sound HAT:
How do I restore the asound.state at reboot?
I stored the working var/lib/alsa/asound.state with /opt/.filetool.lst

I tried in bootlocal.sh
Code: [Select]
/usr/local/sbin/alsactl restore
and
/usr/local/sbin/alsactl -f /home/tc/asound.state restore
/usr/local/bin/speaker-test [-Ddefault:1] -c2 -t wav -l1 #to proof its working
which didn't work,
so I tried the same with /usr/bin/sudo in ~/.X.d/alsa
which didn't work either...
Title: Re: Build Kernel Modul on 5.10.77
Post by: Paul_123 on January 31, 2022, 04:10:44 PM
bootlocal.sh will run way too soon.  You need to wait for the kernel to recognize the card first.   Then use alsactl to restore.
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on January 31, 2022, 05:47:26 PM
bootlocal.sh will run way too soon.  You need to wait for the kernel to recognize the card first.   Then use alsactl to restore.
Thanks for the hint, but I got a "wifi autoconnect" in it which is working fine
Code: [Select]
/usr/local/bin/wifi.sh -a 2>&1 > /tmp/wifi.log
Is it because its a HAT and wifi onboard or does the wifi.sh wait for the wlan to be ready?
From the corebook the .X.d is described as the "final part of the boot process" so shouldn't this had to work?

To make it easy I would create a start script which checks via lsmod if the wm8960 is loaded or is there an other way!?
Title: Re: Build Kernel Modul on 5.10.77
Post by: Paul_123 on January 31, 2022, 07:31:15 PM
Use a while loop.   Look at /proc/asound   Or just run aplay -L.  And watch for your card.

Some cards are really picky at boot.  I will often, wait for the card, then load the state twice
Title: Re: Build Kernel Modul on 5.10.77
Post by: Rich on January 31, 2022, 09:00:08 PM
Hi michnixweiss
Assuming your card is  wm8960soundcard , something like this should work:
Code: [Select]
while true
do
    s_leep 1
    aplay -l | grep -q wm8960soundcard
    [ $? == 0 ] && break
done
/usr/local/sbin/alsactl restore
Remove the underscore from  s_leep. Sorry, forum error.

Place it in its own script (init8960.sh for example) and launch it in the background.
Title: Re: Build Kernel Modul on 5.10.77
Post by: michnixweiss on February 01, 2022, 06:01:57 PM
Thx a lot for the help. Works like a charm now.
Main problem was in front of the RPi...
I started a daemon in the bootlocal.sh without init script and forgot the "&" at the end of the line...
How can I Set this to SOLVED?
Title: Re: [Solved] Build Kernel Modul on 5.10.77
Post by: Rich on February 01, 2022, 07:49:42 PM
Hi michnixweiss
... How can I Set this to SOLVED?
Easy, just ask.  :)
Title: Re: Build Kernel Modul on 5.10.77
Post by: chinatefl on February 02, 2023, 07:55:46 PM
how to find wm8960.tcz .  The software list does not exist。

Hi michnixweiss
...
Code: [Select]
----- Snip -----
tce-load -i wm8960.tcz
----- Snip -----
Code: [Select]
sudo /sbin/depmod -a
...
Just one more thing. Since you packaged the modules, you don't need to depmod. When you load your extension,
tce-load  checks the extension for modules and runs  depmod  for you.
Title: Re: [Solved] Build Kernel Modul on 5.10.77
Post by: Rich on February 02, 2023, 09:15:03 PM
Hi chinatefl
After michnixweiss compiled the driver, he packaged it as a .tcz for
personal use as shown here:
https://forum.tinycorelinux.net/index.php/topic,25499.msg163412.html#msg163412