Commit Graph

114 Commits (e18af2022ae17c37eabab4367fcac620baf1a595)

Author SHA1 Message Date
Leah Rowe e18af2022a lib.sh: simplify the python check
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:32:51 +01:00
Leah Rowe 46e6169495 lib.sh: add missing copyright year
alper made a fix to this file a few hours ago, but
forgot to update the copyright header

i'm doing it for alper, as a courtesy

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:32:23 +01:00
Alper Nebi Yasak d9908ca648 lib.sh: Fix python3 detection when 'python' is python2
Properly set $pyver to "3" when we detect we can use python3. In the
following version checks, use the $python we detected instead of a
'python' from PATH because the latter might be a python2 while still
co-existing with a python3.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2025-04-30 15:31:34 +01:00
Leah Rowe ec25425e55 lib.sh: perform root check even earlier
initialising variables, setting PWD, setting version,
this is all unnecessary before the root check, because
the dependencies commands use none of these.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:01:48 +01:00
Leah Rowe dbf40653b2 lib.sh: tidy up opening logic (put it together)
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:01:41 +01:00
Leah Rowe 46fb5786e0 lib.sh: do root check before python check
we don't need python before the root check

principle of least privilege

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:01:35 +01:00
Leah Rowe c8c5a0e017 lib.sh: simplify mktarball()
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:01:10 +01:00
Leah Rowe b399252309 lib.sh: fix missing s/TMPDIR/xbmktmp
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 15:00:04 +01:00
Leah Rowe 72c83cdaeb cbmk: don't handle TMPDIR directly
cbmk creates TMPDIR as /tmp/xbmk_*, but it's theoretically
possible that something could re-export it by mistake.

this change retains the same initialisation, but further
use is now via a new variable "xbmktmp", that stores the
value of TMPDIR upon cbmk's initialisation of it.

this reduces the chance of such a bug in the future, as
described above, so it is a preemptive/preventative fix.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 14:59:26 +01:00
Leah Rowe 6fc23805cb lib.sh mktarball: stricter tar error handling
There was no error handling, *at all*, on the actual tar
command, due to the lack of set -o pipefail, which we cannot
rely on in sh.

The x_ wrapper can be used in this case, as a mitigation.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-30 14:37:45 +01:00
Leah Rowe d65d93b300 Revert "lib.sh: use eval for the command in x_"
This reverts commit 7c98661271.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:58:37 +01:00
Leah Rowe 0aace67a54 lib.sh: fix bad eval writing version/versiondate
x_ cannot be used, where output is redirected to a file;
only the convention piping can be used, for errors.

relying on x_ in these cases will cause unpredictable bugs.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:57:19 +01:00
Leah Rowe 7c98661271 lib.sh: use eval for the command in x_
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:57:09 +01:00
Leah Rowe d0b95ffe6e lib.sh: tidy up the error handling
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:53:58 +01:00
Leah Rowe ca6a3c8958 remove xbmk_parent, handle forking in lib.sh
I was using a complicated method of knowing whether
the current instance was parent or a child, to know
whether the lock file and TMPDIR needed to be purged.

It was quite error-prone too. Instead, I'm now handling
it directly from within the if statement that previously
initialised xbmk_parent=y, forking ./mk from there.

The forked instance would not trigger that if clause
again, since then TMPDIR is created, thus avoiding
recursion.

This is an improvement because it doesn't rely on how
the parent handles exit statuses, and it ensures that
the lock/tmp files are never accidentally deleted.

Even if a given program/script that cbmk runs would
export TMPDIR, it doesn't matter because cbmk doesn't,
so it would be unaffected.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:49:12 +01:00
Leah Rowe f3c757c2d2 lib.sh: define x_ right after err_
because the top-down function order isn't as reliable
in lib.sh, since this is what first runs, included
in every other script

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:47:28 +01:00
Leah Rowe 3b2718bd9d lib.sh: minor cleanup
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:47:07 +01:00
Leah Rowe 4cb9db2ba2 lib.sh: write version/versiondate to dotfiles
write to .version and .versiondate, instead
of version and versiondate.

this will hide them to avoid visual clutter while
analysing files within cbmk.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:19:20 +01:00
Leah Rowe f0dcaca4ee lib.sh: hardcode projectname/projectsite
remove the corresponding files, containing these strings

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-14 01:18:00 +01:00
Leah Rowe 9130750ebb lib.sh: double-quote pwd to prevent globbing
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11 20:41:12 +01:00
Leah Rowe 12e600bf5c cbmk: unified PWD handling (work directory)
instead of running pwd all the time, run it once in lib.sh,
and export PWD.

for cbmk-specific use of PWD, use xbmkpwd, which contains
the value of PWD as was set by the pwd utility in lib.sh.

many parts of cbmk rely on pwd, and it *must* be correct.
this change adds basic error handling, since pwd can in
fact return errors in some cases.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11 20:39:55 +01:00
Leah Rowe 891a7d8e63 lib.sh: initialise PATH if it's unset
it's incorrect for PATH not to be set, but some users
may foolishly blank it out before running cbmk.

