-
Notifications
You must be signed in to change notification settings - Fork 37
update wolfboot for option of using local wolfssl source and add wolfhsm recipe #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
965c98d
7434ef2
46251a5
48d08af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,14 @@ | |
| # | ||
| # Optional format variables: | ||
| # COMMERCIAL_BUNDLE_FILE - Bundle filename including extension (defaults to <NAME>.7z) | ||
| # COMMERCIAL_BUNDLE_URL - URL bitbake fetches the bundle from, e.g. an https:// | ||
| # link to a publicly downloadable GPLv3 FIPS Ready release. Avoids having to | ||
| # stage the archive on every build host. | ||
| # COMMERCIAL_BUNDLE_GCS_URI - gs:// path to the protected bundle | ||
| # COMMERCIAL_BUNDLE_SRC_DIR - Direct path to already-extracted source directory (skips fetch/extract) | ||
| # | ||
| # Resolution order in get_commercial_src_uri: SRC_DIR (no fetch), then URL, then | ||
| # GCS_URI, then a local file under COMMERCIAL_BUNDLE_DIR. | ||
|
|
||
| # Commercial bundles already ship generated configure scripts, so skip autoreconf | ||
| AUTOTOOLS_AUTORECONF = "no" | ||
|
|
@@ -67,11 +73,17 @@ def get_commercial_src_uri(d): | |
| gcs_uri = d.getVar('COMMERCIAL_BUNDLE_GCS_URI') | ||
| placeholder = d.getVar('COMMERCIAL_BUNDLE_PLACEHOLDER') or '' | ||
|
|
||
| if gcs_uri and bundle_archive: | ||
| # A plain download URL and a gs:// path are handled identically here: both | ||
| # are just a URI bitbake's fetcher understands. COMMERCIAL_BUNDLE_URL takes | ||
| # precedence so a recipe can offer the public download as its default while | ||
| # still allowing a GCS override. | ||
| remote_uri = d.getVar('COMMERCIAL_BUNDLE_URL') or gcs_uri | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When BitBake cannot find a variable, it does not blank it out. It leaves the raw text |
||
|
|
||
| if remote_uri and bundle_archive: | ||
| unpack_flag = ';unpack=false' if bundle_archive.endswith('.7z') else '' | ||
| sha_flag = f';sha256sum={bundle_sha}' if bundle_sha else '' | ||
| filename_flag = f';downloadfilename={bundle_archive}' | ||
| return f'{gcs_uri}{filename_flag}{unpack_flag}{sha_flag}' | ||
| return f'{remote_uri}{filename_flag}{unpack_flag}{sha_flag}' | ||
|
|
||
| bundle_dir = d.getVar('COMMERCIAL_BUNDLE_DIR') | ||
|
Comment on lines
+82
to
88
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This task exists to unpack password-protected .7z bundles by hand, which is why it wants a folder to look in. A plain .zip from a URL needs none of that, because BitBake has already downloaded and unpacked it. The task knows this at line 198, where it says "not a .7z, let BitBake handle it" and returns, but line 186 demands the folder first and stops the build before getting there. I built it: do_fetch succeeds, then |
||
|
|
||
|
|
@@ -126,6 +138,7 @@ COMMERCIAL_BUNDLE_SHA ?= "" | |
| COMMERCIAL_BUNDLE_TARGET ?= "${WORKDIR}" | ||
| COMMERCIAL_BUNDLE_PLACEHOLDER ?= "${WOLFSSL_LAYERDIR}/recipes-wolfssl/wolfssl/commercial/files/README.md" | ||
| COMMERCIAL_BUNDLE_GCS_URI ?= "" | ||
| COMMERCIAL_BUNDLE_URL ?= "" | ||
| COMMERCIAL_BUNDLE_SRC_DIR ?= "" | ||
| COMMERCIAL_BUNDLE_ARCHIVE = "${@get_commercial_bundle_archive(d)}" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,26 +3,129 @@ | |
| # Pulls the wolfBoot source tree and the wolfSSL submodule source side-by-side. | ||
| # wolfBoot bundles wolfSSL under lib/wolfssl, so we stage wolfSSL there instead | ||
| # of fetching it from the wolfBoot submodule pointer (keeps the two SRCREVs | ||
| # explicit and greppable). | ||
| # explicit and greppable). Set WOLFBOOT_WOLFSSL_SRC to build against an | ||
| # existing wolfSSL source tree instead, see the block below. | ||
|
|
||
| HOMEPAGE = "https://github.com/wolfssl/wolfBoot" | ||
| BUGTRACKER = "https://github.com/wolfssl/wolfBoot/issues" | ||
| SECTION = "bootloaders" | ||
| LICENSE = "GPL-3.0-only" | ||
| LIC_FILES_CHKSUM = "file://LICENSE;md5=1ebbd3e34237af26da5dc08a4e440464" | ||
|
|
||
| # --- Optional: build against an existing wolfSSL source tree ---------------- | ||
| # | ||
| # Set WOLFBOOT_WOLFSSL_SRC to the absolute path of a wolfSSL source tree to | ||
| # build wolfCrypt from it instead of the pinned copy fetched below. When it is | ||
| # set the wolfSSL entry drops out of SRC_URI entirely and nothing is downloaded | ||
| # making SRCREV_wolfssl unused. | ||
| # | ||
| # NOTE: this reuses a source *tree*, not a built library. wolfBoot compiles the | ||
| # wolfCrypt sources itself into a -nostdlib bare-metal image; it can never link | ||
| # against the target libwolfssl.so that the wolfssl recipe produces. | ||
| WOLFBOOT_WOLFSSL_SRC ?= "" | ||
|
|
||
| # Private copy of that tree, made by do_stage_external_wolfssl below. The copy | ||
| # is not an optimisation: wolfBoot compiles objects *alongside* the wolfCrypt | ||
| # sources ($(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/*.o, in both options.mk and | ||
| # tools/keytools/Makefile), so building in place would write into the caller's | ||
| # tree -- and race with it if it belongs to another recipe. Copying also lets | ||
| # WOLFBOOT_WOLFSSL_SRC live somewhere read-only or shared. | ||
| WOLFBOOT_WOLFSSL_STAGED_SRC = "${WORKDIR}/wolfssl-external" | ||
|
|
||
| # NOTE: SRCREVs below are pinned to wolfSSL/wolfBoot master and | ||
| # wolfSSL/wolfssl master tips at the time of writing. Bump these as | ||
| # upstream evolves. Downstream users can override via local.conf: | ||
| # SRCREV_wolfboot:pn-wolfboot = "<sha>" | ||
| # SRCREV_wolfboot:pn-wolfboot-keytools-native = "<sha>" | ||
| SRC_URI = " \ | ||
| git://github.com/wolfssl/wolfBoot.git;protocol=https;branch=master;name=wolfboot;destsuffix=git \ | ||
| git://github.com/wolfssl/wolfssl.git;protocol=https;branch=master;name=wolfssl;destsuffix=git/lib/wolfssl \ | ||
| ${@'' if d.getVar('WOLFBOOT_WOLFSSL_SRC') else 'git://github.com/wolfssl/wolfssl.git;protocol=https;branch=master;name=wolfssl;destsuffix=git/lib/wolfssl'} \ | ||
| " | ||
| SRCREV_wolfboot ?= "9a667f2a7527da2b8e490ae7923665321af2d3ac" | ||
| SRCREV_wolfssl ?= "1d363f3adceba9d1478230ede476a37b0dcdef24" | ||
| SRCREV_FORMAT = "wolfboot_wolfssl" | ||
| SRCREV_FORMAT = "${@'wolfboot' if d.getVar('WOLFBOOT_WOLFSSL_SRC') else 'wolfboot_wolfssl'}" | ||
|
|
||
| def wolfboot_wolfssl_src_id(d): | ||
| """Fingerprint the external wolfSSL tree: relative path, size and mtime of | ||
| every file. Fed into the task hashes below so that editing the tree rebuilds | ||
| wolfBoot. BitBake otherwise hashes only the WOLFBOOT_WOLFSSL_SRC *string*, | ||
| and changes to its contents would silently reuse a stale wolfboot.elf. | ||
| Returns '' (and costs nothing) when the feature is not in use.""" | ||
| import os | ||
| import hashlib | ||
|
|
||
| src = d.getVar('WOLFBOOT_WOLFSSL_SRC') | ||
| if not src or not os.path.isdir(src): | ||
| return '' | ||
|
|
||
| h = hashlib.sha256() | ||
| for root, dirs, files in os.walk(src): | ||
| # Same pruning as the copy below, so the fingerprint tracks exactly | ||
| # what gets staged. | ||
| dirs[:] = sorted(x for x in dirs if x not in ('.git', '.libs')) | ||
| for name in sorted(files): | ||
| path = os.path.join(root, name) | ||
| try: | ||
| st = os.lstat(path) | ||
| except OSError: | ||
| continue | ||
| entry = '%s %d %d\n' % (os.path.relpath(path, src), | ||
| st.st_size, st.st_mtime_ns) | ||
| h.update(entry.encode()) | ||
| return h.hexdigest() | ||
|
|
||
| WOLFBOOT_WOLFSSL_SRC_ID = "${@wolfboot_wolfssl_src_id(d)}" | ||
|
|
||
| python check_wolfboot_wolfssl_src() { | ||
| import os | ||
|
|
||
| src = d.getVar('WOLFBOOT_WOLFSSL_SRC') or '' | ||
| if not src: | ||
| return | ||
| if not os.path.isabs(src): | ||
| bb.fatal("WOLFBOOT_WOLFSSL_SRC='%s' must be an absolute path. wolfBoot's " | ||
| "Makefile only abspaths WOLFBOOT_LIB_WOLFSSL when the value " | ||
| "comes from a makefile; the recipe passes it on the make " | ||
| "command line, which overrides that assignment, so a relative " | ||
| "path reaches every sub-makefile verbatim and resolves against " | ||
| "whichever working directory each one runs in." % src) | ||
| if not os.path.isdir(os.path.join(src, 'wolfcrypt', 'src')): | ||
| bb.fatal("WOLFBOOT_WOLFSSL_SRC='%s' does not look like a wolfSSL source " | ||
| "tree (no wolfcrypt/src directory)." % src) | ||
| } | ||
|
|
||
| do_stage_external_wolfssl() { | ||
| if [ -z "${WOLFBOOT_WOLFSSL_SRC}" ]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| rm -rf "${WOLFBOOT_WOLFSSL_STAGED_SRC}" | ||
| mkdir -p "${WOLFBOOT_WOLFSSL_STAGED_SRC}" | ||
|
|
||
| # Prebuilt objects are excluded so a natively-configured wolfSSL tree | ||
| # (./configure && make) cannot leak host x86 .o/.a files into the cross | ||
| # build: wolfBoot's object paths sit inside this tree, and make would | ||
| # happily reuse an existing .o that is newer than its .c. | ||
| tar -cf - -C "${WOLFBOOT_WOLFSSL_SRC}" \ | ||
| --exclude=.git --exclude=.libs \ | ||
| --exclude='*.o' --exclude='*.lo' --exclude='*.a' --exclude='*.la' \ | ||
| --exclude='*.so' --exclude='*.so.*' \ | ||
| . | tar -xf - -C "${WOLFBOOT_WOLFSSL_STAGED_SRC}" | ||
|
|
||
| # Guard against a half-copied tree: the pipeline above reports only the | ||
| # extract side's exit status under a plain POSIX shell. | ||
| if [ ! -f "${WOLFBOOT_WOLFSSL_STAGED_SRC}/wolfcrypt/src/asn.c" ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This catches a copy that produced nothing at all. It will not catch one that started fine and died halfway, disk filling up, or a permissions problem part way down. In that case asn.c already exists, the check passes, and the build carries on with an incomplete tree. Not sure if this is something we want to account for. |
||
| bbfatal "Failed to stage WOLFBOOT_WOLFSSL_SRC='${WOLFBOOT_WOLFSSL_SRC}':" \ | ||
| "wolfcrypt/src/asn.c is missing from the copy at" \ | ||
| "${WOLFBOOT_WOLFSSL_STAGED_SRC}." | ||
| fi | ||
|
|
||
| chmod -R u+w "${WOLFBOOT_WOLFSSL_STAGED_SRC}" | ||
| } | ||
| do_stage_external_wolfssl[prefuncs] += "check_wolfboot_wolfssl_src" | ||
| do_stage_external_wolfssl[vardeps] += "WOLFBOOT_WOLFSSL_SRC_ID" | ||
| do_compile[vardeps] += "WOLFBOOT_WOLFSSL_SRC_ID" | ||
| addtask stage_external_wolfssl after do_unpack before do_compile | ||
|
|
||
| python () { | ||
| if d.getVar('UNPACKDIR', False): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment says GCS can still override, but
url or gcs_urimeans a non-empty URL wins and gcs_uri is never read. Might be good to comment that if both are set GCS is ignored.