Skip to content

Commit c91e309

Browse files
committed
Add: Bootmodes
1 parent 1efeaf2 commit c91e309

10 files changed

Lines changed: 179 additions & 80 deletions

File tree

alteriso5/cmd/build/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func build() error {
2626
profile := config.Profile{
2727
Base: path.Join(current, "profile"),
2828
InstallDir: "alter",
29+
BootModes: []string{"SysLinux"},
2930
}
3031

3132
// TODO: Add more targets

alteriso5/cmd/build/config/profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
type Profile struct {
44
Base string
55
InstallDir string
6+
BootModes []string
67
}
78

89
func ReadProfile(path string) (Profile, error) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package boot
2+
3+
func GetModesByName(targets ...string) []*Mode {
4+
modes := []*Mode{}
5+
for _, t := range targets {
6+
m := getModeByName(t)
7+
if m != nil {
8+
modes = append(modes, m)
9+
}
10+
}
11+
return modes
12+
}
13+
14+
func Setup(modes *[]*Mode) error {
15+
for _, m := range *modes {
16+
m.setupXorriso()
17+
if err := m.install(); err != nil {
18+
return err
19+
}
20+
}
21+
return nil
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package boot
2+
3+
type Mode struct {
4+
name string
5+
install func() error
6+
setupXorriso func()
7+
}
8+
9+
func (m *Mode) SetInstall(f func() error) {
10+
m.install = f
11+
}
12+
13+
var AllModes []*Mode = []*Mode{
14+
SysLinux,
15+
}
16+
17+
func getModeByName(name string) *Mode {
18+
for _, m := range AllModes {
19+
if m.name == name {
20+
return m
21+
}
22+
}
23+
return nil
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package boot
2+
3+
var SysLinux *Mode = &Mode{
4+
name: "SysLinux",
5+
setupXorriso: func() {
6+
Xorriso.setArgsForSysLinuxElTorito()
7+
Xorriso.setArgsForSysLinuxMBRBios()
8+
},
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package boot
2+
3+
import (
4+
"path"
5+
)
6+
7+
// SysLinux MBR El Torito
8+
func (o *xorriso) setArgsForSysLinuxElTorito() {
9+
arg := xorrisoArg{
10+
name: "SysLinuxEltorito",
11+
}
12+
13+
arg.add("-eltorito-boot", "boot/syslinux/isolinux.bin")
14+
arg.add("-eltorito-catalog", "boot/syslinux/boot.cat")
15+
arg.add("-no-emul-boot", "-boot-load-size", "4", "-boot-info-table")
16+
17+
o.addArg(&arg)
18+
}
19+
20+
func (o *xorriso) setArgsForSysLinuxMBRBios() {
21+
22+
arg := xorrisoArg{
23+
name: "SysLinuxMBRBios",
24+
}
25+
26+
arg.add("-isohybrid-mbr", path.Join(o.fsDir, "boot", "syslinux", "isohqpfx.bin"))
27+
arg.add("--mbr-force-bootable")
28+
arg.add("-partition_offset", "16")
29+
30+
o.addArg(&arg)
31+
32+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package boot
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
)
7+
8+
var Xorriso = xorriso{}
9+
10+
type xorriso struct {
11+
fsDir string
12+
out string
13+
args []*xorrisoArg
14+
}
15+
16+
type xorrisoArg struct {
17+
name string
18+
args *[]string
19+
}
20+
21+
func (xa *xorrisoArg) add(args ...string) {
22+
arg := append(*(xa.args), args...)
23+
xa.args = &arg
24+
}
25+
26+
func (x *xorriso) hasArg(a *xorrisoArg) bool {
27+
for _, x := range x.args {
28+
if x.name == a.name {
29+
return true
30+
}
31+
}
32+
return false
33+
}
34+
35+
func (o *xorriso) addArg(arg *xorrisoArg) {
36+
if !o.hasArg(arg) {
37+
o.args = append(o.args, arg)
38+
}
39+
}
40+
41+
func (o *xorriso) defaultArgs() *xorrisoArg {
42+
d := []string{
43+
"-as", "mkisofs",
44+
"-iso-level", "3",
45+
"-full-iso9660-filenames",
46+
"-joliet",
47+
"-joliet-long",
48+
"-rational-rock",
49+
"--output", o.out,
50+
o.fsDir,
51+
}
52+
return &xorrisoArg{
53+
name: "default",
54+
args: &d,
55+
}
56+
}
57+
58+
func (x *xorriso) Args() *[]string {
59+
args := []string{}
60+
for _, a := range x.args {
61+
args = append(args, *a.args...)
62+
}
63+
64+
def := x.defaultArgs()
65+
args = append(args, *def.args...)
66+
return &args
67+
}
68+
69+
func (x *xorriso) Build(dir string, out string) error {
70+
x.fsDir = dir
71+
x.out = out
72+
73+
args := x.Args()
74+
75+
cmd := exec.Command("xorriso", *args...)
76+
cmd.Stdout = os.Stdout
77+
cmd.Stdin = os.Stdin
78+
cmd.Stderr = os.Stderr
79+
80+
return cmd.Run()
81+
}

alteriso5/cmd/build/work/tasks.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"path"
66

77
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/airootfs"
8+
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/boot"
89
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/chroot"
9-
"github.com/FascodeNet/alterlinux/alteriso5/cmd/build/work/xorriso"
1010
"github.com/FascodeNet/alterlinux/alteriso5/utils"
1111
cp "github.com/otiai10/copy"
1212
)
@@ -69,14 +69,12 @@ var makeAirootfs *BuildTask = NewBuildTask("makeAirootfs", func(w *Work) error {
6969
})
7070

7171
var makeBoot *BuildTask = NewBuildTask("makeBoot", func(w *Work) error {
72-
// TODO: ISO以外もサポートする
7372

74-
opt := xorriso.Options{
75-
SysLinux: true,
76-
}
77-
78-
isodir := path.Join(w.Base, "iso")
73+
boot.SysLinux.SetInstall(func() error {
74+
return nil
75+
})
7976

80-
return xorriso.Build(isodir, w.target.Out, &opt)
77+
modes := boot.GetModesByName(w.profile.BootModes...)
78+
return boot.Setup(&modes)
8179

8280
})

alteriso5/cmd/build/work/xorriso/struct.go

Lines changed: 0 additions & 72 deletions
This file was deleted.

profile/profiledef.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"bootmodes": ["SysLinux"]
3+
}

0 commit comments

Comments
 (0)