40
41
// this partition is "good".
41
42
bootloaderUbootStampFileReal = "/boot/uboot/snappy-stamp.txt"
43
// the main uEnv.txt u-boot config file sources this snappy
44
// boot-specific config file.
45
45
bootloaderUbootEnvFileReal = "/boot/uboot/snappy-system.txt"
48
bootloaderUbootFwEnvFileReal = "/boot/uboot/uboot.env"
48
51
// var to make it testable
199
203
return file.Sync()
202
func (u *uboot) MarkCurrentBootSuccessful() (err error) {
203
changes := []configFileChange{
204
configFileChange{Name: bootloaderBootmodeVar,
205
Value: bootloaderBootmodeSuccess,
207
configFileChange{Name: bootloaderRootfsVar,
208
Value: string(u.currentRootfs),
212
if err := modifyNameValueFile(bootloaderUbootEnvFile, changes); err != nil {
216
return os.RemoveAll(bootloaderUbootStampFile)
219
206
func (u *uboot) SyncBootFiles() (err error) {
220
207
srcDir := u.currentBootPath
221
208
destDir := u.otherBootPath
307
func (u *uboot) unsetBootVar(name string) error {
308
hasBootVar, err := u.hasBootVar(name)
313
// already unset, nothing to do
318
return u.setBootVar(name, "")
321
func (u *uboot) setBootVar(name, value string) error {
322
env, err := uenv.Open(bootloaderUbootFwEnvFile)
327
// already set, nothing to do
328
if env.Get(name) == value {
336
func (u *uboot) hasBootVar(name string) (bool, error) {
337
v, err := u.getBootVar(name)
341
func (u *uboot) getBootVar(name string) (string, error) {
342
env, err := uenv.Open(bootloaderUbootFwEnvFile)
347
return env.Get(name), nil
350
// FIXME: this is super similar to grub now, refactor to extract the
352
func (u *uboot) markCurrentBootSuccessfulFwEnv(currentRootfs string) error {
353
// Clear the variable set on boot to denote a good boot.
354
if err := u.unsetBootVar(bootloaderTrialBootVar); err != nil {
358
if err := u.setBootVar(bootloaderRootfsVar, currentRootfs); err != nil {
362
return u.setBootVar(bootloaderBootmodeVar, bootloaderBootmodeSuccess)
365
func (u *uboot) markCurrentBootSuccessfulLegacy(currentRootfs string) error {
366
changes := []configFileChange{
367
configFileChange{Name: bootloaderBootmodeVar,
368
Value: bootloaderBootmodeSuccess,
370
configFileChange{Name: bootloaderRootfsVar,
371
Value: string(u.currentRootfs),
375
if err := modifyNameValueFile(bootloaderUbootEnvFile, changes); err != nil {
379
return os.RemoveAll(bootloaderUbootStampFile)
382
func (u *uboot) MarkCurrentBootSuccessful() error {
384
if helpers.FileExists(bootloaderUbootFwEnvFile) {
385
return u.markCurrentBootSuccessfulFwEnv(u.currentRootfs)
389
return u.markCurrentBootSuccessfulLegacy(u.currentRootfs)
320
392
// Write lines to file atomically. File does not have to preexist.
321
393
// FIXME: put into utils package
322
394
func atomicFileUpdateImpl(file string, lines []string) (err error) {