Openembedded Core Discussions
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info
@ 2022-01-11 23:58 Saul Wold
  2022-01-11 23:58 ` [RFC PATCH v2 1/3] create-spdx: Add kernel work-shared source Saul Wold
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Saul Wold @ 2022-01-11 23:58 UTC (permalink / raw)
  To: openembedded-core, bruce.ashfield, JPEWhacker; +Cc: Saul Wold

This second change set, enables the kernel:do_strip() to share the
oe.package:runstrip() method. A copy of the kernel is made for the
kernel strip processing which is ultimately deployed, while the 
unstripped kernel image can be used by package.bbclass to generate
the extended packagedata (debug info).  The extended packagedata is
also used to genrate the SPDX data.

This change also needs to strip out the "/usr/src/kernel" path since
the kernel uses work-shared, which is added to the search path.

I have tested this with edgerouter which uses the
KERNEL_IMAGE_STRIP_EXTRA_SECTIONS variable

If this looks good, I will send a non-RFC patch set tomorrow.


Sau!


Saul Wold (3):
  create-spdx: Add kernel work-shared source
  package: Add support for kernel stripping
  kernel.bbclass: use common strip()

 meta/classes/create-spdx.bbclass |  6 ++++-
 meta/classes/kernel.bbclass      | 44 ++++++++++++++------------------
 meta/classes/package.bbclass     | 21 +++++----------
 meta/lib/oe/package.py           |  7 +++--
 4 files changed, 36 insertions(+), 42 deletions(-)

-- 
2.31.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC PATCH v2 1/3] create-spdx: Add kernel work-shared source
  2022-01-11 23:58 [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info Saul Wold
@ 2022-01-11 23:58 ` Saul Wold
  2022-01-11 23:58 ` [RFC PATCH v2 2/3] package: Add support for kernel stripping Saul Wold
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Saul Wold @ 2022-01-11 23:58 UTC (permalink / raw)
  To: openembedded-core, bruce.ashfield, JPEWhacker; +Cc: Saul Wold

Since the kernel source is stored in work-shared, we need to add it
to the search path so the kernel and kernel-modules source code can
be found correctly.

Signed-off-by: Saul Wold <saul.wold@windriver.com>
---
 meta/classes/create-spdx.bbclass | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index 0a4db80aba5..e1ff2bbb787 100644
--- a/meta/classes/create-spdx.bbclass
+++ b/meta/classes/create-spdx.bbclass
@@ -254,6 +254,7 @@ def add_package_sources_from_debug(d, package_doc, spdx_package, package, packag
         Path(d.getVar('PKGD')),
         Path(d.getVar('STAGING_DIR_TARGET')),
         Path(d.getVar('STAGING_DIR_NATIVE')),
+        Path(d.getVar('STAGING_KERNEL_DIR')),
     ]
 
     pkg_data = oe.packagedata.read_subpkgdata_extended(package, d)
@@ -275,7 +276,10 @@ def add_package_sources_from_debug(d, package_doc, spdx_package, package, packag
         for debugsrc in file_data["debugsrc"]:
             ref_id = "NOASSERTION"
             for search in debug_search_paths:
-                debugsrc_path = search / debugsrc.lstrip("/")
+                if debugsrc.startswith("/usr/src/kernel"):
+                    debugsrc_path = search / debugsrc.replace('/usr/src/kernel/', '')
+                else:
+                    debugsrc_path = search / debugsrc.lstrip("/")
                 if not debugsrc_path.exists():
                     continue
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH v2 2/3] package: Add support for kernel stripping
  2022-01-11 23:58 [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info Saul Wold
  2022-01-11 23:58 ` [RFC PATCH v2 1/3] create-spdx: Add kernel work-shared source Saul Wold
