forked from wolfSSL/wolfssl
initial buildability of full libwolfssl.ko loadable kernel module for Linux via ./configure --enable-linuxkm && make.
This commit is contained in:
9
.gitignore
vendored
9
.gitignore
vendored
@ -229,6 +229,15 @@ IDE/MDK-ARM/LPC43xx/LPC43xx/
|
||||
*.gcno
|
||||
*.gcda
|
||||
*.gcov
|
||||
!linuxkm/Makefile
|
||||
/Kbuild
|
||||
linuxkm/*.ko
|
||||
linuxkm/Module.symvers
|
||||
linuxkm/built-in.a
|
||||
linuxkm/modules.order
|
||||
linuxkm/wolfcrypt
|
||||
linuxkm/libwolfssl.mod
|
||||
linuxkm/libwolfssl.mod.c
|
||||
|
||||
# MPLAB Generated Files (OS X)
|
||||
mcapi/wolfcrypt_mcapi.X/nbproject/Makefile-*
|
||||
|
@ -195,7 +195,8 @@ endif
|
||||
include scripts/include.am
|
||||
|
||||
if BUILD_LINUXKM
|
||||
SUBDIRS = . linuxkm
|
||||
export KROOT KARCH AM_CFLAGS CFLAGS AM_CCASFLAGS CCASFLAGS src_libwolfssl_la_OBJECTS
|
||||
SUBDIRS = linuxkm
|
||||
endif
|
||||
|
||||
if USE_VALGRIND
|
||||
|
13
configure.ac
13
configure.ac
@ -3381,16 +3381,18 @@ then
|
||||
[AS_HELP_STRING([--with-linux-source=PATH],[PATH to root of Linux kernel build tree])],
|
||||
[KROOT=$withval],
|
||||
[KROOT=$DEFAULT_KROOT])
|
||||
AC_SUBST([KROOT])
|
||||
|
||||
AC_DEFAULT_KERNEL_ARCH
|
||||
AC_ARG_WITH([linux-arch],
|
||||
[AS_HELP_STRING([--with-linux-arch=arch],[built arch (SRCARCH) of Linux kernel build tree])],
|
||||
[KARCH=$withval],
|
||||
[KARCH=$DEFAULT_KARCH])
|
||||
AC_SUBST([KARCH])
|
||||
|
||||
AC_DEFINE_KERNEL_KFLAGS
|
||||
|
||||
AM_CPPFLAGS="$KFLAGS $AM_CPPFLAGS"
|
||||
# AC_DEFINE_KERNEL_KFLAGS
|
||||
#
|
||||
# AM_CPPFLAGS="$KFLAGS $AM_CPPFLAGS"
|
||||
fi
|
||||
|
||||
|
||||
@ -5413,7 +5415,7 @@ AC_SUBST([LIB_STATIC_ADD])
|
||||
|
||||
# FINAL
|
||||
AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
|
||||
AC_CONFIG_FILES([Makefile wolfssl/version.h wolfssl/options.h cyassl/options.h support/wolfssl.pc rpm/spec linuxkm/Makefile])
|
||||
AC_CONFIG_FILES([Makefile wolfssl/version.h wolfssl/options.h cyassl/options.h support/wolfssl.pc rpm/spec])
|
||||
|
||||
AX_CREATE_GENERIC_CONFIG
|
||||
AX_AM_JOBSERVER([yes])
|
||||
@ -5665,8 +5667,7 @@ echo " * Small Stack: $ENABLED_SMALL_STACK"
|
||||
echo " * Linux Kernel Module: $ENABLED_LINUXKM"
|
||||
test "$ENABLED_LINUXKM" = "yes" && \
|
||||
echo " * Linux Kernel Build Root: $KROOT" && \
|
||||
echo " * Linux Kernel Build Arch: $KARCH" && \
|
||||
echo " * Linux Kernel Build Flags: $KFLAGS"
|
||||
echo " * Linux Kernel Build Arch: $KARCH"
|
||||
echo " * valgrind unit tests: $ENABLED_VALGRIND"
|
||||
echo " * LIBZ: $ENABLED_LIBZ"
|
||||
echo " * Examples: $ENABLED_EXAMPLES"
|
||||
|
29
linuxkm/Kbuild
Normal file
29
linuxkm/Kbuild
Normal file
@ -0,0 +1,29 @@
|
||||
# libwolfssl Kbuild
|
||||
|
||||
# wolfcrypto asm provokes many objtool complaints:
|
||||
# "call without frame pointer save/setup",
|
||||
# "BP used as a scratch register",
|
||||
# "indirect jump found in RETPOLINE build",
|
||||
# and "is missing an ELF size annotation"
|
||||
# see /usr/src/linux/tools/objtool/Documentation/stack-validation.txt
|
||||
OBJECT_FILES_NON_STANDARD := y
|
||||
|
||||
obj-m := libwolfssl.o
|
||||
|
||||
ifeq "$(WOLFSSL_OBJ_FILES)" ""
|
||||
$(error $$WOLFSSL_OBJ_FILES is unset.)
|
||||
endif
|
||||
|
||||
ifeq "$(WOLFSSL_CFLAGS)" ""
|
||||
$(error $$WOLFSSL_CFLAGS is unset.)
|
||||
endif
|
||||
|
||||
ifeq "$(WOLFSSL_ASFLAGS)" ""
|
||||
$(error $$WOLFSSL_ASFLAGS is unset.)
|
||||
endif
|
||||
|
||||
libwolfssl-y := $(WOLFSSL_OBJ_FILES)
|
||||
|
||||
ccflags-y := $(WOLFSSL_CFLAGS)
|
||||
|
||||
asflags-y := $(WOLFSSL_ASFLAGS)
|
38
linuxkm/Makefile
Normal file
38
linuxkm/Makefile
Normal file
@ -0,0 +1,38 @@
|
||||
all: libwolfssl.ko
|
||||
|
||||
.PHONY: libwolfssl.ko
|
||||
|
||||
ifndef MODULE_TOP
|
||||
MODULE_TOP=$(CURDIR)
|
||||
endif
|
||||
|
||||
ifndef SRC_TOP
|
||||
SRC_TOP=$(shell dirname $(MODULE_TOP))
|
||||
endif
|
||||
|
||||
ifeq "$(KROOT)" ""
|
||||
$(error $$KROOT is unset.)
|
||||
endif
|
||||
|
||||
ifeq "$(AM_CFLAGS)$(CFLAGS)" ""
|
||||
$(error $$AM_CFLAGS and $$CFLAGS are both unset.)
|
||||
endif
|
||||
|
||||
ifeq "$(AM_CCASFLAGS)$(CCASFLAGS)" ""
|
||||
$(error $$AM_CCASFLAGS and $$CCASFLAGS are both unset.)
|
||||
endif
|
||||
|
||||
ifeq "$(src_libwolfssl_la_OBJECTS)" ""
|
||||
$(error $$src_libwolfssl_la_OBJECTS is unset.)
|
||||
endif
|
||||
|
||||
WOLFSSL_CFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CFLAGS) $(CFLAGS) -Wframe-larger-than=262144
|
||||
WOLFSSL_ASFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CCASFLAGS) $(CCASFLAGS)
|
||||
WOLFSSL_OBJ_FILES=linuxkm/module_hooks.o $(patsubst %.lo, %.o, $(patsubst src/libwolfssl_la-%, src/%, $(patsubst wolfcrypt/src/src_libwolfssl_la-%, wolfcrypt/src/%, $(src_libwolfssl_la_OBJECTS))))
|
||||
|
||||
export WOLFSSL_CFLAGS WOLFSSL_ASFLAGS WOLFSSL_OBJ_FILES
|
||||
|
||||
libwolfssl.ko:
|
||||
@mkdir -p linuxkm src wolfcrypt/src
|
||||
@if [[ ! -h $(SRC_TOP)/Kbuild ]]; then ln -s $(MODULE_TOP)/Kbuild $(SRC_TOP)/Kbuild; fi
|
||||
make -C $(KROOT) M=$(MODULE_TOP) src=$(SRC_TOP)
|
@ -1,5 +0,0 @@
|
||||
EXTRA_PROGRAMS = automake_dummy
|
||||
automake_dummy_SOURCES = wolfssl_linuxkm.c
|
||||
module_DATA = wolfssl_linuxkm.o
|
||||
#include ../Makefile.common
|
||||
include Makefile.common
|
@ -1,20 +0,0 @@
|
||||
# Makefile.common
|
||||
moduledir = @moduledir@
|
||||
KERNEL_LOCATION=@kerneldir@
|
||||
KBUILD_VERBOSE = 1
|
||||
MOD_DEVDIR = $(PWD)
|
||||
|
||||
export module_DATA
|
||||
|
||||
$(module_DATA): $(automake_dummy_SOURCES)
|
||||
echo "not building kernel module yet"
|
||||
|
||||
# mv Makefile Makefile.automake
|
||||
# cp $(srcdir)/../Makefile.kernel Makefile
|
||||
# CPPFLAGS="" CFLAGS="" LDFLAGS="" \
|
||||
# $(MAKE) -C $(KROOT) \
|
||||
# ARCH="$KARCH" CC="gcc" M=$(PWD) modules\
|
||||
# KBUILD_VERBOSE=$(KBUILD_VERBOSE)
|
||||
# mv Makefile.automake Makefile
|
||||
|
||||
CLEANFILES = $(module_DATA) .$(module_DATA).flags $(module_DATA:.o=.mod.c) $(module_DATA:.o=.@kernelext@) *~
|
43
linuxkm/module_hooks.c
Normal file
43
linuxkm/module_hooks.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* http://h-wrt.com/en/mini-how-to/autotoolsSimpleModule */
|
||||
|
||||
/* src/module_hello.c */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/ssl.h>
|
||||
|
||||
static int __init wolfssl_init(void)
|
||||
{
|
||||
int ret = wolfSSL_Init();
|
||||
if (ret != WOLFSSL_SUCCESS) {
|
||||
pr_err("wolfSSL_Init() failed: %s", wc_GetErrorString(ret));
|
||||
return -ENOTRECOVERABLE;
|
||||
}
|
||||
|
||||
pr_info("wolfSSL " LIBWOLFSSL_VERSION_STRING " loaded. See https://www.wolfssl.com/ for information.\n");
|
||||
pr_info("Copyright (C) 2006-2020 wolfSSL Inc. All Rights Reserved.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
module_init(wolfssl_init);
|
||||
|
||||
static void __exit wolfssl_exit(void)
|
||||
{
|
||||
int ret = wolfSSL_Cleanup();
|
||||
if (ret != WOLFSSL_SUCCESS)
|
||||
pr_err("wolfSSL_Cleanup() failed: %s", wc_GetErrorString(ret));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
module_exit(wolfssl_exit);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_AUTHOR("https://www.wolfssl.com/");
|
||||
MODULE_DESCRIPTION("libwolfssl cryptographic and protocol facilities");
|
||||
MODULE_VERSION(LIBWOLFSSL_VERSION_STRING);
|
@ -1,28 +0,0 @@
|
||||
/* http://h-wrt.com/en/mini-how-to/autotoolsSimpleModule */
|
||||
|
||||
/* src/module_hello.c */
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
static int __init
|
||||
hello_init(void)
|
||||
{
|
||||
printk("Hello, world!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
module_init(hello_init);
|
||||
|
||||
static void __exit
|
||||
hello_exit(void)
|
||||
{
|
||||
printk("Goodbye, world!\n");
|
||||
}
|
||||
|
||||
module_exit(hello_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("noname ");
|
||||
MODULE_DESCRIPTION("\"Hello, world!\" test module");
|
||||
MODULE_VERSION("printk");
|
@ -28,14 +28,15 @@ else
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([AC_DEFINE_KERNEL_KFLAGS],
|
||||
[
|
||||
AC_MSG_CHECKING([flags for compiling objects for kernel module])
|
||||
if test -z "${KROOT}" || test -z "${KARCH}"; then
|
||||
AC_MSG_ERROR([Linux kernel configuration incomplete (KROOT=${KROOT}, KARCH=${KARCH}).])
|
||||
else
|
||||
GCC_SHORT_VERSION="$($CC -dumpversion)"
|
||||
KFLAGS="-I${KROOT}/include -I${KROOT}/include/uapi -I${KROOT}/arch/${KARCH}/include -I${KROOT}/arch/${KARCH}/include/generated -I${KROOT}/arch/${KARCH}/include/generated/uapi -I${KROOT}/arch/${KARCH}/include/uapi -I${KROOT}/tools/include -I${KROOT}/tools/arch/${KARCH}/include -I${KROOT}/tools/include/uapi -I/usr/lib/gcc/${host_cpu}-${host_vendor}-${host_os}/${GCC_SHORT_VERSION}/include"
|
||||
AC_MSG_RESULT([$KFLAGS])
|
||||
fi
|
||||
])
|
||||
dnl AC_DEFUN([AC_DEFINE_KERNEL_KFLAGS],
|
||||
dnl [
|
||||
dnl AC_MSG_CHECKING([flags for compiling objects for kernel module])
|
||||
dnl if test -z "${KROOT}" || test -z "${KARCH}"; then
|
||||
dnl AC_MSG_ERROR([Linux kernel configuration incomplete (KROOT=${KROOT}, KARCH=${KARCH}).])
|
||||
dnl else
|
||||
dnl GCC_SHORT_VERSION="$($CC -dumpversion)"
|
||||
dnl KFLAGS="-I${KROOT}/include -I${KROOT}/include/uapi -I${KROOT}/arch/${KARCH}/include -I${KROOT}/arch/${KARCH}/include/generated -I${KROOT}/arch/${KARCH}/include/generated/uapi -I${KROOT}/arch/${KARCH}/include/uapi -I${KROOT}/tools/include -I${KROOT}/tools/arch/${KARCH}/include -I${KROOT}/tools/include/uapi -I/usr/lib/gcc/${host_cpu}-${host_vendor}-${host_os}/${GCC_SHORT_VERSION}/include"
|
||||
dnl AC_MSG_RESULT([$KFLAGS])
|
||||
dnl fi
|
||||
dnl ])
|
||||
dnl
|
||||
|
Reference in New Issue
Block a user