Skip to content
Snippets Groups Projects
Commit d7f6eeee authored by Zygmunt Krynicki's avatar Zygmunt Krynicki
Browse files

ota/raucadapter: fix handling of pristine boot configuration


Instead of ignoring the requests entirely, assume slot A is active
and _carry out_ the requests. This fixes updates.

Tested-By: default avatarZygmunt Krynicki <zygmunt.krynicki@huawei.com>
Signed-off-by: default avatarZygmunt Krynicki <zygmunt.krynicki@huawei.com>
parent ece98c17
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,6 @@ package raucadapter ...@@ -8,7 +8,6 @@ package raucadapter
import ( import (
"errors" "errors"
"fmt"
"git.ostc-eu.org/OSTC/OHOS/components/sysota/boot" "git.ostc-eu.org/OSTC/OHOS/components/sysota/boot"
"git.ostc-eu.org/OSTC/OHOS/components/sysota/rauc/installhandler" "git.ostc-eu.org/OSTC/OHOS/components/sysota/rauc/installhandler"
...@@ -60,17 +59,11 @@ func New(proto boot.Protocol, bootModeHolder BootModeHolder) *Adapter { ...@@ -60,17 +59,11 @@ func New(proto boot.Protocol, bootModeHolder BootModeHolder) *Adapter {
func (adapter *Adapter) PrimarySlot() (boot.Slot, error) { func (adapter *Adapter) PrimarySlot() (boot.Slot, error) {
switch adapter.bootModeHolder.BootMode() { switch adapter.bootModeHolder.BootMode() {
case boot.Normal: case boot.Normal:
slot, err := adapter.proto.QueryActive() return adapter.queryActiveOrPristine()
if errors.Is(err, boot.ErrPristineBootConfig) {
fmt.Printf("Forging RAUC get-primary while in pristine boot configuration\n")
return boot.SlotA, nil
}
return slot, err
case boot.Try: case boot.Try:
// TODO(zyga): consider using boot.SynthesizeInactiveSlot and dropping // TODO(zyga): consider using boot.SynthesizeInactiveSlot and dropping
// QueryInactive from the API. // QueryInactive from the API.
return adapter.proto.QueryInactive() return adapter.queryInactiveOrPristine()
default: default:
return boot.InvalidSlot, boot.ErrInvalidBootMode return boot.InvalidSlot, boot.ErrInvalidBootMode
} }
...@@ -91,14 +84,8 @@ func (adapter *Adapter) SetPrimarySlot(slot boot.Slot) error { ...@@ -91,14 +84,8 @@ func (adapter *Adapter) SetPrimarySlot(slot boot.Slot) error {
return boot.ErrInvalidSlot return boot.ErrInvalidSlot
} }
activeSlot, err := adapter.proto.QueryActive() activeSlot, err := adapter.queryActiveOrPristine()
if err != nil { if err != nil {
if errors.Is(err, boot.ErrPristineBootConfig) && adapter.bootModeHolder.BootMode() == boot.Normal {
fmt.Printf("Ignoring RAUC set-primary %s while in pristine boot configuration\n", slot)
return nil
}
return err return err
} }
...@@ -147,21 +134,7 @@ func (adapter *Adapter) SlotState(slot boot.Slot) (boot.SlotState, error) { ...@@ -147,21 +134,7 @@ func (adapter *Adapter) SlotState(slot boot.Slot) (boot.SlotState, error) {
return boot.InvalidSlotState, boot.ErrInvalidSlot return boot.InvalidSlotState, boot.ErrInvalidSlot
} }
active, err := adapter.proto.QueryActive() active, err := adapter.queryActiveOrPristine()
if err != nil {
if errors.Is(err, boot.ErrPristineBootConfig) {
fmt.Printf("Forging RAUC get-state %s while in pristine boot configuration\n", slot)
if slot == boot.SlotA {
return boot.GoodSlot, nil
}
return boot.BadSlot, nil
}
return boot.InvalidSlotState, err
}
if err != nil { if err != nil {
return boot.InvalidSlotState, err return boot.InvalidSlotState, err
} }
...@@ -207,16 +180,8 @@ func (adapter *Adapter) SetSlotState(slot boot.Slot, state boot.SlotState) error ...@@ -207,16 +180,8 @@ func (adapter *Adapter) SetSlotState(slot boot.Slot, state boot.SlotState) error
return boot.ErrInvalidSlotState return boot.ErrInvalidSlotState
} }
active, err := adapter.proto.QueryActive() active, err := adapter.queryActiveOrPristine()
if err != nil { if err != nil {
if errors.Is(err, boot.ErrPristineBootConfig) && adapter.bootModeHolder.BootMode() == boot.Normal {
if (slot == boot.SlotA && state == boot.GoodSlot) || (slot == boot.SlotB && state == boot.BadSlot) {
fmt.Printf("Ignoring RAUC set-state %s %s while in pristine boot configuration\n", slot, state)
return nil
}
}
return err return err
} }
...@@ -313,3 +278,23 @@ func (adapter *Adapter) PostInstallHandler(ctx *installhandler.HandlerContext) e ...@@ -313,3 +278,23 @@ func (adapter *Adapter) PostInstallHandler(ctx *installhandler.HandlerContext) e
return nil return nil
} }
func (adapter *Adapter) queryActiveOrPristine() (boot.Slot, error) {
active, err := adapter.proto.QueryActive()
if errors.Is(err, boot.ErrPristineBootConfig) {
active = boot.SlotA
err = nil
}
return active, err
}
func (adapter *Adapter) queryInactiveOrPristine() (boot.Slot, error) {
active, err := adapter.proto.QueryInactive()
if errors.Is(err, boot.ErrPristineBootConfig) {
active = boot.SlotB
err = nil
}
return active, err
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment