|
1 | 1 | package work |
2 | 2 |
|
3 | | -import "log/slog" |
| 3 | +import ( |
| 4 | + "log/slog" |
| 5 | + "os" |
| 6 | + "path" |
| 7 | + |
| 8 | + "github.com/FascodeNet/alterlinux/alteriso5/utils" |
| 9 | + "github.com/FascodeNet/alterlinux/alteriso5/work/boot" |
| 10 | + "github.com/Hayao0819/nahi/osutils" |
| 11 | +) |
4 | 12 |
|
5 | 13 | // Prepare configuration files for systemd-boot |
6 | 14 | var makeCommonSystemdBootConfig *BuildTask = NewBuildTask("makeCommonSystemdBootConfig", func(w Work) error { |
| 15 | + var total int64 = 0 |
| 16 | + // TODO: Get ucode list |
| 17 | + |
| 18 | + // Calculate ESP size |
| 19 | + |
| 20 | + { |
| 21 | + efiboot_files := []string{} |
| 22 | + |
| 23 | + // For UEFI x64 |
| 24 | + if w.profile.HasBootMode(boot.UefiX64SystemdBootEsp) || w.profile.HasBootMode(boot.UefiX64SystemdBootElTorito) { |
| 25 | + efiboot_files = append(efiboot_files, |
| 26 | + path.Join(w.Dirs.Pacstrap, "usr", "lib", "systemd", "boot", "efi", "systemd-bootx64.efi"), |
| 27 | + path.Join(w.Dirs.Pacstrap, "usr", "share", "edk2-shell", "x64", "Shell_Full.efi"), |
| 28 | + path.Join(w.Dirs.Pacstrap, "boot", "memtest86+", "memtest.efi"), |
| 29 | + path.Join(w.Dirs.Pacstrap, "usr", "share", "licenses", "spdx", "GPL-2.0-only.txt"), |
| 30 | + ) |
| 31 | + } |
| 32 | + |
| 33 | + // For UEFI ia32 |
| 34 | + if w.profile.HasBootMode(boot.UefiIa32SystemdBootEsp) || w.profile.HasBootMode(boot.UefiIa32SystemdBootElTorito) { |
| 35 | + efiboot_files = append(efiboot_files, |
| 36 | + path.Join(w.Dirs.Pacstrap, "usr", "lib", "systemd", "boot", "efi", "systemd-bootia32.efi"), |
| 37 | + path.Join(w.Dirs.Pacstrap, "usr", "share", "edk2-shell", "ia32", "Shell_Full.efi"), |
| 38 | + ) |
| 39 | + } |
| 40 | + |
| 41 | + // For kernel |
| 42 | + { |
| 43 | + chroot, err := w.GetChroot() |
| 44 | + if err != nil { |
| 45 | + return err |
| 46 | + } |
| 47 | + kernels, err := chroot.FindKernels() |
| 48 | + if err != nil { |
| 49 | + return err |
| 50 | + } |
| 51 | + for _, k := range kernels { |
| 52 | + for _, f := range k.Files() { |
| 53 | + if osutils.Exists(f) { |
| 54 | + efiboot_files = append(efiboot_files, f) |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + for _, f := range efiboot_files { |
| 61 | + if s, err := utils.GetFileSize(f); err == nil { |
| 62 | + total += s |
| 63 | + } else { |
| 64 | + slog.Warn("Failed to get file size", "file", f, "error", err) |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + slog.Debug("Found files for efiboot", "files", efiboot_files) |
| 69 | + } |
| 70 | + |
| 71 | + // For efiboot files |
| 72 | + if err := os.MkdirAll(path.Join(w.Base, w.target.Arch, "efiboot"), 0755); err != nil { |
| 73 | + return err |
| 74 | + } |
| 75 | + sizes, err := utils.GetFileSizesInDir(path.Join(w.Base, w.target.Arch, "efiboot")) |
| 76 | + if err != nil { |
| 77 | + return err |
| 78 | + } |
| 79 | + for _, s := range sizes { |
| 80 | + total += s |
| 81 | + } |
| 82 | + |
| 83 | + slog.Debug("efiboot img size", "size", total) |
7 | 84 | return nil |
8 | 85 | }) |
9 | 86 |
|
|
0 commit comments