Skip to contentSkip to conversation

Fix 32-bit builds of CHIPSEC

PATCH New Ricardo Neri 1 participant 5 messages Mar 15, 2017

lore
Share & tools
lore
#0 lore raw

cover Fix 32-bit builds of CHIPSEC

Our build bot discovered broken builds of CHIPSEC in qemux86. This series fixes these issues. In a nutshell, the CHIPSEC driver needs to be aware of the CPU architecture to build the driver differently. Also, given that CHIPSEC provides an out-of-tree module, Linux needs extra tasks performed before CHIPSEC can be built.

Thanks and BR,
Ricardo

Ricardo Neri (4):
chipsec: make chipsec recipe depend on make_scripts
chipsec: Provide CHIPSEC's driver with the build architecture
chipsec: distutils' build arguments
chipsec: Ship 64-bit binary files only in 64-bit packages

 ...ve-CPU-architecture-to-the-driver-s-Makef.patch | 40 ++++++++++++++++++++++
 meta-luv/recipes-core/chipsec/chipsec_git.bb       | 14 +++++++-
 meta/lib/oe/terminal.py                            |  3 +-
 3 files changed, 55 insertions(+), 2 deletions(-)
 create mode 100644 meta-luv/recipes-core/chipsec/chipsec/0001-setup.py-give-CPU-architecture-to-the-driver-s-Makef.patch
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/4 chipsec: make chipsec recipe depend on make_scripts

In order to out-of-tree build modules properly, it is necessary to invoke make prepare && make scripts in the Linux source tree. Otherwise, the module will not know all the appropriate kernel configurations. The task make_scripts, inherited from module-base.bbclass, takes care of it.

CHIPSEC includes an out-of-tree module. Thus, make_scripts should run before our do_compile task. Since in Yocto the Linux build artifacts are put in a separate directory, controlled by the kernel's do_shared_workdir task, such task must run before make_scripts.

Lastly, we hold a lock to the kernel-scripts task.

The issue of not running make_scripts before do_compile manifests itself as:

ERROR: Kernel configuration is invalid.
include/generated/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it.

---
 meta-luv/recipes-core/chipsec/chipsec_git.bb | 4 ++++
 1 file changed, 4 insertions(+)
meta-luv/recipes-core/chipsec/chipsec_git.bb +4 -0
index d6c1bef..6c29231 100644
@@ -28,6 +28,10 @@ inherit python-dir
 inherit distutils
 inherit luv-test
 
+addtask make_scripts after do_patch before do_compile
+do_make_scripts[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
+do_make_scripts[depends] += "virtual/kernel:do_shared_workdir"
+
 S = "${WORKDIR}/git"
 
 export INC = "-I${STAGING_INCDIR}/${PYTHON_DIR}"
Signature · 1 line
2.9.3
#2 lore raw

PATCH 2/4 chipsec: Provide CHIPSEC's driver with the build architecture

In reply to Ricardo Neri

When cross-building for 32-bit x86, we need to make aware the CHIPSEC driver that we intend to build the 32-bit version via the ARCH variable. A quick fix is to define an environment varialble, CHIPSEC_ARCH, that can be retrieved from setup.py and passed to the driver Makefile.

We no longer the EXTRA_OEMAKE variable as we rely on Python setuptools to build CHIPSEC.

---
 ...ve-CPU-architecture-to-the-driver-s-Makef.patch | 40 ++++++++++++++++++++++
 meta-luv/recipes-core/chipsec/chipsec_git.bb       |  3 +-
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 meta-luv/recipes-core/chipsec/chipsec/0001-setup.py-give-CPU-architecture-to-the-driver-s-Makef.patch
meta-luv/recipes-core/chipsec/chipsec/0001-setup.py-give-CPU-architecture-to-the-driver-s-Makef.patch new file +40 -0
new file mode 100644
index 0000000..4fe7f10
@@ -0,0 +1,40 @@
+From 4df09a6f905c9e1cf8c65235ff309ac7bebcc6eb Mon Sep 17 00:00:00 2001
+From: Ricardo Neri <[email protected]>
+Date: Wed, 15 Mar 2017 12:00:57 -0700
+Subject: [PATCH] setup.py: give CPU architecture to the driver's Makefile
+
+Driver is built differently depending on whether it is built for
+32-bit or 64-bit x86 archs. Thus, we need to pass the desired
+CPU architecture. This can be done by reading the environment
+variable CHIPSEC_ARCH. This could be done more nicely by adding
+a new variable to build_ext, though.
+
+Signed-off-by: Ricardo Neri <[email protected]>
+---
+ setup.py | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/setup.py b/setup.py
+index fb0da43..e09eaa6 100644
+--- a/setup.py
++++ b/setup.py
+@@ -68,13 +68,14 @@ class build_ext(_build_ext):
+         self.set_undefined_options("build", ("skip_driver", "skip_driver"))
+ 
+     def _build_linux_driver(self):
+-        log.info("building the linux driver")
++        arch = os.environ["CHIPSEC_ARCH"]
++        log.info("building the linux driver for arch " + arch)
+         build_driver = os.path.join(self.real_build_lib, "drivers", "linux")
+         ko_ext = os.path.join(build_driver, "chipsec.ko")
+         # We copy the drivers extension to the build directory.
+         self.copy_tree(os.path.join("drivers", "linux"), build_driver)
+         # Run the makefile there.
+-        subprocess.check_output(["make", "-C", build_driver])
++        subprocess.check_output(["make", "ARCH="+arch, "-C", build_driver])
+         # And copy the resulting .ko to the right place.
+         # That is to the source directory if we are in "develop" mode,
+         # otherwise to the helper subdirectory in the build directory.
+-- 
+2.9.3
+
meta-luv/recipes-core/chipsec/chipsec_git.bb +2 -1
index 6c29231..1a209e7 100644
@@ -11,6 +11,7 @@ SRC_URI = "git://github.com/chipsec/chipsec.git \
     file://chipsec file://luv-parser-chipsec \
     file://0001-chipsec-building-for-32-bit-systems.patch \
     file://0001-chipsec-do-not-ship-manual.patch \
+    file://0001-setup.py-give-CPU-architecture-to-the-driver-s-Makef.patch \
     "
 
 SRCREV="2fbb7a4eeb3752998dfbcbdf771cd3f8ed1985ae"
@@ -48,7 +49,7 @@ def get_target_arch(d):
  else:
     raise bb.parse.SkipPackage("TARGET_ARCH %s not supported!" % target)
 
-EXTRA_OEMAKE += "ARCH="${@get_target_arch(d)}""
+export CHIPSEC_ARCH = "${@get_target_arch(d)}"
 
 DISTUTILS_INSTALL_ARGS = "--root=${D}${PYTHON_SITEPACKAGES_DIR} \
     --install-data=${D}/${datadir}"
Signature · 1 line
2.9.3
#3 lore raw

PATCH 3/4 chipsec: distutils' build arguments

In reply to Ricardo Neri

Utilize DISTUTILS_BUILD_ARGS variable to give the name of the setup.py build library to use. This is mostly a cosmetic change: it looks odd that the library name is linux-x86_64-2.7 when building for 32-bit.

---
 meta-luv/recipes-core/chipsec/chipsec_git.bb | 2 ++
 1 file changed, 2 insertions(+)
meta-luv/recipes-core/chipsec/chipsec_git.bb +2 -0
index 1a209e7..4778a03 100644
@@ -54,6 +54,8 @@ export CHIPSEC_ARCH = "${@get_target_arch(d)}"
 DISTUTILS_INSTALL_ARGS = "--root=${D}${PYTHON_SITEPACKAGES_DIR} \
     --install-data=${D}/${datadir}"
 
+DISTUTILS_BUILD_ARGS = "--build-lib=${TARGET_ARCH}"
+
 fix_mod_path() {
     sed -i -e "s:^INSTALL_MOD_PATH_PREFIX = .*:INSTALL_MOD_PATH_PREFIX = \"${PYTHON_SITEPACKAGES_DIR}\":" ${S}/chipsec_main.py
     sed -i -e "s:PYTHONPATH:${PYTHON_SITEPACKAGES_DIR}/chipsec:" ${WORKDIR}/chipsec
Signature · 1 line
2.9.3
#4 lore raw

PATCH 4/4 chipsec: Ship 64-bit binary files only in 64-bit packages

In reply to Ricardo Neri

The files TianoCompress.bin and LzmaCompress.bin are distributed in binary form. It's format is ELF64. Thus, only ship them for 64-bit builds. They could not be used in 32-bit builds anyway. We also avoid this package quality error:

ERROR: chipsec-1.2.5+-r0 do_package_qa: QA Issue: Architecture did not match (x86-64, expected x86) on /work/qemux86-oe-linux/chipsec/1.2.5+-r0/packages- split/chipsec/usr/lib/python2.7/site-packages/chipsec/chipsec_tools/linux/ TianoCompress.bin
Architecture did not match (x86-64, expected x86) on /work/qemux86-oe-linux/ chipsec/1.2.5+-r0/packages-split/chipsec/usr/lib/python2.7/site-packages/ chipsec/chipsec_tools/linux/LzmaCompress.bin [arch]
ERROR: chipsec-1.2.5+-r0 do_package_qa: QA Issue: Architecture did not match (x86-64, expected x86) on /work/qemux86-oe-linux/chipsec/1.2.5+-r0/packages- split/chipsec-dbg/usr/lib/python2.7/site-packages/chipsec/chipsec_tools/ linux/.debug/TianoCompress.bin
Architecture did not match (x86-64, expected x86) on /work/qemux86-oe-linux /chipsec/1.2.5+-r0/packages-split/chipsec-dbg/usr/lib/python2.7/site- packages/chipsec/chipsec_tools/linux/.debug/LzmaCompress.bin [arch]
ERROR: chipsec-1.2.5+-r0 do_package_qa: QA run found fatal errors. Please consider fixing them.
ERROR: chipsec-1.2.5+-r0 do_package_qa: Function failed: do_package_qa
ERROR: Logfile of failure stored in: /data/code/luv-yocto-32/build/tmp/ work/qemux86-oe-linux/chipsec/1.2.5+-r0/temp/log.do_package_qa.108703
ERROR: Task (/data/code/luv-yocto-32/meta-luv/recipes-core/chipsec/ chipsec_git.bb:do_package_qa) failed with exit code '1'

---
 meta-luv/recipes-core/chipsec/chipsec_git.bb | 5 +++++
 meta/lib/oe/terminal.py                      | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)
meta-luv/recipes-core/chipsec/chipsec_git.bb +5 -0
index 4778a03..a21c8bd 100644
@@ -86,6 +86,11 @@ do_install_append() {
     cd ${D}${PYTHON_SITEPACKAGES_DIR}
     ls | grep -v chipsec | xargs rm -fr
     cd $OLDPWD
+
+    if [ ! "${TARGET_ARCH}" = "x86_64" ]; then
+        rm ${D}${PYTHON_SITEPACKAGES_DIR}/${PN}/chipsec_tools/linux/LzmaCompress.bin
+        rm ${D}${PYTHON_SITEPACKAGES_DIR}/${PN}/chipsec_tools/linux/TianoCompress.bin
+    fi
 }
 
 LUV_TEST_LOG_PARSER="luv-parser-chipsec"
meta/lib/oe/terminal.py +2 -1
index 3901ad3..22cb5d7 100644
@@ -67,7 +67,8 @@ class Gnome(XTerminal):
         import tempfile
         pidfile = tempfile.NamedTemporaryFile(delete = False).name
         try:
-            sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd
+            #sh_cmd = "oe-gnome-terminal-phonehome " + pidfile + " " + sh_cmd
+            sh_cmd = bb.utils.which(os.getenv('PATH'), "oe-gnome-terminal-phonehome") + " " + pidfile + " " + sh_cmd
             XTerminal.__init__(self, sh_cmd, title, env, d)
             while os.stat(pidfile).st_size <= 0:
                 continue
Signature · 1 line
2.9.3