1 |
2 |
drasko |
#! /usr/bin/env python2.6
|
2 |
|
|
# -*- mode: python; coding: utf-8; -*-
|
3 |
|
|
#
|
4 |
|
|
# Codezero -- Virtualization microkernel for embedded systems.
|
5 |
|
|
#
|
6 |
|
|
# Copyright © 2009 B Labs Ltd
|
7 |
|
|
#
|
8 |
|
|
import os, sys, shelve, glob
|
9 |
|
|
from os.path import join
|
10 |
|
|
|
11 |
|
|
PROJRELROOT = '../../'
|
12 |
|
|
|
13 |
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
|
14 |
|
|
sys.path.append(os.path.abspath("../"))
|
15 |
|
|
|
16 |
|
|
SCRIPTROOT = os.path.abspath(os.path.dirname(__file__))
|
17 |
|
|
|
18 |
|
|
from config.projpaths import *
|
19 |
|
|
from config.configuration import *
|
20 |
|
|
from config.lib import *
|
21 |
|
|
|
22 |
|
|
class BaremetalContGenerator:
|
23 |
|
|
def __init__(self):
|
24 |
|
|
self.CONT_SRC_DIR = '' # Set when container is selected
|
25 |
|
|
self.BAREMETAL_SRC_BASEDIR = join(PROJROOT, 'conts')
|
26 |
|
|
self.BAREMETAL_PROJ_SRC_DIR = join(PROJROOT, 'conts/baremetal')
|
27 |
|
|
|
28 |
|
|
self.main_builder_name = 'build.py'
|
29 |
|
|
self.main_configurator_name = 'configure.py'
|
30 |
|
|
self.mailing_list_url = 'http://lists.l4dev.org/mailman/listinfo/codezero-devel'
|
31 |
|
|
|
32 |
|
|
self.build_script_in = join(SCRIPTROOT, 'files/SConstruct.in')
|
33 |
|
|
self.build_readme_in = join(SCRIPTROOT, 'files/build.readme.in')
|
34 |
|
|
self.build_desc_in = join(SCRIPTROOT, 'files/container.desc.in')
|
35 |
|
|
self.linker_lds_in = join(SCRIPTROOT, 'files/linker.lds.in')
|
36 |
|
|
self.container_h_in = join(SCRIPTROOT, 'files/container.h.in')
|
37 |
|
|
|
38 |
|
|
self.build_script_name = 'SConstruct'
|
39 |
|
|
self.build_readme_name = 'build.readme'
|
40 |
|
|
self.build_desc_name = '.container'
|
41 |
|
|
self.linker_lds_name = 'linker.lds'
|
42 |
|
|
self.container_h_name = 'container.h'
|
43 |
|
|
|
44 |
|
|
self.container_h_out = None
|
45 |
|
|
self.build_script_out = None
|
46 |
|
|
self.build_readme_out = None
|
47 |
|
|
self.build_desc_out = None
|
48 |
|
|
self.src_main_out = None
|
49 |
|
|
|
50 |
|
|
def create_baremetal_srctree(self, config, cont):
|
51 |
|
|
# First, create the base project directory and sources
|
52 |
|
|
shutil.copytree(join(self.BAREMETAL_PROJ_SRC_DIR, cont.dirname), self.CONT_SRC_DIR)
|
53 |
|
|
|
54 |
|
|
def copy_baremetal_build_desc(self, config, cont):
|
55 |
|
|
id_header = '[Container ID]\n'
|
56 |
|
|
type_header = '\n[Container Type]\n'
|
57 |
|
|
name_header = '\n[Container Name]\n'
|
58 |
|
|
pager_lma_header = '\n[Container Pager LMA]\n'
|
59 |
|
|
pager_vma_header = '\n[Container Pager VMA]\n'
|
60 |
|
|
pager_virtmem_header = '\n[Container Virtmem Region %s]\n'
|
61 |
|
|
pager_physmem_header = '\n[Container Physmem Region %s]\n'
|
62 |
|
|
|
63 |
|
|
with open(self.build_desc_out, 'w+') as fout:
|
64 |
|
|
fout.write(id_header)
|
65 |
|
|
fout.write('\t' + str(cont.id) + '\n')
|
66 |
|
|
fout.write(type_header)
|
67 |
|
|
fout.write('\t' + cont.type + '\n')
|
68 |
|
|
fout.write(name_header)
|
69 |
|
|
fout.write('\t' + cont.name + '\n')
|
70 |
|
|
fout.write(pager_lma_header)
|
71 |
|
|
fout.write('\t' + conv_hex(cont.pager_lma) + '\n')
|
72 |
|
|
fout.write(pager_vma_header)
|
73 |
|
|
fout.write('\t' + conv_hex(cont.pager_vma) + '\n')
|
74 |
|
|
for ireg in range(cont.virt_regions):
|
75 |
|
|
fout.write(pager_virtmem_header % ireg)
|
76 |
|
|
fout.write('\t' + cont.virtmem["START"][ireg] + ' - ' + cont.virtmem["END"][ireg] + '\n')
|
77 |
|
|
for ireg in range(cont.phys_regions):
|
78 |
|
|
fout.write(pager_physmem_header % ireg)
|
79 |
|
|
fout.write('\t' + cont.physmem["START"][ireg] + ' - ' + cont.physmem["END"][ireg] + '\n')
|
80 |
|
|
|
81 |
|
|
def copy_baremetal_build_readme(self, config, cont):
|
82 |
|
|
with open(self.build_readme_in) as fin:
|
83 |
|
|
str = fin.read()
|
84 |
|
|
with open(self.build_readme_out, 'w+') as fout:
|
85 |
|
|
# Make any manipulations here
|
86 |
|
|
fout.write(str % (self.mailing_list_url, \
|
87 |
|
|
cont.name, \
|
88 |
|
|
self.build_desc_name, \
|
89 |
|
|
self.main_builder_name, \
|
90 |
|
|
self.main_configurator_name, \
|
91 |
|
|
self.main_configurator_name))
|
92 |
|
|
|
93 |
|
|
def copy_baremetal_container_h(self, config, cont):
|
94 |
|
|
with open(self.container_h_in) as fin:
|
95 |
|
|
str = fin.read()
|
96 |
|
|
with open(self.container_h_out, 'w+') as fout:
|
97 |
|
|
# Make any manipulations here
|
98 |
|
|
fout.write(str % (cont.name, cont.id, cont.id))
|
99 |
|
|
|
100 |
|
|
def create_baremetal_sources(self, config, cont):
|
101 |
|
|
self.create_baremetal_srctree(config, cont)
|
102 |
|
|
self.copy_baremetal_build_readme(config, cont)
|
103 |
|
|
self.copy_baremetal_build_desc(config, cont)
|
104 |
|
|
self.generate_linker_script(config, cont)
|
105 |
|
|
self.copy_baremetal_container_h(config, cont)
|
106 |
|
|
|
107 |
|
|
def update_configuration(self, config, cont):
|
108 |
|
|
self.copy_baremetal_build_desc(config, cont)
|
109 |
|
|
self.generate_linker_script(config, cont)
|
110 |
|
|
self.copy_baremetal_container_h(config, cont)
|
111 |
|
|
|
112 |
|
|
def check_create_baremetal_sources(self, config):
|
113 |
|
|
for cont in config.containers:
|
114 |
|
|
if cont.type == "baremetal":
|
115 |
|
|
# Determine container directory name.
|
116 |
|
|
self.CONT_SRC_DIR = join(self.BAREMETAL_SRC_BASEDIR, cont.name.lower())
|
117 |
|
|
self.build_readme_out = join(self.CONT_SRC_DIR, self.build_readme_name)
|
118 |
|
|
self.build_desc_out = join(self.CONT_SRC_DIR, self.build_desc_name)
|
119 |
|
|
self.linker_lds_out = join(join(self.CONT_SRC_DIR, 'include'), \
|
120 |
|
|
self.linker_lds_name)
|
121 |
|
|
self.container_h_out = join(join(self.CONT_SRC_DIR, 'include'), \
|
122 |
|
|
self.container_h_name)
|
123 |
|
|
|
124 |
|
|
if not os.path.exists(join(self.BAREMETAL_SRC_BASEDIR, cont.name)):
|
125 |
|
|
self.create_baremetal_sources(config, cont)
|
126 |
|
|
else:
|
127 |
|
|
# Don't create new sources but update configuration
|
128 |
|
|
self.update_configuration(config, cont)
|
129 |
|
|
|
130 |
|
|
def generate_linker_script(self, config, cont):
|
131 |
|
|
with open(self.linker_lds_in) as fin:
|
132 |
|
|
str = fin.read()
|
133 |
|
|
with open(self.linker_lds_out, 'w+') as fout:
|
134 |
|
|
fout.write(str % (conv_hex(cont.pager_vma), \
|
135 |
|
|
conv_hex(cont.pager_lma)))
|
136 |
|
|
|
137 |
|
|
def baremetal_container_generate(self, config):
|
138 |
|
|
self.check_create_baremetal_sources(config)
|
139 |
|
|
|
140 |
|
|
if __name__ == "__main__":
|
141 |
|
|
config = configuration_retrieve()
|
142 |
|
|
config.config_print()
|
143 |
|
|
baremetal_cont = BaremetalContGenerator()
|
144 |
|
|
baremetal_cont.baremetal_container_generate(config)
|
145 |
|
|
|