rpi-eeprom-config: Add -x option to extract files

For test/debug add an option to extract all of the modifiable files.
This commit is contained in:
Tim Gover
2022-11-25 16:30:34 +00:00
parent 141a8cd9f0
commit d2cbfbc292

View File

@@ -360,8 +360,15 @@ class BootloaderImage(object):
def get_file(self, filename):
hdr_offset, length, is_last = self.find_file(filename)
offset = hdr_offset + 4 + FILE_HDR_LEN
config_bytes = self._bytes[offset:offset+length-FILENAME_LEN-4]
return config_bytes
file_bytes = self._bytes[offset:offset+length-FILENAME_LEN-4]
return file_bytes
def extract_files(self):
for i in range(0, len(self._sections)):
s = self._sections[i]
if s.magic == FILE_MAGIC:
file_bytes = self.get_file(s.filename)
open(s.filename, 'wb').write(file_bytes)
def read(self):
config_bytes = self.get_file('bootconf.txt')
@@ -457,6 +464,7 @@ See 'rpi-eeprom-update -h' for more information about the available EEPROM image
parser.add_argument('-o', '--out', help='Name of output file', required=False)
parser.add_argument('-d', '--digest', help='Signed boot only. The name of the .sig file generated by rpi-eeprom-dgst for config.txt ', required=False)
parser.add_argument('-p', '--pubkey', help='Signed boot only. The name of the RSA public key file to store in the EEPROM', required=False)
parser.add_argument('-x', '--extract', action='store_true', default=False, help='Extract the modifiable files (boot.conf, pubkey, signature)', required=False)
parser.add_argument('eeprom', nargs='?', help='Name of EEPROM file to use as input')
args = parser.parse_args()
@@ -468,6 +476,9 @@ See 'rpi-eeprom-update -h' for more information about the available EEPROM image
if args.edit:
edit_config(args.eeprom)
elif args.eeprom is not None and args.extract:
image = BootloaderImage(args.eeprom, args.out)
image.extract_files()
elif args.apply is not None:
if not os.path.exists(args.apply):
exit_error("config file '%s' not found" % args.apply)