Skip to content

Commit

Permalink
Rename mkuimage -> uimage make
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Feb 24, 2024
1 parent 2765692 commit 03eff59
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 147 deletions.
99 changes: 0 additions & 99 deletions cmd/mkuimage/main.go

This file was deleted.

1 change: 1 addition & 0 deletions cmd/mkuimage/.gitignore → cmd/uimage/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mkuimage
uimage
cover
62 changes: 62 additions & 0 deletions cmd/uimage/main.go
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)
}
Loading

0 comments on commit 03eff59

Please sign in to comment.