-
Notifications
You must be signed in to change notification settings - Fork 19
/
imxkobs.go
112 lines (87 loc) · 2.46 KB
/
imxkobs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* UpdateHub
* Copyright (C) 2017
* O.S. Systems Sofware LTDA: contato@ossystems.com.br
*
* SPDX-License-Identifier: Apache-2.0
*/
package imxkobs
import (
"os/exec"
"path"
"strconv"
"github.com/OSSystems/pkg/log"
"github.com/UpdateHub/updatehub/installifdifferent"
"github.com/UpdateHub/updatehub/installmodes"
"github.com/UpdateHub/updatehub/metadata"
"github.com/UpdateHub/updatehub/utils"
"github.com/spf13/afero"
)
func init() {
installmodes.RegisterInstallMode(installmodes.InstallMode{
Name: "imxkobs",
CheckRequirements: checkRequirements,
GetObject: getObject,
})
}
func checkRequirements() error {
_, err := exec.LookPath("kobs-ng")
return err
}
func getObject() interface{} {
return &ImxKobsObject{
CmdLineExecuter: &utils.CmdLine{},
}
}
// ImxKobsObject encapsulates the "imxkobs" handler data and functions
type ImxKobsObject struct {
metadata.ObjectMetadata
utils.CmdLineExecuter
installifdifferent.TargetProvider
Add1KPadding bool `json:"1k_padding,omitempty"`
SearchExponent int `json:"search_exponent,omitempty"`
Chip0DevicePath string `json:"chip_0_device_path,omitempty"`
Chip1DevicePath string `json:"chip_1_device_path,omitempty"`
}
// Setup implementation for the "imxkobs" handler
func (ik *ImxKobsObject) Setup() error {
log.Debug("'imxkobs' handler Setup")
return nil
}
// Install implementation for the "imxkobs" handler
func (ik *ImxKobsObject) Install(downloadDir string) error {
log.Debug("'imxkobs' handler Install")
cmdline := "kobs-ng init"
if ik.Add1KPadding {
cmdline += " -x"
}
cmdline += " " + path.Join(downloadDir, ik.Sha256sum)
if ik.SearchExponent > 0 {
cmdline += " --search_exponent=" + strconv.Itoa(ik.SearchExponent)
}
if ik.Chip0DevicePath != "" {
cmdline += " --chip_0_device_path=" + ik.Chip0DevicePath
}
if ik.Chip1DevicePath != "" {
cmdline += " --chip_1_device_path=" + ik.Chip1DevicePath
}
cmdline += " -v"
_, err := ik.Execute(cmdline)
return err
}
// Cleanup implementation for the "imxkobs" handler
func (ik *ImxKobsObject) Cleanup() error {
log.Debug("'imxkobs' handler Cleanup")
return nil
}
// GetTarget implementation for the "imxkobs" handler
func (ik *ImxKobsObject) GetTarget() string {
mtdDevicePath := "/dev/mtd0"
if ik.Chip0DevicePath != "" {
mtdDevicePath = ik.Chip0DevicePath
}
return mtdDevicePath + "ro"
}
// SetupTarget implementation for the "imxkobs" handler
func (ik *ImxKobsObject) SetupTarget(target afero.File) {
}