def get_base_mpu_regions(MPU_config, size_data): default_flash_size = get_default_flash_sections(size_data) default_ram_size = get_default_ram_sections(size_data) flash_pow_size = ld_helpers.next_power_2(default_flash_size) ram_pow_size = ld_helpers.next_power_2(default_ram_size) mpu_helpers.encode_mpu_region(MPU_config, 0, 0, 4 * 1024 * 1024 * 1024, 'RAM-RO', [0, 7]) mpu_helpers.encode_mpu_region(MPU_config, 1, FLASH_ADDR, flash_pow_size, 'FLASH-XR') #mpu_helpers.encode_mpu_region(MPU_config,2,RAM_ADDR,ram_pow_size,'RAM-RW') stack_pwr_2 = ld_helpers.next_power_2( size_data[DEFAULT_STACK_REGION]['size']) stack_addr = size_data[DEFAULT_STACK_REGION]['addr'] # print "Stack Base Addr 0x%08x" % stack_addr mpu_helpers.encode_mpu_region(MPU_config, 2, stack_addr, stack_pwr_2, 'RAM-RW')
def get_ram_usage(sections, base_addr=0x20000000): size = 0 frag_loss = 0 for key, value in sections.items(): if value['addr'] & base_addr != 0: if key == '.stack' or key == "._user_heap_stack": continue # Stack and heap are measured dynamically if key.startswith(".DATA_REGION"): p2size = next_power_2(value['size']) frag_loss += p2size - value['size'] size += p2size else: size += value['size'] return size, frag_loss
def create_ram_linker_string(ram_sorted_sections): ram_regions = {} hexbox_data = ld_helpers.get_hexbox_rt_data_region() str_list = [] str_list.extend(hexbox_data) last_ram_addr = RAM_ADDR + RAM_SIZE for section in ram_sorted_sections: name = section[0] size = ld_helpers.next_power_2(section[1]) last_ram_addr = last_ram_addr - size addr = last_ram_addr ram_regions[name] = {'addr': addr, 'size': size} str_list.extend(ld_helpers.set_ram_sections(name, addr, size)) data_str = "\n".join(str_list) return data_str, ram_regions
def get_flash_usage(sections, base_addr=0x08000000): size = 0 frag_loss = 0 code_size = 0 for key, value in sections.items(): if value['addr'] & base_addr != 0: if key == '.text' or key == '.rodata' or key == '.isr_vector': size += value['size'] else: p2size = next_power_2(value['size']) frag_loss += p2size - value['size'] size += p2size if not (key == '.rodata'): code_size += value['size'] return size, frag_loss, code_size
def create_flash_linker_string(flash_sorted_sections): ''' Creates the linker string for all the flash regions. Also returns a dictionary of the linker sections, with their start addr and sizes ''' flash_regions = {} str_list = [] hexbox_code = ld_helpers.get_hexbox_rt_code_region() str_list.extend(hexbox_code) last_flash_addr = FLASH_ADDR + FLASH_SIZE for section in flash_sorted_sections: name = section[0] size = ld_helpers.next_power_2(section[1]) last_flash_addr = last_flash_addr - size addr = last_flash_addr flash_regions[name] = {'addr': addr, 'size': size} str_list.extend(ld_helpers.set_code_sections(name, addr, size)) text_str = "\n".join(str_list) return text_str, flash_regions
def get_sorted_sections(size_data): hexbox_flash_sections = {} hexbox_ram_sections = {} for name, data in size_data.items(): addr = data['addr'] aligned_size = ld_helpers.next_power_2(data['size']) if addr >= FLASH_ADDR and addr < (FLASH_ADDR + FLASH_SIZE): if name not in DEFAULT_FLASH_SECTIONS: hexbox_flash_sections[name] = aligned_size elif addr >= RAM_ADDR and addr < (RAM_ADDR + RAM_SIZE): if name not in DEFAULT_RAM_SECTIONS: hexbox_ram_sections[name] = aligned_size flash_sorted_sections = sorted(hexbox_flash_sections.items(), key=operator.itemgetter(1), reverse=True) ram_sorted_sections = sorted(hexbox_ram_sections.items(), key=operator.itemgetter(1), reverse=True) return (flash_sorted_sections, ram_sorted_sections)
help="Policy file used to derive the permissions for each region") parser.add_argument( '-f', '--final_policy', dest='final_policy', required=True, help="Copy of Policy file with the permissions specified") args = parser.parse_args() size_data = get_section_sizes(args.object_filename) # print size_data default_ram_size = get_default_ram_sections(size_data) # print default_ram_size default_flash_size = get_default_flash_sections(size_data) flash_pow_size = ld_helpers.next_power_2(default_flash_size) ram_pow_size = ld_helpers.next_power_2(default_ram_size) # print default_flash_size (flash_sorted_sections, ram_sorted_sections) = get_sorted_sections(size_data) # print flash_sorted_sections # print ram_sorted_sections text_str, flash_regions = create_flash_linker_string(flash_sorted_sections) data_str, ram_regions = create_ram_linker_string(ram_sorted_sections) ld_helpers.write_linker(args.template, args.ld_script, text_str, data_str) with open(args.policy_file, 'rb') as in_policy: policy = json.load(in_policy) ld_regions = flash_regions.copy()
def write_section_contents(section, fd): for key in sorted(section.keys()): value = section[key] p2size = next_power_2(value['size']) fd.write("%s,0x%08x,%i,%i\n"%(key,value['addr'],value['size'],p2size))