CM4 Out of tree module build

I am attempting to build and deploy this https://github.com/balena-os/kernel-module-build as is. I’m actually attempting to build a modified mcp251x driver but I’ve backed up and the kernel-module-build project won’t build successfully on the newer versions of Balena / GCC.

I had this working a month or so ago on an older version of Balena OS. 2.75.0+rev1 but now I’m struggling.

OS Version: Balena OS 2.88.4.dev
Device Type: CM4 IO Board (custom board)

[main]     2022-03-23 15:53:13 (42.7 MB/s) - 'kernel_modules_headers.tar.gz' saved [13110176/13110176]
[main]     
[main]     make: Entering directory '/tmp/tmp.46Vy6IYLQR'
[main]       CC [M]  /usr/src/app/output/example_module_raspberrypi4-64_2.88.4.dev/hello.o
[main]     gcc: error: unrecognized command line option '-mbranch-protection=pac-ret+leaf'
[main]     gcc: error: unrecognized command line option '-fpatchable-function-entry=2'
[main]     gcc: error: unrecognized command line option '-mstack-protector-guard=sysreg'
[main]     gcc: error: unrecognized command line option '-mstack-protector-guard-reg=sp_el0'
[main]     gcc: error: unrecognized command line option '-mstack-protector-guard-offset=1376'
[main]     
[main]     scripts/Makefile.build:280: recipe for target '/usr/src/app/output/example_module_raspberrypi4-64_2.88.4.dev/hello.o' failed
[main]     make[1]: *** [/usr/src/app/output/example_module_raspberrypi4-64_2.88.4.dev/hello.o] Error 1
[main]     
[main]     make: *** [/usr/src/app/output/example_module_raspberrypi4-64_2.88.4.dev] Error 2
[main]     
[main]     Makefile:1825: recipe for target '/usr/src/app/output/example_module_raspberrypi4-64_2.88.4.dev' failed
[main]     make: Leaving directory '/tmp/tmp.46Vy6IYLQR'
[main]     Removing intermediate container 5141306ef4b7
[main]     The command '/bin/sh -c ./build.sh build --device raspberrypi4-64 --os-version "$VERSION" --src example_module' returned a non-zero code: 2
[Info]     Uploading images
[Success]  Successfully uploaded images
[Error]    Some services failed to build:
[Error]      Service: main
[Error]        Error: The command '/bin/sh -c ./build.sh build --device raspberrypi4-64 --os-version "$VERSION" --src example_module' returned a non-zero code: 2
[Info]     Built on arm01
[Error]    Not deploying release.
Remote build failed

I attempted to use update-alternatives to use GCC 9 but a I get a different error with that.

FROM balenalib/raspberrypicm4-ioboard-ubuntu:xenial

RUN apt-get update && apt-get install -y curl wget build-essential libelf-dev awscli bc flex libssl-dev python bison
COPY . /usr/src/app
WORKDIR /usr/src/app

RUN apt-get update && apt-get install software-properties-common -y
RUN add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get update && apt-get install -y gcc-9     g++-9
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9

ENV VERSION '2.88.4+rev0.dev'
RUN ./build.sh build --device raspberrypicm4-ioboard --os-version "$VERSION" --src example_module

CMD ./run.sh

That results in this


[main]     2022-03-23 16:12:10 (21.8 MB/s) - 'kernel_modules_headers.tar.gz' saved [13110471/13110471]
[main]     
[main]     make: Entering directory '/tmp/tmp.HcRkmzPMww'
[main]       CC [M]  /usr/src/app/output/example_module_raspberrypicm4-ioboard_2.88.4+rev0.dev/hello.o
[main]     Assembler messages:
[main]     Error: unknown architecture `armv8.4-a'
[main]     Error: unrecognized option -march=armv8.4-a
[main]     
[main]     scripts/Makefile.build:280: recipe for target '/usr/src/app/output/example_module_raspberrypicm4-ioboard_2.88.4+rev0.dev/hello.o' failed
[main]     make[1]: *** [/usr/src/app/output/example_module_raspberrypicm4-ioboard_2.88.4+rev0.dev/hello.o] Error 1
[main]     
[main]     make: *** [/usr/src/app/output/example_module_raspberrypicm4-ioboard_2.88.4+rev0.dev] Error 2
[main]     
[main]     Makefile:1825: recipe for target '/usr/src/app/output/example_module_raspberrypicm4-ioboard_2.88.4+rev0.dev' failed
[main]     make: Leaving directory '/tmp/tmp.HcRkmzPMww'
[main]     Removing intermediate container bbe076a369d4
[main]     The command '/bin/sh -c ./build.sh build --device raspberrypicm4-ioboard --os-version "$VERSION" --src example_module' returned a non-zero code: 2
[Info]     Uploading images
[Success]  Successfully uploaded images
[Error]    Some services failed to build:
[Error]      Service: main
[Error]        Error: The command '/bin/sh -c ./build.sh build --device raspberrypicm4-ioboard --os-version "$VERSION" --src example_module' returned a non-zero code: 2
[Info]     Built on arm06
[Error]    Not deploying release.
Remote build failed

When I attempted to build the example_module without docker on a CM4 I running the same version of Balena OS / Ubuntu:Xenial I get the same error.

Any help is greatly appreciated.

Kyle

Hi, could you please use the latest head on https://github.com/balena-os/kernel-module-build and try again? We have just merged a PR that should address this.

Hi, just following up to see if using the latest version helped.

The latest version didn’t solve the problem but your support through chat was able to point me in the direction of using a multistage build which I didn’t realize was possible. In parallel we found we were able to use the stock kernel module for MCP2515 and ended up not needing the changes we originally were attempting to include.