Skip to content

Commit 43c911c

Browse files
Add logic to preserve user partition
1 parent d6bef23 commit 43c911c

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

flash.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
func newFlashCmd() *cobra.Command {
33-
var forceYes bool
33+
var forceYes, preserveUser bool
3434
appCmd := &cobra.Command{
3535
Use: "flash",
3636
Short: "Flash a Debian image on the board",
@@ -66,11 +66,11 @@ NOTE: On Windows, required drivers are automatically installed with elevated pri
6666
Args: cobra.ExactArgs(1),
6767
Run: func(cmd *cobra.Command, args []string) {
6868
checkDriversInstalled()
69-
runFlashCommand(cmd.Context(), args, forceYes)
69+
runFlashCommand(cmd.Context(), args, forceYes, preserveUser)
7070
},
7171
}
7272
appCmd.Flags().BoolVarP(&forceYes, "yes", "y", false, "Automatically confirm all prompts")
73-
// TODO: add --clean-install flag or something similar to distinguish between keeping and purging the /home directory
73+
appCmd.Flags().BoolVar(&preserveUser, "preserve-user", false, "Preserve user partition")
7474

7575
return appCmd
7676
}
@@ -86,13 +86,13 @@ func checkDriversInstalled() {
8686
}
8787
}
8888

89-
func runFlashCommand(ctx context.Context, args []string, forceYes bool) {
89+
func runFlashCommand(ctx context.Context, args []string, forceYes bool, preserveUser bool) {
9090
imagePath, err := paths.New(args[0]).Abs()
9191
if err != nil {
9292
feedback.Fatal(i18n.Tr("could not find image absolute path: %v", err), feedback.ErrBadArgument)
9393
}
9494

95-
err = updater.Flash(ctx, imagePath, args[0], forceYes)
95+
err = updater.Flash(ctx, imagePath, args[0], forceYes, preserveUser)
9696
if err != nil {
9797
feedback.Fatal(i18n.Tr("error flashing the board: %v", err), feedback.ErrBadArgument)
9898
}

updater/flasher.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/arduino/arduino-flasher-cli/updater/artifacts"
2929
)
3030

31-
func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes bool) error {
31+
func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes bool, preserveUser bool) error {
3232
if !imagePath.Exist() {
3333
client := NewClient()
3434

@@ -89,10 +89,10 @@ func Flash(ctx context.Context, imagePath *paths.Path, version string, forceYes
8989
}
9090
yes := strings.ToLower(yesInput) == "yes" || strings.ToLower(yesInput) == "y"
9191
return yes, nil
92-
}, forceYes)
92+
}, forceYes, preserveUser)
9393
}
9494

95-
func FlashBoard(ctx context.Context, downloadedImagePath string, version string, upgradeConfirmCb DownloadConfirmCB, forceYes bool) error {
95+
func FlashBoard(ctx context.Context, downloadedImagePath string, version string, upgradeConfirmCb DownloadConfirmCB, forceYes bool, preserveUser bool) error {
9696
if !forceYes {
9797
res, err := upgradeConfirmCb(version)
9898
if err != nil {
@@ -139,9 +139,14 @@ func FlashBoard(ctx context.Context, downloadedImagePath string, version string,
139139
if err != nil {
140140
return err
141141
}
142-
// TODO: add logic to preserve the user partition
142+
143+
rawProgram := "rawprogram0.xml"
144+
if preserveUser {
145+
rawProgram = "rawprogram0.nouser.xml"
146+
}
147+
143148
feedback.Print(i18n.Tr("Flashing with qdl"))
144-
cmd, err := paths.NewProcess(nil, qdlPath.String(), "--allow-missing", "--storage", "emmc", "prog_firehose_ddr.elf", "rawprogram0.xml", "patch0.xml")
149+
cmd, err := paths.NewProcess(nil, qdlPath.String(), "--allow-missing", "--storage", "emmc", "prog_firehose_ddr.elf", rawProgram, "patch0.xml")
145150
if err != nil {
146151
return err
147152
}

0 commit comments

Comments
 (0)