Skip to content

Commit

Permalink
add set boot slot command
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Jan 10, 2025
1 parent f048f8e commit a07d27e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
40 changes: 40 additions & 0 deletions flashloader/image-loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
class ActionId(enum.IntEnum):
CORRUPT_APP_A = 128
CORRUPT_APP_B = 129
SET_BOOT_SLOT = 130


_LOGGER = logging.getLogger(__name__)
Expand All @@ -78,11 +79,37 @@ class Target(enum.Enum):
APP_B = 2


class AppSel(enum.IntEnum):
APP_A = 0
APP_B = 1


class ImageLoader:
def __init__(self, com_if: ComInterface, verificator: PusVerificator) -> None:
self.com_if = com_if
self.verificator = verificator

def handle_boot_sel_cmd(self, target: AppSel):
_LOGGER.info("Sending ping command")
action_tc = PusTc(
apid=0x00,
service=PusService.S8_FUNC_CMD,
subservice=ActionId.SET_BOOT_SLOT,
seq_count=SEQ_PROVIDER.get_and_increment(),
app_data=bytes([target]),
)
self.verificator.add_tc(action_tc)
self.com_if.send(bytes(action_tc.pack()))
data_available = self.com_if.data_available(0.4)
if not data_available:
_LOGGER.warning("no reply received for boot image selection command")
for reply in self.com_if.receive():
result = self.verificator.add_tm(
Service1Tm.from_tm(PusTm.unpack(reply, 0), UnpackParams(0))
)
if result is not None and result.completed:
_LOGGER.info("received boot image selection command confirmation")

def handle_ping_cmd(self):
_LOGGER.info("Sending ping command")
ping_tc = PusTc(
Expand Down Expand Up @@ -251,6 +278,9 @@ def main() -> int:
prog="image-loader", description="Python VA416XX Image Loader Application"
)
parser.add_argument("-p", "--ping", action="store_true", help="Send ping command")
parser.add_argument(
"-s", "--sel", choices=["a", "b"], help="Set boot slot (Slot A or B)"
)
parser.add_argument("-c", "--corrupt", action="store_true", help="Corrupt a target")
parser.add_argument(
"-t",
Expand Down Expand Up @@ -286,13 +316,23 @@ def main() -> int:
target = Target.APP_A
elif args.target == "b":
target = Target.APP_B

boot_sel = None
if args.sel:
if args.sel == "a":
boot_sel = AppSel.APP_A
elif args.sel == "b":
boot_sel = AppSel.APP_B

image_loader = ImageLoader(com_if, verificator)
file_path = None
result = -1
if args.ping:
image_loader.handle_ping_cmd()
com_if.close()
return 0
if args.sel and boot_sel is not None:
image_loader.handle_boot_sel_cmd(boot_sel)
if target:
if not args.corrupt:
if not args.path:
Expand Down
4 changes: 2 additions & 2 deletions flashloader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const RX_DEBUGGING: bool = false;
pub enum ActionId {
CorruptImageA = 128,
CorruptImageB = 129,
SetPreferredImage = 130,
SetBootSlot = 130,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive)]
Expand Down Expand Up @@ -357,7 +357,7 @@ mod app {
rprintln!("corrupting App Image B");
corrupt_image(APP_B_START_ADDR);
}
if pus_tc.subservice() == ActionId::SetPreferredImage as u8 {
if pus_tc.subservice() == ActionId::SetBootSlot as u8 {
if pus_tc.app_data().is_empty() {
log::warn!(target: "TC Handler", "App data for preferred image command too short");
}
Expand Down

0 comments on commit a07d27e

Please sign in to comment.