mirror of
https://github.com/seL4/seL4.git
synced 2026-03-27 10:29:57 +00:00
platform_gen: only generate regions that are used
Right now the `platform_gen.json` and `platform_gen.yaml` files contain regions that are not actually used by the kernel. This is fine for `platform_gen.h` because they are guarded by #ifdefs with kernel config defines but the same approach does not work for YAML and JSON. So, this patch changes the Python scripts that generate this files so that they only generate the regions that actually end up being used. Signed-off-by: Ivan-Velickovic <i.velickovic@unsw.edu.au>
This commit is contained in:
committed by
Gerwin Klein
parent
7f6d5c72aa
commit
1cbaeb97f0
@@ -131,7 +131,7 @@ static const p_region_t BOOT_RODATA avail_p_regs[] = {
|
||||
'''
|
||||
|
||||
|
||||
def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml) -> (List, Dict):
|
||||
def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml, kernel_config_dict: Dict[str, str]) -> (List, Dict):
|
||||
'''
|
||||
Given a device tree and a set of rules, returns a tuple (groups, offsets).
|
||||
|
||||
@@ -208,12 +208,12 @@ def create_c_header_file(config, kernel_irqs: List, kernel_macros: Dict,
|
||||
outputStream.write(data)
|
||||
|
||||
|
||||
def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, args: argparse.Namespace):
|
||||
def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, kernel_config_dict, args: argparse.Namespace):
|
||||
if not args.header_out:
|
||||
raise ValueError('You need to specify a header-out to use c header output')
|
||||
|
||||
physical_memory, reserved, physBase = hardware.utils.memory.get_physical_memory(tree, config)
|
||||
kernel_regions, kernel_macros = get_kernel_devices(tree, hw_yaml)
|
||||
kernel_regions, kernel_macros = get_kernel_devices(tree, hw_yaml, kernel_config_dict)
|
||||
|
||||
create_c_header_file(
|
||||
config,
|
||||
|
||||
@@ -9,10 +9,11 @@ import argparse
|
||||
from hardware.config import Config
|
||||
from hardware.fdt import FdtParser
|
||||
from hardware.utils.rule import HardwareYaml
|
||||
from typing import Dict
|
||||
|
||||
|
||||
def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config,
|
||||
args: argparse.Namespace):
|
||||
kernel_config_dict: Dict[str, str], args: argparse.Namespace):
|
||||
if not args.compat_strings_out:
|
||||
raise ValueError('You need to specify a compat-strings-out to use compat strings output')
|
||||
chosen = tree.get_kernel_devices()
|
||||
|
||||
@@ -12,7 +12,7 @@ import logging
|
||||
import pyfdt.pyfdt
|
||||
|
||||
from jinja2 import Environment, BaseLoader
|
||||
from typing import List
|
||||
from typing import Dict, List
|
||||
|
||||
from hardware import config, device, fdt
|
||||
from hardware.utils import cpu, memory, rule
|
||||
@@ -140,7 +140,7 @@ def get_elfloader_cpus(tree: fdt.FdtParser, devices: List[device.WrappedNode]) -
|
||||
return sorted(cpu_info, key=lambda a: a['cpuid'])
|
||||
|
||||
|
||||
def run(tree: fdt.FdtParser, hardware: rule.HardwareYaml, config: config.Config, args: argparse.Namespace):
|
||||
def run(tree: fdt.FdtParser, hardware: rule.HardwareYaml, config: config.Config, kernel_config_dict: Dict[str, str], args: argparse.Namespace):
|
||||
devices = tree.get_elfloader_devices()
|
||||
cpu_info = get_elfloader_cpus(tree, devices)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from typing import List
|
||||
from typing import Dict, List
|
||||
import hardware
|
||||
from hardware.config import Config
|
||||
from hardware.fdt import FdtParser
|
||||
@@ -35,24 +35,29 @@ def create_json_file(dev_mem, phys_mem, output_stream):
|
||||
json.dump(json_obj, output_stream)
|
||||
|
||||
|
||||
def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml):
|
||||
def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml, kernel_config_dict: Dict[str, str]):
|
||||
kernel_devices = tree.get_kernel_devices()
|
||||
|
||||
groups = []
|
||||
for dev in kernel_devices:
|
||||
rule = hw_yaml.get_rule(dev)
|
||||
groups += rule.get_regions(dev)
|
||||
new_regions = rule.get_regions(dev)
|
||||
for reg in new_regions:
|
||||
if reg.macro in kernel_config_dict:
|
||||
if kernel_config_dict[reg.macro] != "ON":
|
||||
continue
|
||||
groups.append(reg)
|
||||
|
||||
return groups
|
||||
|
||||
|
||||
def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config,
|
||||
args: argparse.Namespace):
|
||||
kernel_config_dict, args: argparse.Namespace):
|
||||
if not args.json_out:
|
||||
raise ValueError('you need to provide a json-out to use the JSON output method')
|
||||
|
||||
phys_mem, reserved, _ = hardware.utils.memory.get_physical_memory(tree, config)
|
||||
kernel_devs = get_kernel_devices(tree, hw_yaml)
|
||||
kernel_devs = get_kernel_devices(tree, hw_yaml, kernel_config_dict)
|
||||
dev_mem = hardware.utils.memory.get_addrspace_exclude(
|
||||
list(reserved) + phys_mem + kernel_devs, config)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import argparse
|
||||
import yaml
|
||||
from typing import List
|
||||
from typing import Dict, List
|
||||
import hardware
|
||||
from hardware.config import Config
|
||||
from hardware.fdt import FdtParser
|
||||
@@ -40,24 +40,29 @@ def create_yaml_file(dev_mem, phys_mem, outputStream):
|
||||
yaml.dump(yaml_obj, outputStream)
|
||||
|
||||
|
||||
def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml):
|
||||
def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml, kernel_config_dict: Dict[str, str]):
|
||||
kernel_devices = tree.get_kernel_devices()
|
||||
|
||||
groups = []
|
||||
for dev in kernel_devices:
|
||||
rule = hw_yaml.get_rule(dev)
|
||||
groups += rule.get_regions(dev)
|
||||
new_regions = rule.get_regions(dev)
|
||||
for reg in new_regions:
|
||||
if reg.macro in kernel_config_dict:
|
||||
if kernel_config_dict[reg.macro] != "ON":
|
||||
continue
|
||||
groups.append(reg)
|
||||
|
||||
return groups
|
||||
|
||||
|
||||
def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config,
|
||||
args: argparse.Namespace):
|
||||
kernel_config_dict, args: argparse.Namespace):
|
||||
if not args.yaml_out:
|
||||
raise ValueError('you need to provide a yaml-out to use the yaml output method')
|
||||
|
||||
phys_mem, reserved, _ = hardware.utils.memory.get_physical_memory(tree, config)
|
||||
kernel_devs = get_kernel_devices(tree, hw_yaml)
|
||||
kernel_devs = get_kernel_devices(tree, hw_yaml, kernel_config_dict)
|
||||
dev_mem = hardware.utils.memory.get_addrspace_exclude(
|
||||
list(reserved) + phys_mem + kernel_devs, config)
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ def main(args: argparse.Namespace):
|
||||
arg_dict = vars(args)
|
||||
for t in sorted(OUTPUTS.keys()):
|
||||
if arg_dict[t]:
|
||||
OUTPUTS[t].run(parsed_dt, hw_yaml, cfg, args)
|
||||
OUTPUTS[t].run(parsed_dt, hw_yaml, cfg, kernel_config_dict, args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -75,6 +75,8 @@ if __name__ == '__main__':
|
||||
required=True, type=argparse.FileType('r'))
|
||||
parser.add_argument('--sel4arch', help='seL4 architecture to generate for',
|
||||
required=True)
|
||||
parser.add_argument('--kernel-config-flags',
|
||||
help='List of kernel config params', action='append', nargs='+')
|
||||
parser.add_argument('--addrspace-max',
|
||||
help='maximum address that is available as device untyped', type=int, default=32)
|
||||
|
||||
@@ -85,6 +87,12 @@ if __name__ == '__main__':
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
kernel_config_dict = dict()
|
||||
if args.kernel_config_flags:
|
||||
for option in sum(args.kernel_config_flags, []):
|
||||
name, val = option.split('=')
|
||||
kernel_config_dict[name] = val
|
||||
|
||||
if args.enable_profiling:
|
||||
import cProfile
|
||||
cProfile.run('main(args)', sort='cumtime')
|
||||
|
||||
Reference in New Issue
Block a user