in newtmgr/cli/image.go [366:485]
func imageCmd() *cobra.Command {
imageCmd := &cobra.Command{
Use: "image",
Short: "Manage images on a device",
Run: func(cmd *cobra.Command, args []string) {
cmd.HelpFunc()(cmd, args)
},
}
listCmd := &cobra.Command{
Use: "list -c <conn_profile>",
Short: "Show images on a device",
Run: imageStateListCmd,
}
imageCmd.AddCommand(listCmd)
testCmd := &cobra.Command{
Use: "test <hex-image-hash>",
Short: "Test an image on next reboot",
Run: imageStateTestCmd,
}
imageCmd.AddCommand(testCmd)
confirmCmd := &cobra.Command{
Use: "confirm [hex-image-hash] -c <conn_profile>",
Short: "Permanently run image",
Long: "If a hash is specified, permanently switch to the " +
"corresponding image. If no hash is specified, the current " +
"image setup is made permanent.",
Run: imageStateConfirmCmd,
}
imageCmd.AddCommand(confirmCmd)
uploadEx := " " + nmutil.ToolInfo.ExeName +
" -c olimex image upload bin/slinky_zero/apps/slinky.img\n"
uploadCmd := &cobra.Command{
Use: "upload <image-file> -c <conn_profile>",
Short: "Upload image to a device",
Example: uploadEx,
Run: imageUploadCmd,
}
uploadCmd.PersistentFlags().BoolVarP(&noerase,
"noerase", "e", true,
"Don't send specific image erase command to start with")
uploadCmd.PersistentFlags().BoolVarP(&upgrade,
"upgrade", "u", false,
"Only allow the upload if the new image's version is greater than "+
"that of the currently running image")
uploadCmd.PersistentFlags().IntVarP(&imageNum,
"image", "n", 0,
"In a multi-image system, which image should be uploaded")
uploadCmd.PersistentFlags().IntVarP(&maxWinSz,
"maxwinsize", "w", xact.IMAGE_UPLOAD_DEF_MAX_WS,
"Set the maximum size for the window of outstanding chunks in transit. "+
"caution:higher num may not translate to better perf and may result in errors")
imageCmd.AddCommand(uploadCmd)
coreListCmd := &cobra.Command{
Use: "corelist -c <conn_profile>",
Short: "List core(s) on a device",
Example: " " + nmutil.ToolInfo.ExeName + " -c olimex image corelist\n",
Run: coreListCmd,
}
imageCmd.AddCommand(coreListCmd)
coreEx := " " + nmutil.ToolInfo.ExeName +
" -c olimex image coredownload -e core\n"
coreEx += " " + nmutil.ToolInfo.ExeName +
" -c olimex image coredownload --offset 10 -n 10 core\n"
coreDownloadCmd := &cobra.Command{
Use: "coredownload <core-file> -c <conn_profile>",
Short: "Download core from a device",
Example: coreEx,
Run: coreDownloadCmd,
}
coreDownloadCmd.Flags().BoolVarP(&coreElfify, "elfify", "e", false,
"Create an elf file")
coreDownloadCmd.Flags().Uint32Var(&coreOffset, "offset", 0, "Start offset")
coreDownloadCmd.Flags().Uint32VarP(&coreNumBytes, "bytes", "n", 0,
"Number of bytes of the core to download")
imageCmd.AddCommand(coreDownloadCmd)
coreEraseEx := " " + nmutil.ToolInfo.ExeName +
" -c olimex image coreerase\n"
coreEraseCmd := &cobra.Command{
Use: "coreerase -c <conn_profile>",
Short: "Erase core on a device",
Example: coreEraseEx,
Run: coreEraseCmd,
}
imageCmd.AddCommand(coreEraseCmd)
imageEraseHelpText := "Erase an unused image from the secondary image slot on a device.\n"
imageEraseHelpText += "The image cannot be erased if the image is a confirmed image, is marked\n"
imageEraseHelpText += "for test on the next reboot, or is an active image for a split image setup.\n"
imageEraseEx := " " + nmutil.ToolInfo.ExeName +
" -c olimex image erase\n"
imageEraseCmd := &cobra.Command{
Use: "erase -c <conn_profile>",
Short: "Erase unused image on a device",
Long: imageEraseHelpText,
Example: imageEraseEx,
Run: imageEraseCmd,
}
imageCmd.AddCommand(imageEraseCmd)
coreConvertCmd := &cobra.Command{
Use: "coreconvert <core-filename> <elf-filename>",
Short: "Convert core to ELF",
Run: coreConvertCmd,
}
imageCmd.AddCommand(coreConvertCmd)
return imageCmd
}