mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 19:03:15 +01:00
CML boolean type compiles into #define and #undefs. This is not useful for capabilities since a value of 0 or 1 can be used automatically for setting or unsetting bits in permission words. Meanwhile using an integer type with 0 - 1 range has a worse usability experience than the boolean Y, N. Also moved parsing of container.template.cml to newer Python argument parsing format.
72 lines
1.7 KiB
Python
Executable File
72 lines
1.7 KiB
Python
Executable File
#! /usr/bin/env python2.6
|
|
# -*- mode: python; coding: utf-8; -*-
|
|
#
|
|
# Codezero -- a microkernel for embedded systems.
|
|
#
|
|
# Copyright © 2009 B Labs Ltd
|
|
#
|
|
import os, sys, shelve, glob
|
|
from os.path import join
|
|
|
|
PROJRELROOT = '../../'
|
|
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
|
|
sys.path.append(os.path.abspath("../"))
|
|
|
|
from config.projpaths import *
|
|
from config.configuration import *
|
|
|
|
containers_menu = \
|
|
'''
|
|
menu containers_menu
|
|
'''
|
|
|
|
containers_constraint = \
|
|
'''
|
|
unless CONTAINERS > %d suppress cont%d_menu
|
|
'''
|
|
|
|
containers_default = \
|
|
'''
|
|
default CONTAINERS from %d
|
|
'''
|
|
|
|
def add_container_constraint(cid):
|
|
cml_string = ""
|
|
if cid == 0:
|
|
return ""
|
|
cml_string = containers_constraint % (cid, cid)
|
|
return cml_string
|
|
|
|
def generate_container_cml(arch, ncont):
|
|
fbody = ""
|
|
with open(join(CML2_CONFIG_SRCDIR, arch + '.cml')) as in_cml:
|
|
fbody += in_cml.read()
|
|
|
|
# Add container visibility constraint
|
|
for cont in range(ncont):
|
|
fbody += add_container_constraint(cont)
|
|
|
|
# Add number of default containers
|
|
fbody += containers_default % ncont
|
|
|
|
# Generate the containers menu with as many entries as containers
|
|
fbody += containers_menu
|
|
for cont in range(ncont):
|
|
fbody += '\tcont%d_menu\n' % cont
|
|
|
|
# Write each container's rules
|
|
for cont in range(ncont):
|
|
with open(CML2_CONT_DEFFILE, "rU") as contdefs:
|
|
defbody = contdefs.read()
|
|
defbody = defbody.replace("%\n", "%%\n")
|
|
fbody += defbody % { 'cn' : cont }
|
|
|
|
# Write the result to output rules file.
|
|
with open(join(CML2_CONFIG_SRCDIR, "out.cml"), "w+") as out_cml:
|
|
out_cml.write(fbody)
|
|
|
|
if __name__ == "__main__":
|
|
generate_container_cml('arm', 4)
|
|
|