| 1 |
2 |
drasko |
#! /usr/bin/env python2.6
|
| 2 |
|
|
# -*- mode: python; coding: utf-8; -*-
|
| 3 |
|
|
#
|
| 4 |
|
|
# Codezero -- a 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 |
|
|
from tools.pyelf.elfsize import *
|
| 11 |
|
|
from tools.pyelf.elf_section_info import *
|
| 12 |
|
|
|
| 13 |
|
|
PROJRELROOT = '../../'
|
| 14 |
|
|
|
| 15 |
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
|
| 16 |
|
|
sys.path.append(os.path.abspath("../"))
|
| 17 |
|
|
|
| 18 |
|
|
from config.projpaths import *
|
| 19 |
|
|
from config.configuration import *
|
| 20 |
|
|
from scripts.linux.build_linux import *
|
| 21 |
|
|
from scripts.linux.build_rootfs import *
|
| 22 |
|
|
from scripts.linux.build_atags import *
|
| 23 |
|
|
from pack import *
|
| 24 |
|
|
from packall import *
|
| 25 |
|
|
|
| 26 |
|
|
def fill_pager_section_markers(cont, pager_binary):
|
| 27 |
|
|
cont.pager_rw_section_start, cont.pager_rw_section_end, \
|
| 28 |
|
|
cont.pager_rx_section_start, cont.pager_rx_section_end = \
|
| 29 |
|
|
elf_loadable_section_info(join(PROJROOT, pager_binary))
|
| 30 |
|
|
|
| 31 |
|
|
def build_linux_container(config, projpaths, container):
|
| 32 |
|
|
linux_builder = LinuxBuilder(projpaths, container)
|
| 33 |
|
|
linux_builder.build_linux(config)
|
| 34 |
|
|
|
| 35 |
|
|
rootfs_builder = RootfsBuilder(projpaths, container)
|
| 36 |
|
|
rootfs_builder.build_rootfs(config)
|
| 37 |
|
|
atags_builder = AtagsBuilder(projpaths, container)
|
| 38 |
|
|
atags_builder.build_atags(config)
|
| 39 |
|
|
|
| 40 |
|
|
# Calculate and store size of pager
|
| 41 |
|
|
pager_binary = \
|
| 42 |
|
|
join(BUILDDIR, "cont" + str(container.id) +
|
| 43 |
|
|
"/linux/linux-2.6.33/linux.elf")
|
| 44 |
|
|
config.containers[container.id].pager_size = \
|
| 45 |
|
|
conv_hex(elf_binary_size(pager_binary))
|
| 46 |
|
|
|
| 47 |
|
|
fill_pager_section_markers(config.containers[container.id], pager_binary)
|
| 48 |
|
|
|
| 49 |
|
|
linux_container_packer = \
|
| 50 |
|
|
LinuxContainerPacker(container, linux_builder, \
|
| 51 |
|
|
rootfs_builder, atags_builder)
|
| 52 |
|
|
return linux_container_packer.pack_container(config)
|
| 53 |
|
|
|
| 54 |
|
|
def glob_by_walk(arg, dirname, names):
|
| 55 |
|
|
ext, imglist = arg
|
| 56 |
|
|
files = glob.glob(join(dirname, ext))
|
| 57 |
|
|
imglist.extend(files)
|
| 58 |
|
|
|
| 59 |
|
|
def source_to_builddir(srcdir, id):
|
| 60 |
|
|
cont_builddir = \
|
| 61 |
|
|
os.path.relpath(srcdir, \
|
| 62 |
|
|
PROJROOT).replace("conts", \
|
| 63 |
|
|
"cont" + str(id))
|
| 64 |
|
|
return join(BUILDDIR, cont_builddir)
|
| 65 |
|
|
|
| 66 |
|
|
# We simply use SCons to figure all this out from container.id
|
| 67 |
|
|
# This is very similar to examples container builder:
|
| 68 |
|
|
# In fact this notion may become a standard convention for
|
| 69 |
|
|
# calling specific bare containers
|
| 70 |
|
|
def build_posix_container(config, projpaths, container):
|
| 71 |
|
|
images = []
|
| 72 |
|
|
cwd = os.getcwd()
|
| 73 |
|
|
os.chdir(POSIXDIR)
|
| 74 |
|
|
print '\nBuilding Posix Container %d...' % container.id
|
| 75 |
|
|
scons_cmd = 'scons ' + 'cont=' + str(container.id)
|
| 76 |
|
|
#print "Issuing scons command: %s" % scons_cmd
|
| 77 |
|
|
os.system(scons_cmd)
|
| 78 |
|
|
builddir = source_to_builddir(POSIXDIR, container.id)
|
| 79 |
|
|
os.path.walk(builddir, glob_by_walk, ['*.elf', images])
|
| 80 |
|
|
|
| 81 |
|
|
# Calculate and store size of pager
|
| 82 |
|
|
pager_binary = join(BUILDDIR,
|
| 83 |
|
|
"cont" + str(container.id) + "/posix/mm0/mm0.elf")
|
| 84 |
|
|
config.containers[container.id].pager_size = \
|
| 85 |
|
|
conv_hex(elf_binary_size(pager_binary))
|
| 86 |
|
|
|
| 87 |
|
|
print 'Find markers for ' + pager_binary
|
| 88 |
|
|
fill_pager_section_markers(config.containers[container.id], pager_binary)
|
| 89 |
|
|
|
| 90 |
|
|
container_packer = DefaultContainerPacker(container, images)
|
| 91 |
|
|
return container_packer.pack_container(config)
|
| 92 |
|
|
|
| 93 |
|
|
# This simply calls SCons on a given container, and collects
|
| 94 |
|
|
# all images with .elf extension, instead of using whole classes
|
| 95 |
|
|
# for building and packing.
|
| 96 |
|
|
def build_default_container(config, projpaths, container):
|
| 97 |
|
|
images = []
|
| 98 |
|
|
cwd = os.getcwd()
|
| 99 |
|
|
projdir = join(join(PROJROOT, 'conts'), container.name)
|
| 100 |
|
|
os.chdir(projdir)
|
| 101 |
|
|
os.system("scons")
|
| 102 |
|
|
os.path.walk(projdir, glob_by_walk, ['*.elf', images])
|
| 103 |
|
|
|
| 104 |
|
|
# Calculate and store size of pager
|
| 105 |
|
|
pager_binary = join(PROJROOT, "conts/" + container.name + "/main.elf")
|
| 106 |
|
|
config.containers[container.id].pager_size = \
|
| 107 |
|
|
conv_hex(elf_binary_size(pager_binary))
|
| 108 |
|
|
|
| 109 |
|
|
fill_pager_section_markers(config.containers[container.id], pager_binary)
|
| 110 |
|
|
|
| 111 |
|
|
container_packer = DefaultContainerPacker(container, images)
|
| 112 |
|
|
return container_packer.pack_container(config)
|
| 113 |
|
|
|
| 114 |
|
|
def build_all_containers():
|
| 115 |
|
|
config = configuration_retrieve()
|
| 116 |
|
|
cont_images = []
|
| 117 |
|
|
for container in config.containers:
|
| 118 |
|
|
if container.type == 'linux':
|
| 119 |
|
|
pass
|
| 120 |
|
|
cont_images.append(build_linux_container(config, projpaths, container))
|
| 121 |
|
|
elif container.type == 'baremetal':
|
| 122 |
|
|
cont_images.append(build_default_container(config, projpaths, container))
|
| 123 |
|
|
elif container.type == 'posix':
|
| 124 |
|
|
cont_images.append(build_posix_container(config, projpaths, container))
|
| 125 |
|
|
else:
|
| 126 |
|
|
print "Error: Don't know how to build " + \
|
| 127 |
|
|
"container of type: %s" % (container.type)
|
| 128 |
|
|
exit(1)
|
| 129 |
|
|
configuration_save(config)
|
| 130 |
|
|
all_cont_packer = AllContainerPacker(cont_images, config.containers)
|
| 131 |
|
|
|
| 132 |
|
|
return all_cont_packer.pack_all(config)
|
| 133 |
|
|
|
| 134 |
|
|
if __name__ == "__main__":
|
| 135 |
|
|
build_all_containers()
|
| 136 |
|
|
|