def do_sign(args): if args.rsa_pkcs1_15: keys.sign_rsa_pss = False version_num = next_version_number(args, version.decode_version("0"), "lastVerNum.txt") if args.security_counter is None: # Security counter has not been explicitly provided, # generate it from the version number args.security_counter = ((version_num.major << 24) + (version_num.minor << 16) + version_num.revision) pad_size = macro_parser.evaluate_macro(args.layout, sign_bin_size_re, 0, 1) img = image.Image.load(args.infile, version=version_num, header_size=args.header_size, security_cnt=args.security_counter, included_header=args.included_header, pad=pad_size) key = keys.load(args.key, args.public_key_format) if args.key else None ram_load_address = macro_parser.evaluate_macro(args.layout, image_load_address_re, 0, 1) img.sign(key, ram_load_address, args.dependencies) if pad_size: img.pad_to(pad_size, args.align) img.save(args.outfile)
def find_slots(self): offsets = {} sizes = {} offsets = macro_parser.evaluate_macro(self.layout_path, offset_re, 1, 2) sizes = macro_parser.evaluate_macro(self.layout_path, size_re, 1, 2) if 'SECURE' not in offsets: raise Exception("Image config does not have secure partition") if 'NON_SECURE' not in offsets: raise Exception("Image config does not have non-secure partition") self.offsets = offsets self.sizes = sizes
def wrap(key, align, version, header_size, pad_header, layout, pad, confirm, max_sectors, overwrite_only, endian, encrypt, infile, outfile, dependencies, hex_addr, erased_val, save_enctlv, public_key_format, security_counter): slot_size = macro_parser.evaluate_macro(layout, sign_bin_size_re, 0, 1) load_addr = macro_parser.evaluate_macro(layout, load_addr_re, 0, 1) rom_fixed = macro_parser.evaluate_macro(layout, rom_fixed_re, 0, 1) if "_s" in layout: boot_record = "SPE" elif "_ns" in layout: boot_record = "NSPE" else: boot_record = "NSPE_SPE" img = imgtool.image.Image(version=imgtool.version.decode_version(version), header_size=header_size, pad_header=pad_header, pad=pad, confirm=confirm, align=int(align), slot_size=slot_size, max_sectors=max_sectors, overwrite_only=overwrite_only, endian=endian, load_addr=load_addr, rom_fixed=rom_fixed, erased_val=erased_val, save_enctlv=save_enctlv, security_counter=security_counter) img.load(infile) key = imgtool.main.load_key(key) if key else None enckey = imgtool.main.load_key(encrypt) if encrypt else None if enckey and key: if (isinstance(key, imgtool.keys.RSA) and not isinstance(enckey, imgtool.keys.RSAPublic)): # FIXME raise click.UsageError("Signing and encryption must use the same " "type of key") img.create(key, public_key_format, enckey, dependencies, boot_record) img.save(outfile, hex_addr)
def do_flash(args): image_value_re = re.compile(r"^\s*" + args.macro + "\s*=\s*(.*)") value = macro_parser.evaluate_macro(args.layout, image_value_re, 0, 1, True) if args.setting == 1: begin_line = "set " + args.begin else: begin_line = args.begin for line in fileinput.input(args.infile, inplace=True): if line.startswith(begin_line): if args.division: value = int(value / int(args.division)) if args.phexa == 0: line = begin_line + "=" + str(value) + "\n" else: line = begin_line + "=" + hex(value) + "\n" sys.stdout.write(line)
def flash(infile, layout, macro, begin, setting, division, phexa): image_value_re = re.compile(r"^\s*" + macro + "\s*=\s*(.*)") try: value = macro_parser.evaluate_macro(layout, image_value_re, 0, 1) except: pass if value is not None: if setting == 1: begin_line = "set " + begin else: begin_line = begin for line in fileinput.input(infile, inplace=True): if line.startswith(begin_line): if division: value = int(value / int(division)) if phexa == 0: line = begin_line + "=" + str(value) + "\n" else: line = begin_line + "=" + hex(value) + "\n" sys.stdout.write(line)