Skip to content

Conversation

@tlaurion
Copy link
Collaborator

@tlaurion tlaurion commented May 16, 2025

Fixes #1969 in f9afeb7

data.cpio should have hash of 879be3583e8a7ad429e969cba378d000f36cfd7d11acbebda78c0f0bb94eab1f for most boards.

Verified over Circleci t480, x230. And local builds.


TLDR: kbd archive contained hardlinked files which cp -a --remove-destination was not able to reproducibly put in data temp dir.


Details :
There was an issue where initrd_tmp_dir was used to create tools.cpio and wipe that dir, while data.cpio was subdirectory of initrd_tmp_dir. This PR seperates tools.cpio temp dir from data.cpio temp dir:

  • tools.cpio: initrd_tmp_dir/tools/{bin,lib}
  • data.cpio: initrd_tmp_dir/data

So that when wiping happens of a subdir, this doesn't affect others:

  • initrd_tmp_dir = mktemp -d
  • initrd_tools_dir = initrd_tmp_dir/tools
  • initrd_bin_dir = initrd_tools_dir/bin
  • initrd_lib_dir = initrd_tools_dir/lib
  • initrd_data_dir = initrd_tmp_dir/data

This commit:

  • Use proper variable names everywhere, no more initrd_tmp_dir.
    • initrd_tools_dir, initrd_lib_dir, initrd_bin_dir, initrd_data_dir
  • change to busybox (initrd_tmp_dir/bin -> initrd_bin_dir) as well and review all other modules
  • simplifies data files/dir registration and remove hardlink support: we want multiple copies of files that would be harlinked: cpio will be compressed to deduplicate.

…or tools.cpio dir (initrd_tmp_dir/tools/bin+lib) and data (initrd_tmp_dir/data) so that wiping tools don't wipe data

There was an issue where initrd_tmp_dir was used to create tools.cpio and wipe that dir, while data.cpio was subdirectory of initrd_tmp_dir.
This seperates tools.cpio temp dir from data.cpio temp dir:
- tools.cpio:	initrd_tmp_dir/tools/{bin,lib}
- data.cpio:	initrd_tmp_dir/data

So that when wiping happens of a subdir, this doesn't affect others:
- initrd_tmp_dir = mktemp -d
- initrd_tools_dir = initrd_tmp_dir/tools
- initrd_bin_dir = initrd_tools_dir/bin
- initrd_lib_dir = initrd_tools_dir/lib
- initrd_data_dir = initrd_tmp_dir/data

This commit:
- Use proper variable names everywhere, no more initrd_tmp_dir.
  - initrd_tools_dir, initrd_lib_dir, initrd_bin_dir, initrd_data_dir
- change to busybox (initrd_tmp_dir/bin -> initrd_bin_dir) as well and review all other modules

Signed-off-by: Thierry Laurion <[email protected]>
@tlaurion
Copy link
Collaborator Author

@JonathonHall-Purism

