Merge lp:~mvo/snappy/snappy-snappy-bootsuccess-env2 into lp:~snappy-dev/snappy/snappy-moved-to-github

Proposed by Michael Vogt on 2015-07-20
Status: Merged
Approved by: John Lenton on 2015-07-22
Approved revision: 596
Merged at revision: 595
Proposed branch: lp:~mvo/snappy/snappy-snappy-bootsuccess-env2
Merge into: lp:~snappy-dev/snappy/snappy-moved-to-github
Prerequisite: lp:~mvo/snappy/snappy-bootsuccess-env
Diff against target: 204 lines (+63/-51)
4 files modified
debian/control (+1/-0)
dependencies.tsv (+1/-0)
partition/bootloader_uboot.go (+29/-23)
partition/bootloader_uboot_test.go (+32/-28)
To merge this branch: bzr merge lp:~mvo/snappy/snappy-snappy-bootsuccess-env2
Reviewer Review Type Date Requested Status
John Lenton 2015-07-20 Approve on 2015-07-22
Review via email: mp+265259@code.launchpad.net

Commit Message

Use native uboot-go code to manipulate the snappy uboot.env file.

Description of the Change

This branch uses the native go uboot code to read/write the uboot environment.

To post a comment you must log in.
594. By Michael Vogt on 2015-07-21

add github.com/mvo5/uboot-go

John Lenton (chipaca) wrote :

We need golang-uboot-dev or sth in debian/ (or vendoring). Other than that it looks very good.

review: Needs Fixing
595. By Michael Vogt on 2015-07-21

add golang-uboot-go-dev dependency

Michael Vogt (mvo) wrote :

Thanks! I added the missing build-dependency and upload the golang-uboot-go-dev package to the image PPA.

596. By Michael Vogt on 2015-07-22

dependencies.tsv: update uboot-go git dependency

John Lenton (chipaca) wrote :

