diff --git a/ota/raucadapter/raucadapter.go b/ota/raucadapter/raucadapter.go index bcc22409ab168089509cb1c0cb69edf7391c36b9..f1c472390242295d6276e40ebd7b6b342b69b5ce 100644 --- a/ota/raucadapter/raucadapter.go +++ b/ota/raucadapter/raucadapter.go @@ -8,7 +8,6 @@ package raucadapter import ( "errors" - "fmt" "git.ostc-eu.org/OSTC/OHOS/components/sysota/boot" "git.ostc-eu.org/OSTC/OHOS/components/sysota/rauc/installhandler" @@ -60,17 +59,11 @@ func New(proto boot.Protocol, bootModeHolder BootModeHolder) *Adapter { func (adapter *Adapter) PrimarySlot() (boot.Slot, error) { switch adapter.bootModeHolder.BootMode() { case boot.Normal: - slot, err := adapter.proto.QueryActive() - 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 + return adapter.queryActiveOrPristine() case boot.Try: // TODO(zyga): consider using boot.SynthesizeInactiveSlot and dropping // QueryInactive from the API. - return adapter.proto.QueryInactive() + return adapter.queryInactiveOrPristine() default: return boot.InvalidSlot, boot.ErrInvalidBootMode } @@ -91,14 +84,8 @@ func (adapter *Adapter) SetPrimarySlot(slot boot.Slot) error { return boot.ErrInvalidSlot } - activeSlot, err := adapter.proto.QueryActive() + activeSlot, err := adapter.queryActiveOrPristine() 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 } @@ -147,21 +134,7 @@ func (adapter *Adapter) SlotState(slot boot.Slot) (boot.SlotState, error) { return boot.InvalidSlotState, boot.ErrInvalidSlot } - active, err := adapter.proto.QueryActive() - 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 - } - + active, err := adapter.queryActiveOrPristine() if err != nil { return boot.InvalidSlotState, err } @@ -207,16 +180,8 @@ func (adapter *Adapter) SetSlotState(slot boot.Slot, state boot.SlotState) error return boot.ErrInvalidSlotState } - active, err := adapter.proto.QueryActive() + active, err := adapter.queryActiveOrPristine() 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 } @@ -313,3 +278,23 @@ func (adapter *Adapter) PostInstallHandler(ctx *installhandler.HandlerContext) e 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 +}