33 Commits

Author SHA1 Message Date
Michael Stapelberg
4f97436034 implement Package.GoBuildEnvironment option
This allows setting e.g. CGO_ENABLED=1 for only specific programs.
2025-03-30 11:14:56 +02:00
thielepaul
b0f9892141 allow overriding basename in package config (#86)
related to https://github.com/gokrazy/gokrazy/issues/303
2025-02-27 20:28:19 +01:00
Olivier Mengué
772c0a9421 packer: move call to unix.Sync behind Linux conditional compile (#84)
In RereadPartitions, move call to unix.Sync() in Linux specific code
as unix.Sync() is not portable (not available on Windows).
2025-02-21 20:39:03 +01:00
Michael Stapelberg
f7db22daab gotool: add missing -tags=gokrazy for list
I noticed this while working on the integration test.
2024-08-18 21:39:22 +02:00
George Hopkins
de5f76c883 Support i386/x86 platforms (#75) 2024-08-18 16:15:51 +02:00
oliverpool
05d1f9d1a0 Fix building when GOBIN is set in the GOENV file (#73)
compute basename manually when target is missing

fixes #71
2024-07-06 08:25:14 +02:00
Anup Chenthamarakshan
fe5fe168ac Support non-default FirstPartitionOffsetSectors (#70)
Support devices that require non-default space before the first partition
starts (4MiB). Required to enable booting Rock64 devices
2024-07-04 17:50:25 +02:00
oliverpool
e53ba4e609 Satisfy staticcheck (#74)
* remove deprecated ioutil usage

* use more suitable functions

* add missing error handling

* remove unused variables

* select{} instead of for{}
2024-07-04 17:35:15 +02:00
Michael Stapelberg
c2c21f612c warn about slow GOPROXY=direct setting 2023-11-05 16:24:03 +01:00
Michael Stapelberg
23cde3b0d8 fix build on non-linux: run go list with the required environment 2023-08-12 10:57:38 +02:00
oliverpool
763d4e4697 fix: prevent race condition in PackageDirs (#52) 2023-03-21 08:53:09 +01:00
Michael Stapelberg
abef3a8e0b skip Raspberry Pi 4 EEPROM updates when the version is unchanged
This shaves about 10s off of the `gok update` time.
2023-02-15 18:29:25 +01:00
Michael Stapelberg
45ce7ad200 implement 'gok get' subcommand
fixes https://github.com/gokrazy/gokrazy/issues/162
2023-01-15 18:27:02 +01:00
Michael Stapelberg
434e942c97 refactor packer code into internal/packer, add gok update entrypoint
related to https://github.com/gokrazy/gokrazy/issues/147
2023-01-07 16:01:35 +01:00
Anmol Khirbat
360a12cb46 Pass fs-size to mkfs.ext4 so it doesn't scribble over secondary GPT (#42) 2022-12-06 10:44:48 +01:00
Michael Stapelberg
b0f51bdf92 update remaining outdated messages regarding supported devices
related to https://github.com/gokrazy/gokrazy/issues/157
2022-11-20 16:21:15 +01:00
Michael Stapelberg
c87c806562 go.mod migration: don’t incorrectly absolutize non-path replace
fixes https://github.com/gokrazy/gokrazy/issues/148
2022-10-08 11:00:41 +02:00
Michael Stapelberg
93542fb1da log a pointer to the documentation when migrating go.mod
related to https://github.com/gokrazy/tools/issues/38
2022-09-29 22:16:43 +02:00
Michael Stapelberg
2e1812da69 make packer.BuildDir function configurable, fix gok run
related to https://github.com/gokrazy/tools/pull/39
2022-09-13 20:44:38 +02:00
Michael Stapelberg
c3979e1ceb Use builddir/ for storing go.mod/go.sum per package
Before

Before this commit, gokr-packer was building all Go binaries to include in the
gokrazy root file system from the same working directory, meaning the same
go.mod and go.sum files were used for all packages.

This wasn’t really an intentional choice, instead it was the easiest way to get
things working when Go switched from GOPATH to modules.

The downside of that approach is that updates in one package can result in other
packages no longer building. In the most extreme cases, it can mean that two
packages cannot be built into the same gokrazy root file system at all.

After

With this commit, gokr-packer will build each package in a subdirectory of the
new builddir/ directory in your gokrazy instance directory,
e.g. ~/gokrazy/scan2drive/builddir.

If there is no go.mod file in the builddir yet, gokr-packer will copy the
top-level go.mod/go.sum files into the builddir to keep your current module
selection, and hopefully build exactly the same binary as before.

Influencing the granularity

Often, one Go package will be the only package you use from a certain Go
module. But this isn’t always the case: for example, the system packages
github.com/gokrazy/gokrazy/cmd/dhcp and github.com/gokrazy/gokrazy/cmd/ntp both
come from the github.com/gokrazy/gokrazy module.

gokr-packer will by default create a separate builddir, including a separate
go.mod and go.sum, for each package, even when they come from the same module.

If you want to add module-wide replace directives to your go.mod file,
you can influence the granularity at which gokr-packer works as follows.

Move the go.mod/go.sum files to the directory level within the builddir/
hierarchy at which you would like to work. gokr-packer will look for
go.mod/go.sum files at the package level, going one level up until it finds the
files.

Hence, you can use the following locations, ordered from finest to coarsest
granularity:

1. per-package builddir (default), e.g.:
   builddir/github.com/gokrazy/gokrazy/cmd/dhcp/go.mod

2. per-module builddir (convenient when working with replace directives), e.g.:
   builddir/github.com/gokrazy/gokrazy/go.mod

3. per-org builddir (convenient for wide-reaching replace directives), e.g.:
   builddir/github.com/gokrazy/go.mod

4. single builddir, preserving the previous behavior, e.g.:
   builddir/go.mod

related to https://github.com/gokrazy/tools/issues/38
2022-09-04 19:56:52 +02:00
Michael Stapelberg
afe3e5085f apply default build tags also to init binary build
related to https://github.com/stapelberg/scan2drive/issues/18
2022-04-21 21:17:42 +02:00
Michael Stapelberg
4fe1051453 revert GOFLAGS, add buildtags per-package config, add osusergo/netgo
The GOFLAGS handling is the opposite of how the Go tool handles it, where
GOFLAGS provides default values that the command line then overwrites. I think
it’s better to match that behavior.

Instead, allow extending gokr-packer’s list of build tags via the buildtags/
per-package config directive.

Also, add osusergo and netgo build tags by default so that even when cgo is
enabled, gokrazy code results in statically linked binaries.

related to https://github.com/stapelberg/scan2drive/issues/18
2022-04-21 21:17:36 +02:00
Michael Stapelberg
32c5136e01 respect GOFLAGS=-tags (don’t set -tags=gokrazy)
related to https://github.com/stapelberg/scan2drive/issues/18
2022-04-20 21:13:08 +02:00
Michael Stapelberg
125418d8b3 respect CGO_ENABLED=1 if explicitly specified in environment
Our default is still CGO_ENABLED=0

related to https://github.com/stapelberg/scan2drive/issues/18
2022-04-20 21:12:58 +02:00
Michael Stapelberg
8dc754717c look for architecture-dependent extrafiles tar first
related to https://github.com/gokrazy/podman/issues/2
2022-04-14 13:06:12 +02:00
oliverpool
07643813fd packer: fail on small device (#33) 2022-03-31 09:10:30 +02:00
Michael Stapelberg
0721be4715 move (*os.File).Sync() call into linux-specific packer_linux.go
This fixes the following error on macOS:

sync /dev/disk2: inappropriate ioctl for device

related to https://github.com/gokrazy/gokrazy/issues/22
2022-03-01 18:04:43 +01:00
Michael Stapelberg
c64054cdc5 set -mod=mod for now-first go tool invocation 2022-02-24 22:25:00 +01:00
Michael Stapelberg
0fde06653c packer: pick up _gokrazy/extrafiles/ within package dirs, too
This allows e.g. the github.com/gokrazy/wifi package to include firmware files
that end up in the root file system.

related to https://github.com/gokrazy/gokrazy/issues/13
2022-02-24 20:45:22 +01:00
Anup Chenthamarakshan
8bb7e491ea packer: allow using MBR partition tables (#28)
Some ARM devices (like Odroid XU4/HC1/HC2) only support MBR booting.
Allow generating MBR partition table for such devices.
2022-01-13 09:20:34 +01:00
Michael Stapelberg
a99f2c5561 move gotool.go into packer package for upcoming re-use 2021-11-21 09:50:50 +01:00
Michael Stapelberg
2e02ea7acd fix: move guid_test to the packer package 2021-11-20 11:12:32 +01:00
Michael Stapelberg
bea67498b5 Switch to GPT partition tables, add systemd-boot for UEFI boot
This is useful for running gokrazy on PC platforms (e.g. for
https://router7.org/), where the first systems without legacy BIOS support are
starting to ship.

The existing boot methods (Legacy BIOS MBR boot, Raspberry Pi) are unaffected by
this change and keep working.

Regardless of the bootloader (BIOS, UEFI, Raspberry Pi), we now use a GPT
partition table with hybrid MBR (= protective MBR + FAT32 /boot partition
which the Raspberry Pi bootloader requires).

This change should have no effect on existing installations.

To switch to GPT, you’ll need to use the -overwrite= flag to partition the
device (e.g. SD card). If you want to keep your /perm partition, you’ll need to
shrink the file system (using resize2fs) by 1 MB to make space for the secondary
GPT partition table copy at the end of the device.

Previously, the partition *table* contained a UUID that we used as root=
parameter for the Linux kernel, e.g. root=PARTUUID=471cad93-03

Now, individual partitions (not the partition *table*) have a UUID that begins
with 60c24cc1-f3f9-427a-8199,
e.g. root=PARTUUID=60c24cc1-f3f9-427a-8199-2e18c40c0004

fixes https://github.com/gokrazy/gokrazy/issues/87
2021-06-24 13:52:55 +02:00