@ 2022-01-11 23:58 ` Saul Wold
  2022-01-12 14:21   ` Bruce Ashfield
  2022-01-11 23:58 ` [RFC PATCH v2 3/3] kernel.bbclass: use common strip() Saul Wold
  2022-01-12 14:30 ` [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info Bruce Ashfield
  3 siblings, 1 reply; 8+ messages in thread
From: Saul Wold @ 2022-01-11 23:58 UTC (permalink / raw)
  To: openembedded-core, bruce.ashfield, JPEWhacker; +Cc: Saul Wold

Extend runstrip() to accept additional argument to enable
sharing it with the kernel do_strip() to that
KERNEL_IMAGE_STRIP_EXTRA_SECTIONS can be passed.

Since is_elf() understands kernel modules there is no need to keep a
seperate list for kernmodules or hardcode the values to runstrip.

Signed-off-by: Saul Wold <saul.wold@windriver.com>
---
 meta/classes/package.bbclass | 21 +++++++--------------
 meta/lib/oe/package.py       |  7 +++++--
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index 09cd376f4af..794996e6d6d 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -390,10 +390,6 @@ def splitdebuginfo(file, dvar, debugdir, debuglibdir, debugappend, debugsrcdir,
     dvar = d.getVar('PKGD')
     objcopy = d.getVar("OBJCOPY")
 
-    # We ignore kernel modules, we don't generate debug info files.
-    if file.find("/lib/modules/") != -1 and file.endswith(".ko"):
-        return (file, sources)
-
     newmode = None
     if not os.access(file, os.W_OK) or os.access(file, os.R_OK):
         origmode = os.stat(file)[stat.ST_MODE]
@@ -1122,7 +1118,6 @@ python split_and_strip_files () {
     #
     elffiles = {}
     symlinks = {}
-    kernmods = []
     staticlibs = []
     inodes = {}
     libdir = os.path.abspath(dvar + os.sep + d.getVar("libdir"))
@@ -1145,9 +1140,6 @@ python split_and_strip_files () {
                 if file in skipfiles:
                     continue
 
-                if file.endswith(".ko") and file.find("/lib/modules/") != -1:
-                    kernmods.append(file)
-                    continue
                 if oe.package.is_static_lib(file):
                     staticlibs.append(file)
                     continue
@@ -1164,8 +1156,11 @@ python split_and_strip_files () {
                 if not s:
                     continue
                 # Check its an executable
-                if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \
-                        or ((file.startswith(libdir) or file.startswith(baselibdir)) and (".so" in f or ".node" in f)):
+                if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) \
+                        or (s[stat.ST_MODE] & stat.S_IXOTH) \
+                        or ((file.startswith(libdir) or file.startswith(baselibdir)) \
+                        and (".so" in f or ".node" in f)) \
+                        or (f.startswith('vmlinux') or ".ko" in f):
 
                     if cpath.islink(file):
                         checkelflinks[file] = ltarget
@@ -1311,12 +1306,10 @@ python split_and_strip_files () {
         for file in elffiles:
             elf_file = int(elffiles[file])
             #bb.note("Strip %s" % file)
-            sfiles.append((file, elf_file, strip))
-        for f in kernmods:
-            sfiles.append((f, 16, strip))
+            sfiles.append((file, elf_file, strip, ''))
         if (d.getVar('PACKAGE_STRIP_STATIC') == '1' or d.getVar('PACKAGE_DEBUG_STATIC_SPLIT') == '1'):
             for f in staticlibs:
-                sfiles.append((f, 16, strip))
+                sfiles.append((f, 16, strip, ''))
 
         oe.utils.multiprocess_launch(oe.package.runstrip, sfiles, d)
 
diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index dd700cbb0c9..7842a614e9f 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -16,7 +16,7 @@ def runstrip(arg):
     # 8 - shared library
     # 16 - kernel module
 
-    (file, elftype, strip) = arg
+    (file, elftype, strip, extra_strip_sections) = arg
 
     newmode = None
     if not os.access(file, os.W_OK) or os.access(file, os.R_OK):
@@ -40,6 +40,9 @@ def runstrip(arg):
     # shared or executable:
     elif elftype & 8 or elftype & 4:
         stripcmd.extend(["--remove-section=.comment", "--remove-section=.note"])
+        if file.find("boot/vmlinux") != -1 and extra_strip_sections != '':
+            for section in extra_strip_sections.split():
+                stripcmd.extend(["--remove-section=" + section])
 
     stripcmd.append(file)
     bb.debug(1, "runstrip: %s" % stripcmd)
@@ -172,7 +175,7 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, d, qa_already_stripp
     sfiles = []
     for file in elffiles:
         elf_file = int(elffiles[file])
-        sfiles.append((file, elf_file, strip_cmd))
+        sfiles.append((file, elf_file, strip_cmd, ''))
 
     oe.utils.multiprocess_launch(runstrip, sfiles, d)
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH v2 3/3] kernel.bbclass: use common strip()
  2022-01-11 23:58 [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info Saul Wold
  2022-01-11 23:58 ` [RFC PATCH v2 1/3] create-spdx: Add kernel work-shared source Saul Wold
  2022-01-11 23:58 ` [RFC PATCH v2 2/3] package: Add support for kernel stripping Saul Wold
@ 2022-01-11 23:58 ` Saul Wold
  2022-01-12 14:30   ` Bruce Ashfield
  2022-01-12 14:30 ` [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info Bruce Ashfield
  3 siblings, 1 reply; 8+ messages in thread
From: Saul Wold @ 2022-01-11 23:58 UTC (permalink / raw)
  To: openembedded-core, bruce.ashfield, JPEWhacker; +Cc: Saul Wold

Re-use the runstrip() code from oe.packaging, for the kernel
stripping process. Since runstrip() is python the kernel do_strip()
need to be converted to Python also. The stripped kernel image
will be used for deployment in do_deploy(). This will allow the
package.bbclass to split an unstripped kernel binary for the debug
information and extended packagedata. The extended package data is
used by create-spdx.

Signed-off-by: Saul Wold <saul.wold@windriver.com>
---
 meta/classes/kernel.bbclass | 44 ++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
index 7685c6921fa..b2f9e3c8071 100644
--- a/meta/classes/kernel.bbclass
+++ b/meta/classes/kernel.bbclass
@@ -700,30 +700,19 @@ do_kernel_link_images() {
 }
 addtask kernel_link_images after do_compile before do_strip
 
-do_strip() {
-	if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
-		if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
-			bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
-			return
-		fi
-
-		cd ${B}
-		headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
-			  grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
-			  sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
-			  gawk '{print $1}'`
-
-		for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
-			if ! (echo "$headers" | grep -q "^$str$"); then
-				bbwarn "Section not found: $str";
-			fi
-
-			"$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
-		}; done
-
-		bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
-			"${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
-	fi;
+python do_strip() {
+    import shutil
+
+    strip = d.getVar('STRIP')
+    extra_sections = d.getVar('KERNEL_IMAGE_STRIP_EXTRA_SECTIONS')
+    kernel_image = d.getVar('B') + "/" + d.getVar('KERNEL_OUTPUT_DIR') + "/vmlinux"
+
+    if (extra_sections is not None and kernel_image.find('boot/vmlinux') != -1):
+        kernel_image_stripped = kernel_image + ".stripped"
+        shutil.copy2(kernel_image, kernel_image_stripped)
+        oe.package.runstrip((kernel_image_stripped, 8, strip, extra_sections))
+        bb.note ("KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections: " + \
+            extra_sections)
 }
 do_strip[dirs] = "${B}"
 
@@ -768,7 +757,12 @@ kernel_do_deploy() {
 
 	for imageType in ${KERNEL_IMAGETYPES} ; do
 		baseName=$imageType-${KERNEL_IMAGE_NAME}
-		install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
+
+		if [ -s ${KERNEL_OUTPUT_DIR}/$imageType.stripped ] ; then
+			install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.stripped $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
+		else
+			install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
+		fi
 		if [ -n "${KERNEL_IMAGE_LINK_NAME}" ] ; then
 			ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
 		fi
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH v2 2/3] package: Add support for kernel stripping
  2022-01-11 23:58 ` [RFC PATCH v2 2/3] package: Add support for kernel stripping Saul Wold
@ 2022-01-12 14:21   ` Bruce Ashfield
  0 siblings, 0 replies; 8+ messages in thread
From: Bruce Ashfield @ 2022-01-12 14:21 UTC (permalink / raw)
  To: Saul Wold; +Cc: Patches and discussions about the oe-core layer, Joshua Watt

On Tue, Jan 11, 2022 at 6:59 PM Saul Wold <saul.wold@windriver.com> wrote:
>
> Extend runstrip() to accept additional argument to enable
> sharing it with the kernel do_strip() to that
> KERNEL_IMAGE_STRIP_EXTRA_SECTIONS can be passed.
>
> Since is_elf() understands kernel modules there is no need to keep a
> seperate list for kernmodules or hardcode the values to runstrip.
>
> Signed-off-by: Saul Wold <saul.wold@windriver.com>
> ---
>  meta/classes/package.bbclass | 21 +++++++--------------
>  meta/lib/oe/package.py       |  7 +++++--
>  2 files changed, 12 insertions(+), 16 deletions(-)
>
> diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
> index 09cd376f4af..794996e6d6d 100644
> --- a/meta/classes/package.bbclass
> +++ b/meta/classes/package.bbclass
> @@ -390,10 +390,6 @@ def splitdebuginfo(file, dvar, debugdir, debuglibdir, debugappend, debugsrcdir,
>      dvar = d.getVar('PKGD')
>      objcopy = d.getVar("OBJCOPY")
>
> -    # We ignore kernel modules, we don't generate debug info files.
> -    if file.find("/lib/modules/") != -1 and file.endswith(".ko"):
> -        return (file, sources)
> -
>      newmode = None
>      if not os.access(file, os.W_OK) or os.access(file, os.R_OK):
>          origmode = os.stat(file)[stat.ST_MODE]
> @@ -1122,7 +1118,6 @@ python split_and_strip_files () {
>      #
>      elffiles = {}
>      symlinks = {}
> -    kernmods = []
>      staticlibs = []
>      inodes = {}
>      libdir = os.path.abspath(dvar + os.sep + d.getVar("libdir"))
> @@ -1145,9 +1140,6 @@ python split_and_strip_files () {
>                  if file in skipfiles:
>                      continue
>
> -                if file.endswith(".ko") and file.find("/lib/modules/") != -1:
> -                    kernmods.append(file)
> -                    continue
>                  if oe.package.is_static_lib(file):
>                      staticlibs.append(file)
>                      continue
> @@ -1164,8 +1156,11 @@ python split_and_strip_files () {
>                  if not s:
>                      continue
>                  # Check its an executable
> -                if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH) \
> -                        or ((file.startswith(libdir) or file.startswith(baselibdir)) and (".so" in f or ".node" in f)):
> +                if (s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) \
> +                        or (s[stat.ST_MODE] & stat.S_IXOTH) \
> +                        or ((file.startswith(libdir) or file.startswith(baselibdir)) \
> +                        and (".so" in f or ".node" in f)) \
> +                        or (f.startswith('vmlinux') or ".ko" in f):
>
>                      if cpath.islink(file):
>                          checkelflinks[file] = ltarget
> @@ -1311,12 +1306,10 @@ python split_and_strip_files () {
>          for file in elffiles:
>              elf_file = int(elffiles[file])
>              #bb.note("Strip %s" % file)
> -            sfiles.append((file, elf_file, strip))
> -        for f in kernmods:
> -            sfiles.append((f, 16, strip))
> +            sfiles.append((file, elf_file, strip, ''))
>          if (d.getVar('PACKAGE_STRIP_STATIC') == '1' or d.getVar('PACKAGE_DEBUG_STATIC_SPLIT') == '1'):
>              for f in staticlibs:
> -                sfiles.append((f, 16, strip))
> +                sfiles.append((f, 16, strip, ''))
>
>          oe.utils.multiprocess_launch(oe.package.runstrip, sfiles, d)
>
> diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
> index dd700cbb0c9..7842a614e9f 100644
> --- a/meta/lib/oe/package.py
> +++ b/meta/lib/oe/package.py
> @@ -16,7 +16,7 @@ def runstrip(arg):
>      # 8 - shared library
>      # 16 - kernel module
>
> -    (file, elftype, strip) = arg
> +    (file, elftype, strip, extra_strip_sections) = arg
>
>      newmode = None
>      if not os.access(file, os.W_OK) or os.access(file, os.R_OK):
> @@ -40,6 +40,9 @@ def runstrip(arg):
>      # shared or executable:
>      elif elftype & 8 or elftype & 4:
>          stripcmd.extend(["--remove-section=.comment", "--remove-section=.note"])
> +        if file.find("boot/vmlinux") != -1 and extra_strip_sections != '':
> +            for section in extra_strip_sections.split():
> +                stripcmd.extend(["--remove-section=" + section])

One thought that came to mind when reading this, is does that really
need to be restricted to boot/vmlinux ? The code would be simplified
by just testing for 'if extra_strip_sections:' .. and then the
sections are only passed for the kernel components that need it.

The more broadly available functionality obviously isn't used (or
maybe ever needed), but it does simplify things.  But I'm only looking
at the diff, so maybe I'm missing a nuance.

>
>      stripcmd.append(file)
>      bb.debug(1, "runstrip: %s" % stripcmd)
> @@ -172,7 +175,7 @@ def strip_execs(pn, dstdir, strip_cmd, libdir, base_libdir, d, qa_already_stripp
>      sfiles = []
>      for file in elffiles:
>          elf_file = int(elffiles[file])
> -        sfiles.append((file, elf_file, strip_cmd))
> +        sfiles.append((file, elf_file, strip_cmd, ''))

Rather than needing to add the '' to all of the appends, isn't there a
way that the oe util runstrip could just check the length of args and
assign a default if there isn't a 4th argument ? That routine is
already assigning specifically to variables to checking the length
wouldn't be adding any specific knowledge to a generic routine.

Bruce

>
>      oe.utils.multiprocess_launch(runstrip, sfiles, d)
>
> --
> 2.31.1
>


-- 
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH v2 3/3] kernel.bbclass: use common strip()
  2022-01-11 23:58 ` [RFC PATCH v2 3/3] kernel.bbclass: use common strip() Saul Wold
@ 2022-01-12 14:30   ` Bruce Ashfield
  2022-01-12 15:42     ` Saul Wold
  0 siblings, 1 reply; 8+ messages in thread
From: Bruce Ashfield @ 2022-01-12 14:30 UTC (permalink / raw)
  To: Saul Wold; +Cc: Patches and discussions about the oe-core layer, Joshua Watt

On Tue, Jan 11, 2022 at 6:59 PM Saul Wold <saul.wold@windriver.com> wrote:
>
> Re-use the runstrip() code from oe.packaging, for the kernel
> stripping process. Since runstrip() is python the kernel do_strip()
> need to be converted to Python also. The stripped kernel image
> will be used for deployment in do_deploy(). This will allow the
> package.bbclass to split an unstripped kernel binary for the debug
> information and extended packagedata. The extended package data is
> used by create-spdx.
>
> Signed-off-by: Saul Wold <saul.wold@windriver.com>
> ---
>  meta/classes/kernel.bbclass | 44 ++++++++++++++++---------------------
>  1 file changed, 19 insertions(+), 25 deletions(-)
>
> diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
> index 7685c6921fa..b2f9e3c8071 100644
> --- a/meta/classes/kernel.bbclass
> +++ b/meta/classes/kernel.bbclass
> @@ -700,30 +700,19 @@ do_kernel_link_images() {
>  }
>  addtask kernel_link_images after do_compile before do_strip
>
> -do_strip() {
> -       if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
> -               if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
> -                       bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
> -                       return
> -               fi
> -
> -               cd ${B}
> -               headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
> -                         grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
> -                         sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
> -                         gawk '{print $1}'`
> -
> -               for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
> -                       if ! (echo "$headers" | grep -q "^$str$"); then
> -                               bbwarn "Section not found: $str";
> -                       fi

We are losing this warning in the relocated / common routine. It looks
like something we could continue to detect and warn on, no ?

> -
> -                       "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
> -               }; done
> -
> -               bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
> -                       "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
> -       fi;
> +python do_strip() {
> +    import shutil
> +
> +    strip = d.getVar('STRIP')
> +    extra_sections = d.getVar('KERNEL_IMAGE_STRIP_EXTRA_SECTIONS')
> +    kernel_image = d.getVar('B') + "/" + d.getVar('KERNEL_OUTPUT_DIR') + "/vmlinux"
> +
> +    if (extra_sections is not None and kernel_image.find('boot/vmlinux') != -1):

Minor 'nit .. I'd probably just write that as: if extra_sections
(versus the is not None) .. but maybe you have it that way due to that
check not working.

> +        kernel_image_stripped = kernel_image + ".stripped"
> +        shutil.copy2(kernel_image, kernel_image_stripped)
> +        oe.package.runstrip((kernel_image_stripped, 8, strip, extra_sections))
> +        bb.note ("KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections: " + \
> +            extra_sections)

In theory, we could move the debug log to the common routine when it
detects the extra section argument

>  }
>  do_strip[dirs] = "${B}"
>
> @@ -768,7 +757,12 @@ kernel_do_deploy() {
>
>         for imageType in ${KERNEL_IMAGETYPES} ; do
>                 baseName=$imageType-${KERNEL_IMAGE_NAME}
> -               install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
> +
> +               if [ -s ${KERNEL_OUTPUT_DIR}/$imageType.stripped ] ; then
> +                       install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.stripped $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
> +               else
> +                       install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
> +               fi

Is there a scenario when the ".stripped" image isn't available ?
Wouldn't that already be an error, and so the deploy should just be an
error, versus copying the non-stripped one ?

Bruce

>                 if [ -n "${KERNEL_IMAGE_LINK_NAME}" ] ; then
>                         ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
>                 fi
> --
> 2.31.1
>


-- 
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info
  2022-01-11 23:58 [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info Saul Wold
                   ` (2 preceding siblings ...)
  2022-01-11 23:58 ` [RFC PATCH v2 3/3] kernel.bbclass: use common strip() Saul Wold
@ 2022-01-12 14:30 ` Bruce Ashfield
  3 siblings, 0 replies; 8+ messages in thread
From: Bruce Ashfield @ 2022-01-12 14:30 UTC (permalink / raw)
  To: Saul Wold; +Cc: Patches and discussions about the oe-core layer, Joshua Watt

On Tue, Jan 11, 2022 at 6:59 PM Saul Wold <saul.wold@windriver.com> wrote:
>
> This second change set, enables the kernel:do_strip() to share the
> oe.package:runstrip() method. A copy of the kernel is made for the
> kernel strip processing which is ultimately deployed, while the
> unstripped kernel image can be used by package.bbclass to generate
> the extended packagedata (debug info).  The extended packagedata is
> also used to genrate the SPDX data.
>
> This change also needs to strip out the "/usr/src/kernel" path since
> the kernel uses work-shared, which is added to the search path.
>
> I have tested this with edgerouter which uses the
> KERNEL_IMAGE_STRIP_EXTRA_SECTIONS variable
>
> If this looks good, I will send a non-RFC patch set tomorrow.
>

Minor comments from my side, the approach looks fine to me .. no major concerns!

Bruce

>
> Sau!
>
>
> Saul Wold (3):
>   create-spdx: Add kernel work-shared source
>   package: Add support for kernel stripping
>   kernel.bbclass: use common strip()
>
>  meta/classes/create-spdx.bbclass |  6 ++++-
>  meta/classes/kernel.bbclass      | 44 ++++++++++++++------------------
>  meta/classes/package.bbclass     | 21 +++++----------
>  meta/lib/oe/package.py           |  7 +++--
>  4 files changed, 36 insertions(+), 42 deletions(-)
>
> --
> 2.31.1
>


-- 
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH v2 3/3] kernel.bbclass: use common strip()
  2022-01-12 14:30   ` Bruce Ashfield
@ 2022-01-12 15:42     ` Saul Wold
  0 siblings, 0 replies; 8+ messages in thread
From: Saul Wold @ 2022-01-12 15:42 UTC (permalink / raw)
  To: Bruce Ashfield
  Cc: Patches and discussions about the oe-core layer, Joshua Watt



On 1/12/22 06:30, Bruce Ashfield wrote:
> On Tue, Jan 11, 2022 at 6:59 PM Saul Wold <saul.wold@windriver.com> wrote:
>>
>> Re-use the runstrip() code from oe.packaging, for the kernel
>> stripping process. Since runstrip() is python the kernel do_strip()
>> need to be converted to Python also. The stripped kernel image
>> will be used for deployment in do_deploy(). This will allow the
>> package.bbclass to split an unstripped kernel binary for the debug
>> information and extended packagedata. The extended package data is
>> used by create-spdx.
>>
>> Signed-off-by: Saul Wold <saul.wold@windriver.com>
>> ---
>>   meta/classes/kernel.bbclass | 44 ++++++++++++++++---------------------
>>   1 file changed, 19 insertions(+), 25 deletions(-)
>>
>> diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
>> index 7685c6921fa..b2f9e3c8071 100644
>> --- a/meta/classes/kernel.bbclass
>> +++ b/meta/classes/kernel.bbclass
>> @@ -700,30 +700,19 @@ do_kernel_link_images() {
>>   }
>>   addtask kernel_link_images after do_compile before do_strip
>>
>> -do_strip() {
>> -       if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
>> -               if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
>> -                       bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
>> -                       return
>> -               fi
>> -
>> -               cd ${B}
>> -               headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
>> -                         grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
>> -                         sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
>> -                         gawk '{print $1}'`
>> -
>> -               for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
>> -                       if ! (echo "$headers" | grep -q "^$str$"); then
>> -                               bbwarn "Section not found: $str";
>> -                       fi
> 
> We are losing this warning in the relocated / common routine. It looks
> like something we could continue to detect and warn on, no ?
> 
I guess do we care in this case?  We still do the strip regardless, the 
strip command does not complain about a missing section.

>> -
>> -                       "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
>> -               }; done
>> -
>> -               bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
>> -                       "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
>> -       fi;
>> +python do_strip() {
>> +    import shutil
>> +
>> +    strip = d.getVar('STRIP')
>> +    extra_sections = d.getVar('KERNEL_IMAGE_STRIP_EXTRA_SECTIONS')
>> +    kernel_image = d.getVar('B') + "/" + d.getVar('KERNEL_OUTPUT_DIR') + "/vmlinux"
>> +
>> +    if (extra_sections is not None and kernel_image.find('boot/vmlinux') != -1):
> 
> Minor 'nit .. I'd probably just write that as: if extra_sections
> (versus the is not None) .. but maybe you have it that way due to that
> check not working.
> 
>> +        kernel_image_stripped = kernel_image + ".stripped"
>> +        shutil.copy2(kernel_image, kernel_image_stripped)
>> +        oe.package.runstrip((kernel_image_stripped, 8, strip, extra_sections))
>> +        bb.note ("KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections: " + \
>> +            extra_sections)
> 
> In theory, we could move the debug log to the common routine when it
> detects the extra section argument
> 
Sure this can move to bb.debug(), will do that.

>>   }
>>   do_strip[dirs] = "${B}"
>>
>> @@ -768,7 +757,12 @@ kernel_do_deploy() {
>>
>>          for imageType in ${KERNEL_IMAGETYPES} ; do
>>                  baseName=$imageType-${KERNEL_IMAGE_NAME}
>> -               install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
>> +
>> +               if [ -s ${KERNEL_OUTPUT_DIR}/$imageType.stripped ] ; then
>> +                       install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.stripped $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
>> +               else
>> +                       install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
>> +               fi
> 
> Is there a scenario when the ".stripped" image isn't available ?
> Wouldn't that already be an error, and so the deploy should just be an
> error, versus copying the non-stripped one ?
> 
We only copy to .stripped when KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, 
so in the non-set case we will have the un-stripped image that needs to 
get installed correctly.


Sau!
> Bruce
> 
>>                  if [ -n "${KERNEL_IMAGE_LINK_NAME}" ] ; then
>>                          ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
>>                  fi
>> --
>> 2.31.1
>>
> 
> 

-- 
Sau!


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-01-12 15:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-11 23:58 [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info Saul Wold
2022-01-11 23:58 ` [RFC PATCH v2 1/3] create-spdx: Add kernel work-shared source Saul Wold
2022-01-11 23:58 ` [RFC PATCH v2 2/3] package: Add support for kernel stripping Saul Wold
2022-01-12 14:21   ` Bruce Ashfield
2022-01-11 23:58 ` [RFC PATCH v2 3/3] kernel.bbclass: use common strip() Saul Wold
2022-01-12 14:30   ` Bruce Ashfield
2022-01-12 15:42     ` Saul Wold
2022-01-12 14:30 ` [RFC PATCH v2 0/3] Extend create-spdx to build kernel spdx info Bruce Ashfield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox