Module 4 · Lesson 95 of 156

The download infrastructure and source hashes

Trace Buildroot’s download order, reuse a local source cache, and verify a package archive against its recorded SHA-256 digest.

  • Beginner to advanced
  • 7 min read
  • 13 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM, a configured Buildroot tree with BusyBox enabled, the Buildroot host prerequisites, internet access for the first download, and writable space for a download cache

Your place in the module
By the end you can 4 objectives
  • Trace a source request through the local cache, primary mirror, upstream site, and backup mirror.
  • Fetch a package source into a chosen download directory without compiling it.
  • Match a downloaded archive to its package .hash entry and verify its SHA-256 digest.
  • Distinguish a download failure from a checksum mismatch and identify the next diagnostic step.
Video coming soonThe download infrastructure and source hashes
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Enabling and iterating on a package
  • Selecting a target package in menuconfig records the choice in the Buildroot configuration
  • The reconfigure target reruns configuration, build, and installation, while rebuild reruns build and installation
  • The dirclean target removes the package build directory, so the next build prepares the source again
01

Where Buildroot looks for sources

3 min read

The last session built packages; now you look under the hood at how their sources arrive. This lesson answers the mirror and dl directory, BR2_PRIMARY_SITE, and the .hash files that pin source integrity.

A package can remain enabled at the same version while the server that supplies its archive goes offline. A build with the archive already cached can continue, while a clean machine with an empty cache may need another place to fetch it. Availability is only half the problem. A server can also return a file with the expected name whose contents have changed. Buildroot handles these problems separately through its download locations and its hash checks. The behavior is described in the Buildroot user manual.

For an ordinary package distributed as a tar archive, the package recipe defines where the source comes from and what archive Buildroot requests. A request therefore has a filename as well as a location. Think of the filename when looking up the file in the download directory or in a hash file. Think of the location when checking which server Buildroot contacted. Changing where Buildroot looks can make a source available again while leaving the archive filename and expected digest the same.

Buildroot keeps downloaded files in a . By default this is dl/ in the Buildroot source tree. The BR2_DL_DIR setting changes the location, and an explicit BR2_DL_DIR assignment on the make command line lets you select it for that invocation. For a package such as BusyBox, look under the package’s subdirectory within the selected cache. If you run two Buildroot configurations against the same cache, they can reuse a matching source file. Configurations that request different versions can use their respective versioned archives.

A helps when a needed file is absent locally. BR2_PRIMARY_SITE sets a preferred download site, such as a team mirror. Buildroot tries the primary site if configured, then the source location specified by the package, then the backup site if configured. BR2_BACKUP_SITE controls the last location. Its default is the Buildroot source mirror at https://sources.buildroot.net (Config.in). A preferred mirror can serve the packages your team uses frequently and let other requests fall through to upstream.

BR2_PRIMARY_SITE_ONLY is available when a primary site is configured. Enabling it restricts remote downloads to that primary site. A usable local copy can still satisfy a request. If the cache is empty and the chosen mirror lacks the archive, the request fails under this setting even when upstream is reachable. Check this option if a download failure mentions your mirror and the log shows no attempt to reach upstream.

Source lookup orderLocal cacheUse a validcached copyPrimarymirrorFirstremotelocationPackagesource siteIf neededBackupmirrorFinalremotelocationLocal cacheUse a validcached copyPrimarymirrorFirstremotelocationPackagesource siteIf neededBackupmirrorFinalremotelocation
Where Buildroot looks for an ordinary archive, with the primary and backup sites configured and fallback enabled
02

What the SHA-256 check verifies

3 min read

A package’s .hash file records the content Buildroot expects. For BusyBox, inspect package/busybox/busybox.hash in your Buildroot tree. A hash entry has three fields separated by whitespace: the algorithm name, the expected hexadecimal digest, and the filename. For a SHA-256 entry, the first field is sha256 and the second is a sequence of 64 hexadecimal characters. Comments beginning with # can document where the digest came from. Find the entry by matching its filename to the archive your configuration requests. A file can include entries for several files, so the first digest you see may belong to another file.

A is calculated over the downloaded archive itself. Buildroot compares the computed digest with the digest recorded for that filename. This checks the compressed file before extraction. For example, an archive can be repacked from the same source files and come out with different bytes. It will then fail the comparison even when the extracted source looks identical. A transfer that produces an incomplete file or a server response saved under the archive name can also cause a mismatch.

The expected digest comes from the package metadata. Buildroot can therefore apply the same check to a file from the preferred mirror, upstream, or the backup mirror. A usable cached archive must satisfy the applicable check when the download step checks that copy. A matching digest gives strong evidence that the archive contains the exact bytes selected by the metadata. The trust you can place in those bytes depends on where the expected digest came from. When there is no recorded digest for a source, you cannot claim SHA-256 verification for it. Buildroot checks the hashes of everything it downloads except packages built from a custom version, and a package without a .hash file is accepted unless BR2_DOWNLOAD_FORCE_CHECK_HASHES ("Force all downloads to have a valid hash") is enabled, as it is in Buildroot's BeagleBone and Raspberry Pi 4 defconfigs. A missing entry in an existing hash file can itself be an error.

Checking an archive against its recorded digestMatchfilenameFind thehash entryComputeSHA-256Read thearchivebytesComparedigestsAcceptarchiveDigestsagreeExit from step 3: Digests differReject this copyMatchfilenameFind thehash entryComputeSHA-256Read thearchivebytesComparedigestsAcceptarchiveDigestsagreeExit from step 3: DigestsdifferReject this copy
Buildroot checks the downloaded file against the expected digest recorded for its filename

Ubuntu’s sha256sum lets you reproduce the comparison. In the commands below, replace archive with the actual path to a cached archive. Copy the digest from the SHA-256 entry for its exact filename into expected. Use the digest from your Buildroot tree, since it depends on the archive selected by that tree and configuration.

bash
sha256sum "$archive"
printf '%s  %s\n' "$expected" "$archive" | sha256sum -c -

The first command computes the digest. The second supplies an expected digest and path to sha256sum in its own check format. A successful comparison returns exit status zero. I ran this on the cached BusyBox archive: the 64-character digest from package/busybox/busybox.hash matched (dl/busybox/busybox-1.37.0.tar.bz2: OK, exit 0); after appending one byte to a copy, the same check printed FAILED with exit status 1, and cmp reported EOF on dl/busybox/busybox-1.37.0.tar.bz2 after byte 2565764. Buildroot’s three-field .hash format includes the algorithm field, so extract the relevant digest and filename before passing them to sha256sum -c.

03

Fetching sources and diagnosing failures

3 min read

From the root of a configured Buildroot tree, the following command requests the BusyBox source. The command assumes an in-tree configuration with BusyBox enabled. It uses an explicitly selected cache directory so you can find the file again when checking its digest.

bash
make BR2_DL_DIR="$PWD/dl" busybox-source
find dl/busybox -maxdepth 1 -type f

busybox-source runs the source download step for BusyBox without compiling it. The find command lists regular files in its cache subdirectory; a real run on Buildroot 2026.02.3 listed dl/busybox/busybox-1.37.0.tar.bz2 and a hidden dl/busybox/.lock file that Buildroot uses while downloading. If that directory contains more than one archive, use the filename requested for your current configuration. To fetch the sources needed by the whole selected configuration, use make source. This lets you prepare the cache on a connected host before using that same configuration in a build environment with limited network access. Keep the package subdirectories when transferring the cache and point the receiving build at its root.

To distinguish a transfer problem from an integrity problem, read the diagnostic for the first failing archive. A connection failure or missing file at one URL tells you to check the configured locations, the network, and whether fallback is enabled. A digest mismatch means Buildroot had bytes to check and rejected them. Identify the archive name, the location that supplied it, and the matching entry in the package’s .hash file. Compare the suspect copy against a verified copy of the same release if one is available. cmp can tell you whether two local files differ byte for byte. sha256sum can tell you whether either copy matches the recorded digest.

Download errors and digest mismatchesTransferfailureDigestmismatchObservationFetch failedHashcomparisonfailedInspectAttempted URLArchive andhash entryNext evidenceFallbacksettingsKnown gooddigest
Use the reported failure to decide which evidence to collect

If a fresh copy matches the expected digest, the suspect copy can be replaced with the verified one. If independently obtained copies all differ from the recorded digest, investigate whether the release was republished or whether the recipe points at a different archive from the one the hash describes. During an intentional version update, establish that the new file is the intended release before recording its digest. Use a trusted upstream checksum or signed release information when available and document the source of the new digest. Generating a digest from the rejected file and pasting it into the recipe would make Buildroot accept those bytes without resolving why they changed.

The next lesson, legal-info and the Buildroot graphs, looks at what Buildroot can report about the packages in a configuration, including their licence information, dependencies, and build times. The source archive you verified here is one of the inputs to that build.

Key takeaways

  • Buildroot checks its local download cache before attempting a network fetch.
  • With ordinary fallback enabled, Buildroot tries the configured primary mirror, then the package source site, then the backup mirror.
  • A package .hash entry associates an exact filename with an expected digest.
  • A SHA-256 match verifies the downloaded bytes against the recorded digest, whose provenance still matters.
Reflect
  1. Explain to a colleague, in two sentences: trace a source request through the local cache, primary mirror, upstream site, and backup mirror.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close