diff --git a/Makefile b/Makefile index f206859..8068984 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ KERNEL_MODULES := /lib/modules/$(TARGET) KERNEL_BUILD := $(KERNEL_MODULES)/build SYSTEM_MAP := /boot/System.map-$(TARGET) DRIVER := asustor asustor_it87 asustor_gpio_it87 -DRIVER_VERSION := v0.1 +DRIVER_VERSION := v0.2 #DRIVER_VERSION ?= $(shell git describe --long) # DKMS @@ -17,6 +17,8 @@ asustor_gpio_it87_DEST_DIR = $(KERNEL_MODULES)/kernel/drivers/gpio obj-m := $(patsubst %,%.o,$(DRIVER)) obj-ko := $(patsubst %,%.ko,$(DRIVER)) +# asustor.o is built from two source files for license reasons +asustor-y := asustor_main.o asustor_gpl2.o all: modules @@ -38,8 +40,9 @@ dkms: @mkdir -p $(DKMS_ROOT_PATH_ASUSTOR) @echo "obj-m := asustor.o" >>$(DKMS_ROOT_PATH_ASUSTOR)/Makefile @echo "obj-ko := asustor.ko" >>$(DKMS_ROOT_PATH_ASUSTOR)/Makefile + @echo "asustor-y := asustor_main.o asustor_gpl2.o" >>$(DKMS_ROOT_PATH_ASUSTOR)/Makefile @cp dkms.conf $(DKMS_ROOT_PATH_ASUSTOR) - @cp asustor.c $(DKMS_ROOT_PATH_ASUSTOR) + @cp asustor_main.c asustor_gpl2.c $(DKMS_ROOT_PATH_ASUSTOR) @sed -i -e '/^PACKAGE_VERSION=/ s/=.*/=\"$(DRIVER_VERSION)\"/' $(DKMS_ROOT_PATH_ASUSTOR)/dkms.conf @mkdir -p $(DKMS_ROOT_PATH_ASUSTOR_IT87) diff --git a/asustor_gpl2.c b/asustor_gpl2.c new file mode 100644 index 0000000..bce740a --- /dev/null +++ b/asustor_gpl2.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * asustor_gpl2.c - Functions used by asustor_main.c (for asustor.ko) that were copied from the + * Linux kernel and are licensed under GPLv2 ONLY, instead of GPLv2 or later. + */ + +#include + +bool asustor_dmi_matches(const struct dmi_system_id *dmi); + +/** + * dmi_matches - check if dmi_system_id structure matches system DMI data + * @dmi: pointer to the dmi_system_id structure to check + */ +// copied from dmi_matches() in Linux 6.11.2 drivers/firmware/dmi_scan.c where it's private (static) +// with only one small change (dmi_val = dmi_get_system_info(s) instead of dmi_ident[s]) +bool asustor_dmi_matches(const struct dmi_system_id *dmi) +{ + int i; + const char *dmi_val; + + for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) { + int s = dmi->matches[i].slot; + if (s == DMI_NONE) + break; + if (s == DMI_OEM_STRING) { + /* DMI_OEM_STRING must be exact match */ + const struct dmi_device *valid; + + valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, + dmi->matches[i].substr, NULL); + if (valid) + continue; + } else if ((dmi_val = dmi_get_system_info(s)) != NULL) { + if (dmi->matches[i].exact_match) { + if (!strcmp(dmi_val, dmi->matches[i].substr)) + continue; + } else { + if (strstr(dmi_val, dmi->matches[i].substr)) + continue; + } + } + + /* No match */ + return false; + } + return true; +} diff --git a/asustor.c b/asustor_main.c similarity index 94% rename from asustor.c rename to asustor_main.c index 7580dd3..91f2188 100644 --- a/asustor.c +++ b/asustor_main.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * asustor.c - Platform driver for ASUSTOR NAS hardware + * asustor_main.c - main part of asustor.ko, a platform driver for ASUSTOR NAS hardware + * (the other part is in asustor_gpl2.c which is GPL-2.0-only) * * Copyright (C) 2021 Mathias Fredriksson */ @@ -408,45 +409,6 @@ static struct gpio_chip *find_chip_by_name(const char *name) } #endif -/** - * dmi_matches - check if dmi_system_id structure matches system DMI data - * @dmi: pointer to the dmi_system_id structure to check - */ -// copied from dmi_matches() in Linux 6.11.2 drivers/firmware/dmi_scan.c where it's private (static) -// with only one small change (dmi_val = dmi_get_system_info(s) instead of dmi_ident[s]) -static bool dmi_matches(const struct dmi_system_id *dmi) -{ - int i; - const char *dmi_val; - - for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) { - int s = dmi->matches[i].slot; - if (s == DMI_NONE) - break; - if (s == DMI_OEM_STRING) { - /* DMI_OEM_STRING must be exact match */ - const struct dmi_device *valid; - - valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, - dmi->matches[i].substr, NULL); - if (valid) - continue; - } else if ((dmi_val = dmi_get_system_info(s)) != NULL) { - if (dmi->matches[i].exact_match) { - if (!strcmp(dmi_val, dmi->matches[i].substr)) - continue; - } else { - if (strstr(dmi_val, dmi->matches[i].substr)) - continue; - } - } - - /* No match */ - return false; - } - return true; -} - // How many PCI(e) devices with given vendor/device IDs exist in this system? static int count_pci_device_instances(unsigned int vendor, unsigned int device) { @@ -492,6 +454,10 @@ static bool pci_devices_match(const struct asustor_driver_data *sys) return true; } +// returns true if dmi->matches match on the current system +// implemented in asustor_gpl2.c +extern bool asustor_dmi_matches(const struct dmi_system_id *dmi); + // find out which ASUSTOR system this is, based on asustor_systems[], including // their linked asustor_driver_data's pci_matches // returns NULL if this isn't a known system @@ -509,7 +475,7 @@ static const struct dmi_system_id *find_matching_asustor_system(void) break; } - if (!dmi_matches(sys)) { + if (!asustor_dmi_matches(sys)) { continue; }