prevent such issues, by initialising it.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11 20:38:48 +01:00
Leah Rowe 18689092d3 move XBMKPATH to include/lib.sh
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11 20:37:14 +01:00
Leah Rowe dcc7f10ec7 cbmk: use pwd util, not PWD environmental variable
PWD could be anything, if the user manually exported
it before running cbmk.

always run pwd instead, to get the real string.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11 20:36:54 +01:00
Leah Rowe 6e6b54cc24 clean up a few semicolons in the build system
several code lines were condensed together, which
make them less readable. make the code more readable
by having separate commands on separate lines.

i previously did this during my manic build system
audits of 2023 and 2024; condensing lines like this
is overly pedantic and serves no real purpose.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-04-11 20:36:05 +01:00
Leah Rowe adf1a2e1a4 lib.sh: Much safer python version check
See:
https://docs.python.org/3/library/sys.html#sys.version_info

The sys.version_info tuple is a more reliable way to
get the version. Our previous logic assumed that Python
would always output "Python versionnumber", but this may
not always be how it works. We've seen this for example
where Debian modifies some GNU toolchains to include Debian
something in the output.

Python has a standard method built in for outputting exact
the information we need. In my system, what I got was this:

(3, 11, 2, 'final', 0)

That output was from running this command:

python -c 'import sys; print(sys.version_info[:])'

This is much more robust, so use this instead.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:37:37 +00:00
Leah Rowe 1b1dae36d2 set up python in PATH, ensuring that it is python3
we already check the python version, and set a variable
for it, so that we can reliably use python3, even if
python in PATH doesn't correspond to python3. for
example if a system has python as python2 and python3
as python3

well, we use that when running deguard for example, but
various upstream projects that we use may need python,
and all of them use python3, not 2

so, re-use the python variable set up by lbmk, and
set it up in PATH accordingly. this now makes the note
about python3 obsolete, on docs/build.md in lbwww.git

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:36:27 +00:00
Leah Rowe d731b07aa7 lib.sh: Set python after dependencies
otherwise, the user can't install python, which is
in the dependencies. an irony!

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:32:58 +00:00
Leah Rowe bf5979f0b2 lib.sh: Fix unescaped quotes in chkvars()
This should be the proper fix now

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:32:33 +00:00
Leah Rowe 9baf6a72a7 Revert "fix more unescaped quotes in eval"
This reverts commit ec6bcc1fba5fbdf8b19b3d1cf9711f3d4c9c3741.
2025-01-07 00:32:28 +00:00
Leah Rowe c1dd3da298 fix more unescaped quotes in eval
it should fix more build errors that might have appeared
in the aforementioned revision, mentioned in the previous
commit message

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:32:22 +00:00
Leah Rowe caa18bdcb3 fix ./mk dependencies build issue
the bug was actually caused by chkvars

add an escape for the quotes and bam. fixed.

without this, i got the following e.g.

For command: ./mk dependencies debian

Output:

