-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chris Koch <[email protected]>
- Loading branch information
Showing
10 changed files
with
119 additions
and
147 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mkuimage | ||
uimage | ||
cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2015-2024 the u-root Authors. All rights reserved | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Command uimage builds CPIO archives with the given files and Go commands. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/u-root/gobusybox/src/pkg/golang" | ||
"github.com/u-root/mkuimage/uimage" | ||
"github.com/u-root/mkuimage/uimage/mkuimage" | ||
"github.com/u-root/uio/cli" | ||
"github.com/u-root/uio/llog" | ||
) | ||
|
||
func main() { | ||
log.SetFlags(log.Ltime) | ||
l := llog.Default() | ||
|
||
env := golang.Default(golang.DisableCGO()) | ||
f := &mkuimage.Flags{ | ||
Commands: mkuimage.CommandFlags{Builder: "bb"}, | ||
ArchiveFormat: "cpio", | ||
OutputFile: defaultFile(env), | ||
} | ||
tf := &mkuimage.TemplateFlags{} | ||
|
||
makeCmd := cli.Command{ | ||
Name: "make", | ||
Short: "create uimage from specified flags", | ||
Run: func(args []string) { | ||
// Set defaults. | ||
m := []uimage.Modifier{ | ||
uimage.WithReplaceEnv(env), | ||
uimage.WithBaseArchive(uimage.DefaultRamfs()), | ||
uimage.WithCPIOOutput(defaultFile(env)), | ||
} | ||
if err := mkuimage.CreateUimage(l, m, tf, f, args); err != nil { | ||
l.Errorf("mkuimage error: %v", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
l.RegisterVerboseFlag(makeCmd.Flags(), "v", slog.LevelDebug) | ||
f.RegisterFlags(makeCmd.Flags()) | ||
tf.RegisterFlags(makeCmd.Flags()) | ||
|
||
app := cli.App{makeCmd} | ||
app.Run(os.Args) | ||
} | ||
|
||
func defaultFile(env *golang.Environ) string { | ||
if len(env.GOOS) == 0 || len(env.GOARCH) == 0 { | ||
return "/tmp/initramfs.cpio" | ||
} | ||
return fmt.Sprintf("/tmp/initramfs.%s_%s.cpio", env.GOOS, env.GOARCH) | ||
} |
Oops, something went wrong.