Re: [OE-core] [PATCH 1/2] kmod: Add an exclude directive to depmod

Jose Quaresma
2022-03-31T08:21:30Z

[-- Attachment #1: Type: text/plain, Size: 9033 bytes --]

Hi Saul,

Saul Wold <Saul.Wold@windriver.com> escreveu no dia quarta, 30/03/2022 à(s)
23:12:

> This adds a new configuration directive to depmod that causes
> depmod to exclude a give path entry like .debug.
>
> kernel-dbg provides the modules .debug/<module>.ko files and
> when installed either directly or when dbg-pkgs are selected
> this can cause depmod to fail.
>
> This patch will be submitted to upstream kmod.
>
> Signed-off-by: Saul Wold <saul.wold@windriver.com>
> ---
> .../kmod/depmodwrapper-cross_1.0.bb | 3 +
> ...dd-support-for-excluding-a-directory.patch | 158 ++++++++++++++++++
> meta/recipes-kernel/kmod/kmod_29.bb | 4 +
> 3 files changed, 165 insertions(+)
> create mode 100644
> meta/recipes-kernel/kmod/kmod/0001-depmod-Add-support-for-excluding-a-directory.patch
>
> diff --git a/meta/recipes-kernel/kmod/depmodwrapper-cross_1.0.bb
> b/meta/recipes-kernel/kmod/depmodwrapper-cross_1.0.bb
> index 04fc14a6d21..aa23ba41276 100644
> --- a/meta/recipes-kernel/kmod/depmodwrapper-cross_1.0.bb
> +++ b/meta/recipes-kernel/kmod/depmodwrapper-cross_1.0.bb
> @@ -16,6 +16,9 @@ do_populate_sysroot[depends] = ""
>
> do_install() {
> install -d ${D}${bindir_crossscripts}/
> + install -d ${D}${sysconfdir}/depmod.d/
> +
> + echo "exclude .debug" > ${D}${sysconfdir}/depmod.d/exclude.conf
>
> cat > ${D}${bindir_crossscripts}/depmodwrapper << EOF
> #!/bin/sh
> diff --git
> a/meta/recipes-kernel/kmod/kmod/0001-depmod-Add-support-for-excluding-a-directory.patch
> b/meta/recipes-kernel/kmod/kmod/0001-depmod-Add-support-for-excluding-a-directory.patch
> new file mode 100644
> index 00000000000..3f16cdf0574
> --- /dev/null
> +++
> b/meta/recipes-kernel/kmod/kmod/0001-depmod-Add-support-for-excluding-a-directory.patch
> @@ -0,0 +1,158 @@
> +From 8bc07c3ba3a412bd6bb94ad8bad0d76801ec2c9f Mon Sep 17 00:00:00 2001
> +From: Saul Wold <saul.wold@windriver.com>
> +Date: Tue, 22 Mar 2022 12:11:45 -0700
> +Subject: [PATCH] depmod: Add support for excluding a directory
> +
> +This adds support to depmod to enable a new exclude directive in
> +the depmod.d/exclude.conf configuration file. Currently depmod
> +already excludes directories named source or build. This change
> +will allow additional directories like .debug to be excluded also
> +via a new exclude directive.
> +
> +depmod.d/exclude.conf example:
> +exclude .debug
> +
> +Upstream-Status: Submitted
> +
> +Signed-off-by: Saul Wold <saul.wold@windriver.com>
> +
> +%% original patch: 0001-depmod-Add-support-for-excluding-a-directory.patch
>

This line comes from devtool but is not needed.

Jose

> +---
> + man/depmod.d.xml | 14 +++++++++++++
> + tools/depmod.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
> + 2 files changed, 68 insertions(+)
> +
> +diff --git a/man/depmod.d.xml b/man/depmod.d.xml
> +index b315e93..9ab790a 100644
> +--- a/man/depmod.d.xml
> ++++ b/man/depmod.d.xml
> +@@ -131,6 +131,20 @@
> +
> +
> + </varlistentry>
> ++ <varlistentry>
> ++ <term>external <replaceable>excludedir</replaceable>
> ++ </term>
> ++
> ++
> ++ This specifies the trailing directories that will be excluded
> ++ during the search for kernel modules.
> ++
> ++
> ++ The <replaceable>excludedir</replaceable> the trailing
> directory
> ++ to exclude
> ++
> ++
> ++ </varlistentry>
> + </variablelist>
> + </refsect1>
> +
> +diff --git a/tools/depmod.c b/tools/depmod.c
> +index eb810b8..8b19ab6 100644
> +--- a/tools/depmod.c
> ++++ b/tools/depmod.c
> +@@ -458,6 +458,12 @@ struct cfg_external {
> + char path[];
> + };
> +
> ++struct cfg_exclude {
> ++ struct cfg_exclude *next;
> ++ size_t len;
> ++ char exclude_dir[];
> ++};
> ++
> + struct cfg {
> + const char *kversion;
> + char dirname[PATH_MAX];
> +@@ -469,6 +475,7 @@ struct cfg {
> + struct cfg_override *overrides;
> + struct cfg_search *searches;
> + struct cfg_external *externals;
> ++ struct cfg_exclude *excludes;
> + };
> +
> + static enum search_type cfg_define_search_type(const char *path)
> +@@ -580,6 +587,31 @@ static void cfg_external_free(struct cfg_external
> *ext)
> + free(ext);
> + }
> +
> ++static int cfg_exclude_add(struct cfg *cfg, const char *path)
> ++{
> ++ struct cfg_exclude *exc;
> ++ size_t len = strlen(path);
> ++
> ++ exc = malloc(sizeof(struct cfg_exclude) + len);
> ++ if (exc == NULL) {
> ++ ERR("exclude add: out of memory\n");
> ++ return -ENOMEM;
> ++ }
> ++ exc->len = len;
> ++ memcpy(exc->exclude_dir, path, len);
> ++
> ++ DBG("exclude add: %s\n", path);
> ++
> ++ exc->next = cfg->excludes;
> ++ cfg->excludes = exc;
> ++ return 0;
> ++}
> ++
> ++static void cfg_exclude_free(struct cfg_exclude *exc)
> ++{
> ++ free(exc);
> ++}
> ++
> + static int cfg_kernel_matches(const struct cfg *cfg, const char *pattern)
> + {
> + regex_t re;
> +@@ -657,6 +689,11 @@ static int cfg_file_parse(struct cfg *cfg, const
> char *filename)
> + }
> +
> + cfg_external_add(cfg, dir);
> ++ } else if (streq(cmd, "exclude")) {
> ++ const char *sp;
> ++ while ((sp = strtok_r(NULL, "\t ", &saveptr)) !=
> NULL) {
> ++ cfg_exclude_add(cfg, sp);
> ++ }
> + } else if (streq(cmd, "include")
> + || streq(cmd, "make_map_files")) {
> + INF("%s:%u: command %s not implemented yet\n",
> +@@ -857,6 +894,12 @@ static void cfg_free(struct cfg *cfg)
> + cfg->externals = cfg->externals->next;
> + cfg_external_free(tmp);
> + }
> ++
> ++ while (cfg->excludes) {
> ++ struct cfg_exclude *tmp = cfg->excludes;
> ++ cfg->excludes = cfg->excludes->next;
> ++ cfg_exclude_free(tmp);
> ++ }
> + }
> +
> +
> +@@ -1239,12 +1282,23 @@ static int depmod_modules_search_dir(struct
> depmod *depmod, DIR *d, size_t basel
> + const char *name = de->d_name;
> + size_t namelen;
> + uint8_t is_dir;
> ++ struct cfg_exclude *exc;
> ++ int exclude = 0;
> +
> + if (name[0] == '.' && (name[1] == '\0' ||
> + (name[1] == '.' && name[2] ==
> '\0')))
> + continue;
> + if (streq(name, "build") || streq(name, "source"))
> + continue;
> ++
> ++ for (exc = depmod->cfg->excludes; exc != NULL; exc =
> exc->next) {
> ++ if (streq(name, exc->exclude_dir)) {
> ++ exclude = 1;
> ++ }
> ++ }
> ++ if (exclude)
> ++ continue;
> ++
> + namelen = strlen(name);
> + if (scratchbuf_alloc(s_path, baselen + namelen + 2) < 0) {
> + err = -ENOMEM;
> +--
> +2.31.1
> +
> diff --git a/meta/recipes-kernel/kmod/kmod_29.bb
> b/meta/recipes-kernel/kmod/kmod_29.bb
> index 91951edde16..9b663490666 100644
> --- a/meta/recipes-kernel/kmod/kmod_29.bb
> +++ b/meta/recipes-kernel/kmod/kmod_29.bb
> @@ -20,6 +20,7 @@ SRCREV = "b6ecfc916a17eab8f93be5b09f4e4f845aabd3d1"
> SRC_URI = "git://
> git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git;branch=master \
> file://depmod-search.conf \
> file://avoid_parallel_tests.patch \
> + file://0001-depmod-Add-support-for-excluding-a-directory.patch
> \
> "
>
> S = "${WORKDIR}/git"
> @@ -64,6 +65,9 @@ do_install:append () {
>
> # install depmod.d file for search/ dir
> install -Dm644 "${WORKDIR}/depmod-search.conf"
> "${D}${nonarch_base_libdir}/depmod.d/search.conf"
> +
> + # Add .debug to the exclude path for depmod
> + echo "exclude .debug" >
> ${D}${nonarch_base_libdir}/depmod.d/exclude.conf
> }
>
> ALTERNATIVE_PRIORITY = "70"
> --
> 2.31.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#163795):
> https://lists.openembedded.org/g/openembedded-core/message/163795
> Mute This Topic: https://lists.openembedded.org/mt/90143170/5052612
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> quaresma.jose@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>

--
Best regards,

José Quaresma

[-- Attachment #2: Type: text/html, Size: 12590 bytes --]