./mk: 1: [: apt-get: unexpected operator
ERROR ./mk: pkg_add unset

Someone reported a similar issue with the Arch one,
which is also now fixed. This regression was caused
by the previous commit:

commit 0cf58c22734b19293f4cbef83add59b031ca1773
Author: Leah Rowe <leah@libreboot.org>
Date:   Thu Jan 2 23:52:45 2025 +0000

    fix lbmk shellcheck errors

I forgot to escape the double quotes in an eval.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:32:16 +00:00
Leah Rowe 76d87782a8 lib.sh mktarball: cleaner if statement
i also removed that printf, because the path it prints is
actually wrong sometimes; in the recent re-write of vendor.sh,
it prints the correct path instead

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:29:28 +00:00
Leah Rowe 3d1fea0977 fix lbmk shellcheck errors
There was also a condition in run_make_command that is now
an OR, where it was an AND, on script/trees, to fix the use
of mixed (and erroneous) OR/AND operators.

I'm planning a much more invasive audit than this. These are
light fixes, intended for Libreboot 20241206 rev8.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:28:41 +00:00
Leah Rowe 4862f6a348 lib.sh and rom.sh: update my header
i made modifications to them in 2025, so
update them to 2025

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:27:37 +00:00
Leah Rowe 8bdfd31498 rom.sh: handle tarballs in mkcoreboottar
don't make sha512 files for tar archives, because it
is my intention to add the ./mk inject command to
canoeboot in a future commit, but without the vendor
file download/inject functionality, just the mac
address changer.

this commit is based on lbmk commit 41275d699ca

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:25:53 +00:00
Leah Rowe 4a83659885 compile rmodtool alongside cbfstool
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:16:30 +00:00
Leah Rowe 012f530656 lib.sh dependencies: support --reinstall argument
./mk dependencies debian --reinstall

Add --reinstall and it'll do:

apt-get install --reinstall

This can be useful when updating from a stable release
to a testing release. The variable, "reinstall" can be
configured for other distros, but it's currently only
configured for Debian-based distros.

Also, it can be anything. For example, you could add -y;
however, a 4th argument will not be accepted. For example,
you cannot do:

./mk dependencies debian --reinstall -y

If you do this, it'll only see --reinstall; similarly, if
you did this command:

./mk dependencies debian -y --reinstall

then -y would be passed, but not --reinstall. This is an
intentional design decision, in case you accidentally pasted
or subshelled something that outputted something undesirable,
to prevent possible abuse.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:12:11 +00:00
Leah Rowe 33206cae60 move xbmkpath to XBMK_CACHE/
When doing ./mk release, the build system would create
symlinks inside xbmkpath/ relative to the current work tree,
which will differ from what's in PATH.

Since XBMK_CACHE is already set globally, from the main work
tree and the release-build work tree, that means we can know
reliably that PATH is always correct if we put xbmkpath/
inside XBMK_CACHE.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:11:59 +00:00
Leah Rowe 2608bea771 use command -v instead of which
which is a non-standard command, whereas command is part of posix

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:11:31 +00:00
Leah Rowe 444154c002 path.sh: Further cleanup
Remove all symlinks each time, to ensure that no
stragglers are left behind, since they are being
re-generated each time anyway.

The code for determining version numbers has now
been unified under gnu_setver()

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:10:57 +00:00
Leah Rowe 5a5a7c37f5 Fix globbing issue in cbmk
When doing e.g. $@ we should use double quotes to prevent globbing.

Thanks go to XRevan86 for pointing this out.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:10:11 +00:00
Leah Rowe 7ee6ec0ce9 Mitigate Debian Trixie/Sid GCC/GNAT version mismatch
When I tested Debian Trixie, and Debian Sid, I saw that
GCC in PATH pointed to gcc-14, but gnat in path pointed
to GNAT-13, even if you manually install gnat-14.

GNAT 14 was marked experimental, but GCC 14 was marked
for use, in the apt repositories.

So this patch doesn't address the mismatch when doing e.g.
apt-get install gcc gnat

I will address the actual package dependency in a follow-up
patch, on the Debian dependencies config.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-07 00:07:24 +00:00
Leah Rowe 417accd9e0 lib.sh: Support copying files locally
Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-06 23:50:39 +00:00
Leah Rowe 7b8bda9977 lib.sh: Safer exit from ./mk dependencies
The exit was dependent upon install_packages returning
zero status, which it always would in practise, due to
its design, but this exit must always be observed, so
the code has been modified to honour this design.

A direct exit violates lbmk's design in most instances,
where a temporary directory and lock file has already
been created; at this stage, no such act was performed,
so a direct exit is perfectly acceptable.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2025-01-06 23:44:36 +00:00
Leah Rowe ac5c87681f Add U-Boot x86_64 payload
Currently seems to stall when booted from the GRUB
payload, but works when booted from the SeaBIOS menu.

I also tested it as a standalone payload and it seems
to boot. Will test on hardware next, and start adding
it to more mainboards.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-11-28 20:27:10 +00:00
Leah Rowe 966fc8c23f Experimental U-Boot payload (32-bit dtb, U-Boot)
NOTE: Support added for xarch target x86_64-elf,
but U-Boot failed to build with this error:

OBJCOPY lib/efi_loader/helloworld.efi
x86_64-elf-objcopy: lib/efi_loader/helloworld_efi.so: invalid bfd target
make[2]: *** [scripts/Makefile.lib:476: lib/efi_loader/helloworld.efi] Error 1

Since I'm building U-Boot for x86_64 *on* an x86-64
host, and since that is currently the recommended type
of machine to use for cbmk development, and since the
other x86 payloads currently don't cross compile anyway,
this is an acceptable compromise for now. This is because
at present, I'm not making U-Boot the primary payload on x86,
instead preferring to chain it from GRUB and SeaBIOS.

The target.cfg file for x86 u-boot shows xarch/xtree commented.
Uncomment these to compile on crossgcc instead of hostcc.

I mention 64-bit because I initially did this first, but decided
to do 32-bit first. I'll work on the 64-bit one next (SPL).

It's only enabled in QEMU for now.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-11-28 19:53:23 +00:00
Leah Rowe 01331db17f lib.sh: more verbose error in x_
part of the command was cut off in the output

Signed-off-by: Leah Rowe <info@minifree.org>
2024-08-14 22:15:55 +01:00
Leah Rowe 8b74fe2c14 lib.sh: new function mk() to handle trees in bulk
single-tree projects cannot be handled in bulk, e.g.
./mk -f project1 project2 project3

that is still the case, from the shell, but internally
it is now possible:
mk -f project1 project2 project3

mk() is a function that simply handles the given flag,
and all projects specified.

it does not handle cases without argument, for example
you cannot do:
mk -f

arguments must be provided. it can be used internally,
to simplify cases where multiple single-tree projects
must be handled, but *also* allows multi-tree projects
to be specified, without being able to actually handle
trees within that multi-tree project; so for example,
you can only specify coreboot, and then it would run
on every coreboot tree.

Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-07-28 15:40:56 +01:00
Leah Rowe 7942aff43d general code cleanup in the build system
Signed-off-by: Leah Rowe <leah@libreboot.org>
2024-07-26 20:53:06 +01:00