diff --git a/tockloader/app_tab.py b/tockloader/app_tab.py index 235811c..c7217f6 100644 --- a/tockloader/app_tab.py +++ b/tockloader/app_tab.py @@ -299,12 +299,13 @@ def align_down_to(v, a): else: return None - def delete_tbfh_tlv(self, tlvid): + def delete_tlv(self, tlvid): """ - Delete a particular TLV from each TBF header. + Delete a particular TLV from each TBF header and footer. """ for tbf in self.tbfs: tbf.tbfh.delete_tlv(tlvid) + tbf.tbff.delete_tlv(tlvid) def modify_tbfh_tlv(self, tlvid, field, value): """ diff --git a/tockloader/main.py b/tockloader/main.py index bef508a..aadf76d 100644 --- a/tockloader/main.py +++ b/tockloader/main.py @@ -353,10 +353,10 @@ def command_tbf_delete_tlv(args): tabs = collect_tabs(args) if len(tabs) == 0: - raise TockLoaderException("No TABs found, no TBF headers to process") + raise TockLoaderException("No TABs found, no TBF to process") tlvid = args.tlvid - logging.status("Removing TLV ID {} from TBF headers...".format(tlvid)) + logging.status("Removing TLV ID {} from TBF...".format(tlvid)) for tab in tabs: # Ask the user which TBF binaries to update. tbf_names = tab.get_tbf_names() @@ -369,7 +369,7 @@ def command_tbf_delete_tlv(args): for i, tbf_name in enumerate(tbf_names): if i == index or index == len(tbf_names): app = tab.extract_tbf(tbf_name) - app.delete_tbfh_tlv(tlvid) + app.delete_tlv(tlvid) tab.update_tbf(app) diff --git a/tockloader/tbfh.py b/tockloader/tbfh.py index a59f93e..291ee98 100644 --- a/tockloader/tbfh.py +++ b/tockloader/tbfh.py @@ -1007,7 +1007,7 @@ def __init__(self, size): self.fields["checksum"] = self._checksum(self.get_binary()) -class TBFFooterTLVCredentials: +class TBFFooterTLVCredentials(TBFTLV): """ Represent a Credentials TLV in the footer of a TBF. """ @@ -1120,6 +1120,8 @@ def __init__(self, tbfh, buffer): self.version = tbfh.version # List of all TLVs in the footer. self.tlvs = [] + # Keep track if tockloader has modified the footer. + self.modified = False # Iterate all TLVs and add to list. position = 0 @@ -1136,6 +1138,21 @@ def __init__(self, tbfh, buffer): buffer = buffer[tlv_length:] + def delete_tlv(self, tlvid): + """ + Delete a particular TLV by ID if it exists. + """ + indices = [] + for i, tlv in enumerate(self.tlvs): + if tlv.get_tlvid() == tlvid: + # Reverse the list + indices.insert(0, i) + # Pop starting with the last match + for index in indices: + logging.debug("Removing TLV at index {}".format(index)) + self.tlvs.pop(index) + self.modified = True + def get_binary(self): """ Get the TBF footer in a bytes array.