Want to add drivers for CM3 kernel

I’m a beginner on linux and I was trying to build a ubuntu core kernel with Gobinet driver for raspberry cm3.
First i use raspberry official kernel and build succeed. The driver is successful detected but the img can not install classic module and other snap application.
Then i use pi2-kernel-snap download from https://launchpad.net/pi2-kernel-snap. But the kernel freeze at starting kernel… And i do not know how to get more information to fix it.
Here is my snapcraft.yaml

name: pi2-kernel
version: 4.4.0-1090
summary: A generic amd64 kernel built from source
description: This is a generic kernel for amd64 / kvm built using x86_64_defconfig plus the minimal snappy config changes
type: kernel
      - armhf
    plugin: kernel
    source: .
    kdefconfig: [bcm2709_defconfig]
      - CONFIG_LOCALVERSION="-raspi2"
      - squashfs
    kernel-image-target: zImage
      - bcm2710-rpi-cm3

And the kernel from pi2-kernle-snap is out of date. The dts file for cm3 is broken. I don’t know how they use this kernel to build the pi2-kernel.snap.
It now freeze at starting kernel. Can someone tell me a way to print the log out so i can debug it?

https://launchpad.net/pi2-kernel-snap has definitely not been used for a long time, it was a prototype the kernel team improved a while ago (and moved somewhere else). I marked it as obsolete now (thanks for pointing it out)…

Nontheless, such a branch would not have helped you at all since it only re-packs the deb package as a snap without compiling anything…

If you need to re-compile it use:

There is a snapcraft.yaml in the tree. Cloning it to a desktop PC and simply calling snapcraft --target-arch=armhf should give you a working snap. Try to build one without patching it first so you know everything is working fine, only then start patching and re-build it…

Very thanks for the suggestion! It works fine now!

Hi, I have some new questions about the dts file. I find the dts file for CM3 are different from official raspberry kernel. And I want to use some SoC function on CM3 while running Ubuntu Core.Then should I change the dts files or just add some configs to config.txt on boot ?

there are various core config options to adjust config.txt settings:

(note that you need to replace the underscores with dahshes when you call get/set)

ogra@pi2:~$ snap set core pi-config.gpu-mem-512=true
ogra@pi2:~$ snap get core
Key        Value
pi-config  {...}
proxy      {...}
seed       {...}
ogra@pi2:~$ snap get core pi-config
Key                    Value
pi-config.gpu-mem-512  true

if you need something else you can indeed just edit config.txt

regarding the dts/dtb files, these files indeed need to match the running kernel, so they need to be created by the kernel build.

the problem with the pi’s is that the loading of the dtb files is managed by the binary blobs instead of the bootloader (like it would be on any other board) so they need to be shipped from the gadget along with broadcoms binary blobs … to test your own dtb files you can just copy the right one to /boot/uboot … likewise for overlays you can put them into /boot/uboot/overlays and point to them from config.txt

I can edit this config file and rebuild the core snap, in this way to get more pi config?
I’m confusing about the core config. If i add some config keys to picfg.go, it will append this config keys to /boot/uboot/config.txt files and broadcoms binary blobs will read this change ,then Soc change gpio’s alter. Is my understanding is correct?

core in the snap set command can also be called as snap set system ... the code and default keys live in the snapd binary. if you just want to change defaults of the config.txt file that are not covered by these settings you can directly edit the file. the file is shipped by the gadget snap, so you can also build your own gadget snap with a prior modified file to have these defaults set … and yes, if you really want you can create a PR against the snapd code to contain more keys for snap set ...

you can not re-build the core snap itself though (i mean, you can technically do that ideed, but to have a valid image that has gets security support and bugfix updates (UbuntuCore is a rolling distro after all) you need to use the official core snap).

Thanks for your patience. So i can rebuild gadget to change GPIO, and I find gpio have already defined in gadget’s snapcraft.yaml file.But only 27 pins defined in it.

interface: gpio
number: 0
interface: gpio
number: 1
interface: gpio
number: 2

interface: gpio
number: 27

But i can change gpio-30 output and input which is not defined in snapcraft.yaml. And is it possible to change Soc functions while not change dts/dtb files just change snapcraft.yaml? I find some function defined in it, but i don’t know how.
I’m not understand relationship between kernel.snap and gadget.snap. While generating other kernel.snap, it also defines about kernel-device-tree. If I snapcraft two different dts/dtb kernel and gadget, which dts/dtb will be available?

the GPIO pinout in snapcraft.yaml is based on:

there is no GPIO30 in that setup, does the kernel actually expose one ? (we can surely add it to the official gadget if we missed to cover it).

as an interim you can indeed add it to your own snapcraft.yaml and build your own gadget.

The dtb’s are built along with the kernel since they need to match the kernel configuration and binary code, when building the gadget they are actually pulled from the kernel binary in the devicetrees part of the snapcraft.yaml:

if you want to ship additional dtb’s you can put them into the gadget source tree and simply add a cp command to the end of the install scriptlet of that part.

I’m working on CM3. It has 45 pins.

Here is the pin map, on page 18. https://www.raspberrypi.org/documentation/hardware/computemodule/datasheets/rpi_DATA_CM_1p0.pdf
I’m confusing about pin-30 which is not defined in gadget but it works well. It seem that slot defined in gadget is not working so well.

slots in the gadget only apply to snap packages, if you run some local script via ssh or some such the slots are indeed not used. once you package your script/tool/app as snap package to deliver it in a product you need the slot for an interface connection of the snap though.