I approve.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2015-07-01 07:30:21 +0000
3+++ debian/control 2015-07-22 08:17:05 +0000
4@@ -16,6 +16,7 @@
5 golang-go.crypto-dev,
6 golang-goconfigparser-dev,
7 golang-pb-dev,
8+ golang-uboot-go-dev,
9 golang-yaml.v2-dev,
10 python3,
11 python3-markdown
12
13=== modified file 'dependencies.tsv'
14--- dependencies.tsv 2015-06-29 23:15:00 +0000
15+++ dependencies.tsv 2015-07-22 08:17:05 +0000
16@@ -3,6 +3,7 @@
17 github.com/gosexy/gettext git 98b7b91596d20b96909e6b60d57411547dd9959c 2013-02-21T11:21:43Z
18 github.com/jessevdk/go-flags git 15347ef417a300349807983f15af9e65cd2e1b3a 2015-01-25T08:53:51Z
19 github.com/mvo5/goconfigparser git 26426272dda20cc76aa1fa44286dc743d2972fe8 2015-02-12T09:37:50Z
20+github.com/mvo5/uboot-go git 361f6ebcbb54f389d15dc9faefa000e996ba3e37 2015-07-22T06:53:46Z
21 golang.org/x/crypto git 60052bd85f2d91293457e8811b0cf26b773de469 2015-06-22T23:34:07Z
22 gopkg.in/check.v1 git 64131543e7896d5bcc6bd5a76287eb75ea96c673 2014-10-24T13:38:53Z
23 gopkg.in/yaml.v2 git 49c95bdc21843256fb6c4e0d370a05f24a0bf213 2015-02-24T22:57:58Z
24
25=== modified file 'partition/bootloader_uboot.go'
26--- partition/bootloader_uboot.go 2015-07-22 08:17:05 +0000
27+++ partition/bootloader_uboot.go 2015-07-22 08:17:05 +0000
28@@ -29,6 +29,7 @@
29 "launchpad.net/snappy/helpers"
30
31 "github.com/mvo5/goconfigparser"
32+ "github.com/mvo5/uboot-go/uenv"
33 )
34
35 const (
36@@ -206,42 +207,47 @@
37 return os.RemoveAll(bootloaderUbootStampFile)
38 }
39
40-// fw_setenv gets the location of the configuration to use from the
41-// file /etc/fw_env.config
42 func (u *uboot) unsetBootVar(name string) error {
43- if u.hasBootVar(name) {
44- return runCommand("fw_setenv", name)
45- }
46-
47- return nil
48+ hasBootVar, err := u.hasBootVar(name)
49+ if err != nil {
50+ return err
51+ }
52+
53+ // already unset, nothing to do
54+ if !hasBootVar {
55+ return nil
56+ }
57+
58+ return u.setBootVar(name, "")
59 }
60
61 func (u *uboot) setBootVar(name, value string) error {
62- // we ignore the error here, the interface of fw_printenv
63- // is very simplistic, the github.com/mvo5/uboot-go code
64- // will fix that
65- curVal, _ := u.getBootVar(name)
66- if curVal != value {
67- return runCommand("fw_setenv", name, value)
68- }
69-
70- return nil
71+ env, err := uenv.Open(bootloaderUbootFwEnvFile)
72+ if err != nil {
73+ return err
74+ }
75+
76+ // already set, nothing to do
77+ if env.Get(name) == value {
78+ return nil
79+ }
80+
81+ env.Set(name, value)
82+ return env.Save()
83 }
84
85-func (u *uboot) hasBootVar(name string) bool {
86- // FIXME: too simplistic, this will be replaces with
87- // github.com/mvo5/uboot-go/
88- err := runCommand("fw_printenv", name)
89- return err == nil
90+func (u *uboot) hasBootVar(name string) (bool, error) {
91+ v, err := u.getBootVar(name)
92+ return v != "", err
93 }
94
95 func (u *uboot) getBootVar(name string) (string, error) {
96- output, err := runCommandWithStdout("fw_printenv", "-n", name)
97+ env, err := uenv.Open(bootloaderUbootFwEnvFile)
98 if err != nil {
99 return "", err
100 }
101
102- return output, nil
103+ return env.Get(name), nil
104 }
105
106 // FIXME: this is super similar to grub now, refactor to extract the
107
108=== modified file 'partition/bootloader_uboot_test.go'
109--- partition/bootloader_uboot_test.go 2015-07-22 08:17:05 +0000
110+++ partition/bootloader_uboot_test.go 2015-07-22 08:17:05 +0000
111@@ -24,9 +24,12 @@
112 "os"
113 "path/filepath"
114 "strings"
115+ "time"
116
117 . "gopkg.in/check.v1"
118 "launchpad.net/snappy/helpers"
119+
120+ "github.com/mvo5/uboot-go/uenv"
121 )
122
123 // TODO move to uboot specific test suite.
124@@ -322,51 +325,52 @@
125 func (s *PartitionTestSuite) TestUbootMarkCurrentBootSuccessfulFwEnv(c *C) {
126 s.makeFakeUbootEnv(c)
127
128- err := ioutil.WriteFile(bootloaderUbootFwEnvFile, []byte(""), 0644)
129+ env, err := uenv.Create(bootloaderUbootFwEnvFile, 4096)
130+ c.Assert(err, IsNil)
131+ env.Set("snappy_ab", "b")
132+ env.Set("snappy_mode", "try")
133+ env.Set("snappy_trial_boot", "1")
134+ err = env.Save()
135 c.Assert(err, IsNil)
136
137 partition := New()
138 u := newUboot(partition)
139 c.Assert(u, NotNil)
140
141- allCommands = nil
142- runCommand = mockRunCommandWithCapture
143 err = u.MarkCurrentBootSuccessful("b")
144 c.Assert(err, IsNil)
145- c.Assert(allCommands, HasLen, 4)
146- c.Assert(allCommands[0], DeepEquals, singleCommand{"fw_printenv", bootloaderTrialBootVar})
147- c.Assert(allCommands[1], DeepEquals, singleCommand{"fw_setenv", bootloaderTrialBootVar})
148- c.Assert(allCommands[2], DeepEquals, singleCommand{"fw_setenv", bootloaderRootfsVar, "b"})
149- c.Assert(allCommands[3], DeepEquals, singleCommand{"fw_setenv", bootloaderBootmodeVar, bootloaderBootmodeSuccess})
150+
151+ env, err = uenv.Open(bootloaderUbootFwEnvFile)
152+ c.Assert(err, IsNil)
153+ c.Assert(env.String(), Equals, "snappy_ab=b\nsnappy_mode=regular\n")
154 }
155
156-func (s *PartitionTestSuite) TestUbootSetEnv(c *C) {
157+func (s *PartitionTestSuite) TestUbootSetEnvNoUselessWrites(c *C) {
158 s.makeFakeUbootEnv(c)
159
160- err := ioutil.WriteFile(bootloaderUbootFwEnvFile, []byte(""), 0644)
161- c.Assert(err, IsNil)
162+ env, err := uenv.Create(bootloaderUbootFwEnvFile, 4096)
163+ c.Assert(err, IsNil)
164+ env.Set("snappy_ab", "b")
165+ env.Set("snappy_mode", "regular")
166+ err = env.Save()
167+ c.Assert(err, IsNil)
168+
169+ st, err := os.Stat(bootloaderUbootFwEnvFile)
170+ c.Assert(err, IsNil)
171+ time.Sleep(100 * time.Millisecond)
172
173 partition := New()
174 u := newUboot(partition)
175 c.Assert(u, NotNil)
176
177- // we simulate here that fw_printenv bootloaderreturns
178- runCommandWithStdout = func(args ...string) (string, error) {
179- if args[0] == "fw_printenv" && args[2] == bootloaderRootfsVar {
180- return "b", nil
181- }
182-
183- return "something", nil
184- }
185-
186- allCommands = nil
187- runCommand = mockRunCommandWithCapture
188 err = u.(*uboot).setBootVar(bootloaderRootfsVar, "b")
189 c.Assert(err, IsNil)
190- c.Assert(allCommands, HasLen, 0)
191-
192- err = u.(*uboot).setBootVar(bootloaderRootfsVar, "a")
193- c.Assert(err, IsNil)
194- c.Assert(allCommands, HasLen, 1)
195- c.Assert(allCommands[0], DeepEquals, singleCommand{"fw_setenv", bootloaderRootfsVar, "a"})
196+
197+ env, err = uenv.Open(bootloaderUbootFwEnvFile)
198+ c.Assert(err, IsNil)
199+ c.Assert(env.String(), Equals, "snappy_ab=b\nsnappy_mode=regular\n")
200+
201+ st2, err := os.Stat(bootloaderUbootFwEnvFile)
202+ c.Assert(err, IsNil)
203+ c.Assert(st.ModTime(), Equals, st2.ModTime())
204 }

Subscribers

People subscribed via source and target branches