Merge lp:~mvo/snappy/15.04-snappy-bootsuccess-env2 into lp:~snappy-dev/snappy/15.04-deprecated

Proposed by Michael Vogt
Status: Merged
Approved by: John Lenton
Approved revision: 462
Merged at revision: 461
Proposed branch: lp:~mvo/snappy/15.04-snappy-bootsuccess-env2
Merge into: lp:~snappy-dev/snappy/15.04-deprecated
Diff against target: 307 lines (+158/-27)
7 files modified
debian/control (+1/-0)
dependencies.tsv (+1/-0)
partition/bootloader.go (+2/-0)
partition/bootloader_grub.go (+6/-8)
partition/bootloader_uboot.go (+91/-19)
partition/bootloader_uboot_test.go (+56/-0)
partition/partition_test.go (+1/-0)
To merge this branch: bzr merge lp:~mvo/snappy/15.04-snappy-bootsuccess-env2
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+265510@code.launchpad.net

Commit message

Backports of the uboot.env changes from trunk.

Description of the change

This branch backports the uboot.env changes from trunk to 15.04

To post a comment you must log in.
462. By Michael Vogt

merge remaining revisions

Revision history for this message
John Lenton (chipaca) :
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-04-21 22:02:02 +0000
3+++ debian/control 2015-07-22 12:17:55 +0000
4@@ -15,6 +15,7 @@
5 golang-goconfigparser-dev,
6 golang-juju-loggo-dev,
7 golang-pb-dev,
8+ golang-uboot-go-dev,
9 golang-yaml.v2-dev
10 Standards-Version: 3.9.6
11 Homepage: https://launchpad.net/snappy
12
13=== modified file 'dependencies.tsv'
14--- dependencies.tsv 2015-03-19 09:33:48 +0000
15+++ dependencies.tsv 2015-07-22 12:17:55 +0000
16@@ -4,5 +4,6 @@
17 github.com/jessevdk/go-flags git 15347ef417a300349807983f15af9e65cd2e1b3a 2015-01-25T08:53:51Z
18 github.com/juju/loggo git 4c7cbce140ca070eeb59a28f4bf9507e511711f9 2015-02-26T05:51:10Z
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 gopkg.in/yaml.v2 git 49c95bdc21843256fb6c4e0d370a05f24a0bf213 2015-02-24T22:57:58Z
22 launchpad.net/gocheck bzr gustavo@niemeyer.net-20140225173054-xu9zlkf9kxhvow02 87
23
24=== modified file 'partition/bootloader.go'
25--- partition/bootloader.go 2015-04-14 20:37:54 +0000
26+++ partition/bootloader.go 2015-07-22 12:17:55 +0000
27@@ -27,6 +27,8 @@
28 // that the boot of the new rootfs was successful).
29 bootloaderBootmodeVar = "snappy_mode"
30
31+ bootloaderTrialBootVar = "snappy_trial_boot"
32+
33 // Initial and final values
34 bootloaderBootmodeTry = "try"
35 bootloaderBootmodeSuccess = "regular"
36
37=== modified file 'partition/bootloader_grub.go'
38--- partition/bootloader_grub.go 2015-04-30 11:28:39 +0000
39+++ partition/bootloader_grub.go 2015-07-22 12:17:55 +0000
40@@ -30,17 +30,15 @@
41 bootloaderGrubConfigFileReal = "/boot/grub/grub.cfg"
42 bootloaderGrubEnvFileReal = "/boot/grub/grubenv"
43
44- bootloaderGrubEnvCmdReal = "/usr/bin/grub-editenv"
45- bootloaderGrubUpdateCmdReal = "/usr/sbin/update-grub"
46- bootloaderGrubTrialBootVarReal = "snappy_trial_boot"
47+ bootloaderGrubEnvCmdReal = "/usr/bin/grub-editenv"
48+ bootloaderGrubUpdateCmdReal = "/usr/sbin/update-grub"
49 )
50
51 // var to make it testable
52 var (
53- bootloaderGrubDir = bootloaderGrubDirReal
54- bootloaderGrubConfigFile = bootloaderGrubConfigFileReal
55- bootloaderGrubTrialBootVar = bootloaderGrubTrialBootVarReal
56- bootloaderGrubEnvFile = bootloaderGrubEnvFileReal
57+ bootloaderGrubDir = bootloaderGrubDirReal
58+ bootloaderGrubConfigFile = bootloaderGrubConfigFileReal
59+ bootloaderGrubEnvFile = bootloaderGrubEnvFileReal
60
61 bootloaderGrubEnvCmd = bootloaderGrubEnvCmdReal
62 bootloaderGrubUpdateCmd = bootloaderGrubUpdateCmdReal
63@@ -136,7 +134,7 @@
64 func (g *grub) MarkCurrentBootSuccessful() (err error) {
65 // Clear the variable set by grub on boot to denote a good
66 // boot.
67- if err := g.unsetBootVar(bootloaderGrubTrialBootVar); err != nil {
68+ if err := g.unsetBootVar(bootloaderTrialBootVar); err != nil {
69 return err
70 }
71
72
73=== modified file 'partition/bootloader_uboot.go'
74--- partition/bootloader_uboot.go 2015-06-03 12:12:13 +0000
75+++ partition/bootloader_uboot.go 2015-07-22 12:17:55 +0000
76@@ -28,6 +28,7 @@
77 "launchpad.net/snappy/helpers"
78
79 "github.com/mvo5/goconfigparser"
80+ "github.com/mvo5/uboot-go/uenv"
81 )
82
83 const (
84@@ -40,9 +41,11 @@
85 // this partition is "good".
86 bootloaderUbootStampFileReal = "/boot/uboot/snappy-stamp.txt"
87
88- // the main uEnv.txt u-boot config file sources this snappy
89- // boot-specific config file.
90+ // DEPRECATED:
91 bootloaderUbootEnvFileReal = "/boot/uboot/snappy-system.txt"
92+
93+ // the real uboot env
94+ bootloaderUbootFwEnvFileReal = "/boot/uboot/uboot.env"
95 )
96
97 // var to make it testable
98@@ -51,6 +54,7 @@
99 bootloaderUbootConfigFile = bootloaderUbootConfigFileReal
100 bootloaderUbootStampFile = bootloaderUbootStampFileReal
101 bootloaderUbootEnvFile = bootloaderUbootEnvFileReal
102+ bootloaderUbootFwEnvFile = bootloaderUbootFwEnvFileReal
103 atomicFileUpdate = atomicFileUpdateImpl
104 )
105
106@@ -199,23 +203,6 @@
107 return file.Sync()
108 }
109
110-func (u *uboot) MarkCurrentBootSuccessful() (err error) {
111- changes := []configFileChange{
112- configFileChange{Name: bootloaderBootmodeVar,
113- Value: bootloaderBootmodeSuccess,
114- },
115- configFileChange{Name: bootloaderRootfsVar,
116- Value: string(u.currentRootfs),
117- },
118- }
119-
120- if err := modifyNameValueFile(bootloaderUbootEnvFile, changes); err != nil {
121- return err
122- }
123-
124- return os.RemoveAll(bootloaderUbootStampFile)
125-}
126-
127 func (u *uboot) SyncBootFiles() (err error) {
128 srcDir := u.currentBootPath
129 destDir := u.otherBootPath
130@@ -317,6 +304,91 @@
131 return err
132 }
133
134+func (u *uboot) unsetBootVar(name string) error {
135+ hasBootVar, err := u.hasBootVar(name)
136+ if err != nil {
137+ return err
138+ }
139+
140+ // already unset, nothing to do
141+ if !hasBootVar {
142+ return nil
143+ }
144+
145+ return u.setBootVar(name, "")
146+}
147+
148+func (u *uboot) setBootVar(name, value string) error {
149+ env, err := uenv.Open(bootloaderUbootFwEnvFile)
150+ if err != nil {
151+ return err
152+ }
153+
154+ // already set, nothing to do
155+ if env.Get(name) == value {
156+ return nil
157+ }
158+
159+ env.Set(name, value)
160+ return env.Save()
161+}
162+
163+func (u *uboot) hasBootVar(name string) (bool, error) {
164+ v, err := u.getBootVar(name)
165+ return v != "", err
166+}
167+
168+func (u *uboot) getBootVar(name string) (string, error) {
169+ env, err := uenv.Open(bootloaderUbootFwEnvFile)
170+ if err != nil {
171+ return "", err
172+ }
173+
174+ return env.Get(name), nil
175+}
176+
177+// FIXME: this is super similar to grub now, refactor to extract the
178+// common code
179+func (u *uboot) markCurrentBootSuccessfulFwEnv(currentRootfs string) error {
180+ // Clear the variable set on boot to denote a good boot.
181+ if err := u.unsetBootVar(bootloaderTrialBootVar); err != nil {
182+ return err
183+ }
184+
185+ if err := u.setBootVar(bootloaderRootfsVar, currentRootfs); err != nil {
186+ return err
187+ }
188+
189+ return u.setBootVar(bootloaderBootmodeVar, bootloaderBootmodeSuccess)
190+}
191+
192+func (u *uboot) markCurrentBootSuccessfulLegacy(currentRootfs string) error {
193+ changes := []configFileChange{
194+ configFileChange{Name: bootloaderBootmodeVar,
195+ Value: bootloaderBootmodeSuccess,
196+ },
197+ configFileChange{Name: bootloaderRootfsVar,
198+ Value: string(u.currentRootfs),
199+ },
200+ }
201+
202+ if err := modifyNameValueFile(bootloaderUbootEnvFile, changes); err != nil {
203+ return err
204+ }
205+
206+ return os.RemoveAll(bootloaderUbootStampFile)
207+}
208+
209+func (u *uboot) MarkCurrentBootSuccessful() error {
210+ // modern system
211+ if helpers.FileExists(bootloaderUbootFwEnvFile) {
212+ return u.markCurrentBootSuccessfulFwEnv(u.currentRootfs)
213+ }
214+
215+ // legacy
216+ return u.markCurrentBootSuccessfulLegacy(u.currentRootfs)
217+}
218+
219 // Write lines to file atomically. File does not have to preexist.
220 // FIXME: put into utils package
221 func atomicFileUpdateImpl(file string, lines []string) (err error) {
222
223=== modified file 'partition/bootloader_uboot_test.go'
224--- partition/bootloader_uboot_test.go 2015-06-02 20:23:20 +0000
225+++ partition/bootloader_uboot_test.go 2015-07-22 12:17:55 +0000
226@@ -22,9 +22,12 @@
227 "os"
228 "path/filepath"
229 "strings"
230+ "time"
231
232 . "launchpad.net/gocheck"
233 "launchpad.net/snappy/helpers"
234+
235+ "github.com/mvo5/uboot-go/uenv"
236 )
237
238 // TODO move to uboot specific test suite.
239@@ -328,3 +331,56 @@
240 c.Check(strings.Contains(string(bytes), "snappy_mode=regular"), Equals, true)
241 c.Check(strings.Contains(string(bytes), "snappy_ab=a"), Equals, true)
242 }
243+
244+func (s *PartitionTestSuite) TestUbootMarkCurrentBootSuccessfulFwEnv(c *C) {
245+ s.makeFakeUbootEnv(c)
246+
247+ env, err := uenv.Create(bootloaderUbootFwEnvFile, 4096)
248+ c.Assert(err, IsNil)
249+ env.Set("snappy_ab", "a")
250+ env.Set("snappy_mode", "try")
251+ env.Set("snappy_trial_boot", "1")
252+ err = env.Save()
253+ c.Assert(err, IsNil)
254+
255+ partition := New()
256+ u := newUboot(partition)
257+ c.Assert(u, NotNil)
258+
259+ err = u.MarkCurrentBootSuccessful()
260+ c.Assert(err, IsNil)
261+
262+ env, err = uenv.Open(bootloaderUbootFwEnvFile)
263+ c.Assert(err, IsNil)
264+ c.Assert(env.String(), Equals, "snappy_ab=a\nsnappy_mode=regular\n")
265+}
266+
267+func (s *PartitionTestSuite) TestUbootSetEnvNoUselessWrites(c *C) {
268+ s.makeFakeUbootEnv(c)
269+
270+ env, err := uenv.Create(bootloaderUbootFwEnvFile, 4096)
271+ c.Assert(err, IsNil)
272+ env.Set("snappy_ab", "a")
273+ env.Set("snappy_mode", "regular")
274+ err = env.Save()
275+ c.Assert(err, IsNil)
276+
277+ st, err := os.Stat(bootloaderUbootFwEnvFile)
278+ c.Assert(err, IsNil)
279+ time.Sleep(100 * time.Millisecond)
280+
281+ partition := New()
282+ u := newUboot(partition)
283+ c.Assert(u, NotNil)
284+
285+ err = u.(*uboot).setBootVar(bootloaderRootfsVar, "a")
286+ c.Assert(err, IsNil)
287+
288+ env, err = uenv.Open(bootloaderUbootFwEnvFile)
289+ c.Assert(err, IsNil)
290+ c.Assert(env.String(), Equals, "snappy_ab=a\nsnappy_mode=regular\n")
291+
292+ st2, err := os.Stat(bootloaderUbootFwEnvFile)
293+ c.Assert(err, IsNil)
294+ c.Assert(st.ModTime(), Equals, st2.ModTime())
295+}
296
297=== modified file 'partition/partition_test.go'
298--- partition/partition_test.go 2015-03-30 14:42:31 +0000
299+++ partition/partition_test.go 2015-07-22 12:17:55 +0000
300@@ -60,6 +60,7 @@
301 bootloaderUbootDir = filepath.Join(s.tempdir, "boot", "uboot")
302 bootloaderUbootConfigFile = filepath.Join(bootloaderUbootDir, "uEnv.txt")
303 bootloaderUbootEnvFile = filepath.Join(bootloaderUbootDir, "uEnv.txt")
304+ bootloaderUbootFwEnvFile = filepath.Join(bootloaderUbootDir, "uboot.env")
305 bootloaderUbootStampFile = filepath.Join(bootloaderUbootDir, "snappy-stamp.txt")
306
307 c.Assert(mounts, DeepEquals, mountEntryArray(nil))

Subscribers

People subscribed via source and target branches