Compiling a single kernel module

Hi,

I’m having troubles compiling a single kernel module. I wrote a script to run these commands:

make O=~/build-dir LOCALVERSION="-tegra" tegra_defconfig

make O=~/build-dir LOCALVERSION="-tegra" menuconfig 
# set device driver (TC358743) as a module (=m), I run the following command:

make O=~/build-dir LOCALVERSION="-tegra" modules_prepare

cp /usr/src/linux-headers-4.9.201-tegra-ubuntu18.04_aarch64/kernel-4.9/Module.symvers /home/bsg/build-dir/Module.symvers

make O=~/build-dir LOCALVERSION="-tegra" -j4 --output-sync=target M=drivers/media/i2c modules

Output error:

make[1]: Entering directory '/home/bsg/build-dir'
arch/arm64/Makefile:49: LSE atomics not supported by binutils
make[1]: Leaving directory '/home/bsg/build-dir'
  LD      drivers/media/i2c/soc_camera/built-in.o
  CC      drivers/media/i2c/imx477.o
  CC      drivers/media/i2c/imx219.o
  CC      drivers/media/i2c/imx318.o
  CC      drivers/media/i2c/imx268.o
  CC      drivers/media/i2c/lc898212.o
/home/bsg/kernel/source/public/kernel/nvidia/drivers/media/i2c/lc898212.c: In function ‘lc898212_init’:
/home/bsg/kernel/source/public/kernel/nvidia/drivers/media/i2c/lc898212.c:398:56: error: pointer targets in passing argument 3 of ‘regmap_read’ differ in signedness [-Werror=pointer-sign]
  err |= regmap_read(priv->regmap16, LC898212_ADOFFSET, &data);
                                                        ^
In file included from /home/bsg/kernel/source/public/kernel/nvidia/drivers/media/i2c/lc898212.c:25:0:
/home/bsg/kernel/source/public/kernel/kernel-4.9/include/linux/regmap.h:763:5: note: expected ‘unsigned int *’ but argument is of type ‘int *’
 int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
     ^~~~~~~~~~~
cc1: all warnings being treated as errors
/home/bsg/kernel/source/public/kernel/kernel-4.9/scripts/Makefile.build:335: recipe for target 'drivers/media/i2c/lc898212.o' failed
make[2]: *** [drivers/media/i2c/lc898212.o] Error 1
make[2]: *** Waiting for unfinished jobs....
  CC      drivers/media/i2c/ov9281.o
  CC      drivers/media/i2c/ov10823.o
  CC      drivers/media/i2c/ov23850.o
In file included from /home/bsg/kernel/source/public/kernel/kernel-4.9/include/linux/trace_seq.h:4:0,
                 from /home/bsg/kernel/source/public/kernel/kernel-4.9/include/linux/trace_events.h:6,
                 from /home/bsg/kernel/source/public/kernel/kernel-4.9/include/trace/trace_events.h:19,
                 from /home/bsg/kernel/source/public/kernel/kernel-4.9/include/trace/define_trace.h:95,
                 from /home/bsg/kernel/source/public/kernel/nvidia/include/trace/events/ov23850.h:45,
                 from /home/bsg/kernel/source/public/kernel/nvidia/drivers/media/i2c/ov23850.c:35:
/home/bsg/kernel/source/public/kernel/kernel-4.9/include/linux/seq_buf.h: In function ‘seq_buf_init’:
/home/bsg/kernel/source/public/kernel/kernel-4.9/include/linux/seq_buf.h:34:12: error: pointer targets in assignment differ in signedness [-Werror=pointer-sign]
  s->buffer = buf;
            ^
cc1: all warnings being treated as errors
/home/bsg/kernel/source/public/kernel/kernel-4.9/scripts/Makefile.build:335: recipe for target 'drivers/media/i2c/ov23850.o' failed
make[2]: *** [drivers/media/i2c/ov23850.o] Error 1
/home/bsg/kernel/source/public/kernel/kernel-4.9/Makefile:1646: recipe for target '_module_drivers/media/i2c' failed
make[1]: *** [_module_drivers/media/i2c] Error 2
Makefile:171: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

It looks like it’s successful in building some modules but then finds syntax errors in others. This is strange to me because with identical source files I can run:

make O=~/build-dir LOCALVERSION="-tegra" -j4 --output-sync=target modules

and then immediately run

make O=~/build-dir LOCALVERSION="-tegra" -j4 --output-sync=target M=drivers/media/i2c modules

and it builds/compiles all successfully.

What else do I need to add to my script to make this work? What else differs between the make modules and make M=directory?

Thanks
Jamie

hello JamieBasil,

please revise your code to address the failure.
according to error reports, all warnings being treated as errors; those compile failures were trigger by this flag, -Werror,
specifically, you’re passing an integer to the function which expect an unsigned variable.

Thanks

I find these errors strange because I’m compiling original Nvidia Jetson nano kernel source code that I didn’t modify. This same source code compiles successfully when I build all modules with make O=~/build-dir LOCALVERSION="-tegra" -j4 --output-sync=target modules so this should also compile error free when trying to build modules in a single directory, right?

Another strange thing I noticed is that if I run…

make O=~/build-dir LOCALVERSION="-tegra" -j4 --output-sync=target M=drivers/media/i2c modules

…two times in a row, the first time I get source code errors as I mentioned in first post and then the second time it builds successfully.

make[1]: Entering directory '/home/bsg/build-dir'

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

make[1]: Leaving directory '/home/bsg/build-dir'
  CC [M]  drivers/media/i2c/imx185_v1.o
  CC [M]  drivers/media/i2c/imx185.o
  CC [M]  drivers/media/i2c/imx274.o
  CC [M]  drivers/media/i2c/tc358743.o
  CC [M]  drivers/media/i2c/ov5693.o
  CC [M]  drivers/media/i2c/tc358840.o
make[1]: Entering directory '/home/bsg/build-dir'
  Building modules, stage 2.
make[1]: Leaving directory '/home/bsg/build-dir'
  MODPOST 6 modules
  CC      drivers/media/i2c/imx185_v1.mod.o
  CC      drivers/media/i2c/ov5693.mod.o
  CC      drivers/media/i2c/imx185.mod.o
  LD [M]  drivers/media/i2c/imx185.ko
  CC      drivers/media/i2c/imx274.mod.o
  LD [M]  drivers/media/i2c/imx185_v1.ko
  LD [M]  drivers/media/i2c/imx274.ko
  LD [M]  drivers/media/i2c/ov5693.ko
  CC      drivers/media/i2c/tc358743.mod.o
  LD [M]  drivers/media/i2c/tc358743.ko
  CC      drivers/media/i2c/tc358840.mod.o
  LD [M]  drivers/media/i2c/tc358840.ko

How is this happening?

Any help appreciated.

Thanks
Jamie

hello JamieBasil,

please check Kernel Customization chapter to build the NVIDIA Kernel.
we had validate the process with r32.6.1 public sources, you shall configure toolchain to complete building the sources.

I figured it out. I got it to run error free by running make modules.builtin before make modules_prepare

So the order of command execution that runs successfully for me is:

make O=~/build-dir LOCALVERSION="-tegra" modules.builtin
make O=~/build-dir LOCALVERSION="-tegra" modules_prepare
make O=~/build-dir LOCALVERSION="-tegra" -j4 --output-sync=target M=drivers/media/i2c modules
1 Like