TLDR:

  • data.cpio, with default keymap per modules/linux's 6.1.8 + modules/kbd keyboard layouts should have hash of
    `879be3583e8a7ad429e969cba378d000f36cfd7d11acbebda78c0f0bb94eab1f /home/user/heads/build/x86/x230-hotp-maximized/data.cpio'

Unfortunately, its not the case all the time:

user@heads-master2:~/heads./docker_repro.sh diffoscope /home/user/heads/build/x86/t480-hotp-maximized/data.cpio /home/user/heads/build/x86/x230-hotp-maximized/data.cpio
Using CircleCI Docker image: tlaurion/heads-dev-env:v0.2.5
----
Usage reminder: The minimal command is 'make BOARD=XYZ', where additional options, including 'V=1' or 'CPUS=N' are optional.
For more advanced QEMU testing options, refer to targets/qemu.md and boards/qemu-*/*.config.

Type exit within docker image to get back to host if launched interactively!
----

--->Launching container with access to host's USB buses (some USB devices were connected to host)...
--- /home/user/heads/build/x86/t480-hotp-maximized/data.cpio
+++ /home/user/heads/build/x86/x230-hotp-maximized/data.cpio
│┄ Installing the 'binwalk' Python module may produce a better output.
├── file list
│ @@ -224,15 +224,15 @@
│  -rw-------   0        0        0     2978 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/fr_CH.map
│  -rw-------   0        0        0     3645 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/hu.map
│  -rw-------   0        0        0     3172 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sg-latin1-lk450.map
│  -rw-------   0        0        0     3360 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sg-latin1.map
│  -rw-------   0        0        0     3161 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sg.map
│  -rw-------   0        0        0     9772 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sk-prog-qwertz.map
│  -rw-------   0        0        0     9940 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sk-qwertz.map
│ --rw-------   0        0        0        0 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/slovene.map
│ +-rw-------   0        0        0     3352 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/slovene.map
│  -rw-------   0        0        0     3352 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sr-latin.map
│  drwx------   0        0        0        0 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include
│  -rw-------   0        0        0      517 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.8859_7
│  -rw-------   0        0        0       23 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.8859_8
│  -rw-------   0        0        0     6030 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.latin
│  -rw-------   0        0        0     3889 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.latin1
│  -rw-------   0        0        0     3465 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.latin2
├── usr/lib/kbd/keymaps/i386/qwertz/slovene.map

i'm out of ideas here @JonathonHall-Purism
The data.cpio changes were introduced by #1961

So the broken changes are somewhere in those lines (introducing data.cpio to master):
ef2da59...master

Where changes of this PR don't seem to fix it.

The two data.cpio compared, one with good hash and whole slovene.map, the other with 0 byte slovene.map. No clue why 0 byte slovene.map.
data_cpios.tar.gz

@tlaurion tlaurion marked this pull request as draft May 16, 2025 18:25
@tlaurion
Copy link
Collaborator Author

@JonathonHall-Purism

This board build: https://app.circleci.com/pipelines/github/tlaurion/heads/3343/workflows/ef3f1c47-ebeb-41d3-91be-9b06dc3d224a/jobs/68321/steps

CircleCI just finished t480-hotp-maximized invalid data.cpio with 0 byte keymap:
911ff63584bd4f3115efe4fe44aacec29dca47bc0e32f1d7d546ddacf266eb02 /root/heads/build/x86/t480-hotp-maximized/data.cpio

As can be seen in hashes.txt

So to repro:

@tlaurion
Copy link
Collaborator Author

tlaurion commented May 16, 2025

Some additional notes @JonathonHall-Purism :

Note that an empty file hash is e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 (as can be seen for cryptsetup placeholder file under hashes.txt and sizes.txt for ./run/cryptsetup/.placeholder

  • hashes.txt: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ./run/cryptsetup/.placeholder
  • sizes.txt: 0:./run/cryptsetup/.placeholder

So at the time of populating hashes.txt and sizes.txt, usr/lib/kbd/keymaps/i386/qwertz/slovene.map is valid; but not at the time of actually creating data.cpio, or something random happens when creating data.cpio, and only with slovene.map.

I'm really puzzled right now.

@tlaurion
Copy link
Collaborator Author

And x230-hotp-maximized has the good hash

So full repro to compare data.cpio of t480-hotp-maximized (bad) with x230-hotp-maximized (good)

--- good_x230-data.cpio
+++ bad_t480-data.cpio
│┄ Installing the 'binwalk' Python module may produce a better output.
├── file list
│ @@ -224,15 +224,15 @@
│  -rw-------   0        0        0     2978 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/fr_CH.map
│  -rw-------   0        0        0     3645 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/hu.map
│  -rw-------   0        0        0     3172 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sg-latin1-lk450.map
│  -rw-------   0        0        0     3360 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sg-latin1.map
│  -rw-------   0        0        0     3161 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sg.map
│  -rw-------   0        0        0     9772 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sk-prog-qwertz.map
│  -rw-------   0        0        0     9940 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sk-qwertz.map
│ --rw-------   0        0        0     3352 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/slovene.map
│ +-rw-------   0        0        0        0 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/slovene.map
│  -rw-------   0        0        0     3352 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/i386/qwertz/sr-latin.map
│  drwx------   0        0        0        0 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include
│  -rw-------   0        0        0      517 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.8859_7
│  -rw-------   0        0        0       23 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.8859_8
│  -rw-------   0        0        0     6030 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.latin
│  -rw-------   0        0        0     3889 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.latin1
│  -rw-------   0        0        0     3465 1970-01-01 00:00:00.000000 usr/lib/kbd/keymaps/include/compose.latin2

…d from src|dst in modules; simplify logic (no cp -a --remove-destination; cp -R)

Signed-off-by: Thierry Laurion <[email protected]>
@tlaurion
Copy link
Collaborator Author

tlaurion commented May 16, 2025

@JonathonHall-Purism after off channel discussion, @JonathonHall-Purism pointed me that some Makefile code was interpreted at build time and not Makefile processing time; directory checks were always failing prior of kbd being compiled (so archive decompressed to check directories and files under it).

It was also noted that the two problematic files under kbd keymaps were hardlinks of each other
(usr/lib/kbd/keymaps/i386/qwertz/sr-latin.map and usr/lib/kbd/keymaps/i386/qwertz/sr-latin.map), and hardlinks should not be respected in cpio. The original cp -a --remove-destination must be the cause of it; so it was removed.

Note that having multiple copies of same files content, increasing space consumption instead of hardlinking doesn't make sense for cpio, since any duplicated space will be saved back with compression. And we don't care much about ram consumption for bootloader.

So data.cpio was simplified to deal wirh src|dst registration under modules, copy into a differenciates data temp dir, and have that temp dir used to create data.cpio through /bin/clean-cpio to finally remove technical debt introduced by whiptail coloring with terminfo a while ago,useful for (not used much...) server BMC/ssh server console.

f9afeb7 should be reproducible.

Tested:

  • sudo rm build/x86/kbd-2.6.1/ build/x86/t480-hotp-maximized/ -rf
  • ./docker_repro.sh make BOARD=t480-hotp-maximized
2025-05-16 21:22:57+00:00 CPIO      build/x86/t480-hotp-maximized/data.cpio
879be3583e8a7ad429e969cba378d000f36cfd7d11acbebda78c0f0bb94eab1f  /home/user/heads/build/x86/t480-hotp-maximized/data.cpio
  • ./docker_repro.sh make BOARD=t480-hotp-maximized
2025-05-16 21:24:13+00:00 UNCHANGED build/x86/t480-hotp-maximized/data.cpio
879be3583e8a7ad429e969cba378d000f36cfd7d11acbebda78c0f0bb94eab1f  /home/user/heads/build/x86/t480-hotp-maximized/data.cpio
 2508800:/home/user/heads/build/x86/t480-hotp-maximized/data.cpio

@tlaurion tlaurion changed the title Makefile: initrd creation refactoring to seperate mktemp initrd dir for tools.cpio dir (initrd_tmp_dir/tools/bin+lib) and data (initrd_tmp_dir/data) so that wiping tools don't wipe data Makefile: initrd refactoring and data.cpio simplification May 17, 2025
@tlaurion tlaurion marked this pull request as ready for review May 17, 2025 04:50
@tlaurion
Copy link
Collaborator Author

This is bugfix still, merging.

@tlaurion tlaurion merged commit f110e1b into linuxboot:master May 17, 2025
47 checks passed
@JonathonHall-Purism
Copy link
Collaborator

Yes looks like that should do it, thanks.

@tlaurion tlaurion mentioned this pull request May 20, 2025
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

data.cpio constructed in a non-reproducible way

2 participants