Added untracked scripts. Added script-location relative module import

This commit is contained in:
Bahadir Balban
2009-09-17 11:28:43 +03:00
parent b2531dc725
commit 6b899ebf15
8 changed files with 270 additions and 2 deletions

View File

52
scripts/conts/containers.py Executable file
View File

@@ -0,0 +1,52 @@
#! /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 *
from scripts.linux.build_linux import *
from scripts.linux.build_rootfs import *
from pack import *
from packall import *
def build_container(container):
if container.type == "linux":
linux_builder = LinuxBuilder(projpaths, container)
linux_builder.build_linux()
rootfs_builder = RootfsBuilder(projpaths, container)
rootfs_builder.build_rootfs()
linux_container_packer = LinuxContainerPacker(container, \
linux_builder, \
rootfs_builder)
return linux_container_packer.pack_container()
else:
print "Error: Don't know how to build " + \
"container of type: %s" % (container.type)
Exit(1)
def main():
container_images = []
config = configuration_retrieve()
for container in config.containers:
container_images.append(build_container(container))
all_cont_packer = AllContainerPacker(container_images, config.containers)
all_cont_packer.pack_all()
if __name__ == "__main__":
main()

113
scripts/conts/pack.py Executable file
View File

@@ -0,0 +1,113 @@
#! /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 *
container_assembler_body = \
'''
.align 4
.section .img.%d
.incbin "%s"
'''
container_lds_start = \
'''/*
* Autogenerated linker script that embeds each image to be
* placed in a single container.
*
* Copyright (C) 2009 B Labs
*/
SECTIONS
{'''
container_lds_body = \
'''
.img.%d : { *(.img.%d) }'''
container_lds_end = \
'''
}
'''
# Create container build base as:
# conts/linux -> build/cont[0-9]
def source_to_builddir(srcdir, id):
cont_builddir = \
os.path.relpath(srcdir, \
PROJROOT).replace("conts", \
"cont" + str(id))
return join(BUILDDIR, cont_builddir)
class LinuxContainerPacker:
def __init__(self, container, linux_builder, rootfs_builder):
# Here, we simply attempt to get PROJROOT/conts as
# PROJROOT/build/cont[0-9]
self.CONTAINER_BUILDDIR_BASE = \
source_to_builddir(join(PROJROOT,'conts'), container.id)
self.container_lds_out = join(self.CONTAINER_BUILDDIR_BASE, \
'container.lds')
self.container_S_out = join(self.CONTAINER_BUILDDIR_BASE, 'container.S')
self.container_elf_out = join(self.CONTAINER_BUILDDIR_BASE, \
'container' + str(container.id) + '.elf')
self.kernel_image_in = linux_builder.kernel_image
self.rootfs_elf_in = rootfs_builder.rootfs_elf_out
def generate_container_assembler(self, source):
with open(self.container_S_out, 'w+') as f:
file_body = ""
img_i = 0
for img in source:
file_body += container_assembler_body % (img_i, img)
img_i += 1
f.write(file_body)
f.close()
def generate_container_lds(self, source):
with open(self.container_lds_out, 'w+') as f:
img_i = 0
file_body = container_lds_start
for img in source:
file_body += container_lds_body % (img_i, img_i)
img_i += 1
file_body += container_lds_end
f.write(file_body)
f.close()
def pack_container(self):
self.generate_container_lds([self.kernel_image_in, \
self.rootfs_elf_in])
self.generate_container_assembler([self.kernel_image_in, \
self.rootfs_elf_in])
os.system("arm-none-linux-gnueabi-gcc " + "-nostdlib -o %s -T%s %s" \
% (self.container_elf_out, \
self.container_lds_out,
self.container_S_out))
# Final file is returned so that the final packer needn't
# get the packer object for this information
return self.container_elf_out
def clean(self):
if os.path.exists(self.container_elf_out):
shutil.rmtree(self.container_elf_out)
if os.path.exists(self.container_lds_out):
shutil.rmtree(self.container_lds_out)
if os.path.exists(self.container_S_out):
shutil.rmtree(self.container_S_out)

103
scripts/conts/packall.py Executable file
View File

@@ -0,0 +1,103 @@
#! /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
from os.path import join
PROJRELROOT = '../../'
SCRIPTROOT = os.path.abspath(os.path.dirname("."))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
from config.projpaths import *
from config.configuration import *
containers_assembler_body = \
'''
.align 4
.section .cont.%d
.incbin "%s"
'''
containers_lds_start = \
'''/*
* Autogenerated linker script that packs all containers
* in a single image.
*
* Copyright (C) 2009 B Labs Ltd.
*/
SECTIONS
{'''
containers_lds_body = \
'''
.cont.%d : { *(.cont.%d) }'''
containers_lds_end = \
'''
}
'''
class AllContainerPacker:
def __init__(self, image_list, container_list):
self.cont_images_in = image_list
self.cont_images_in.sort()
self.containers = container_list
self.CONTAINERS_BUILDDIR = join(PROJROOT, 'build/conts')
self.containers_lds_out = join(self.CONTAINERS_BUILDDIR, \
'containers.lds')
self.containers_S_out = join(self.CONTAINERS_BUILDDIR, 'containers.S')
self.containers_elf_out = join(self.CONTAINERS_BUILDDIR, \
'containers.elf')
def generate_container_S(self, target_path):
with open(target_path, 'w+') as f:
file_body = ""
img_i = 0
for img in self.cont_images_in:
print img
file_body += containers_assembler_body % (img_i, img)
img_i += 1
f.write(file_body)
def generate_container_lds(self, target_path):
with open(target_path, 'w+') as f:
img_i = 0
file_body = containers_lds_start
for img in self.cont_images_in:
file_body += containers_lds_body % (img_i, img_i)
img_i += 1
file_body += containers_lds_end
f.write(file_body)
def pack_all(self):
self.generate_container_lds(self.containers_lds_out)
self.generate_container_S(self.containers_S_out)
os.system("arm-none-linux-gnueabi-gcc " + "-nostdlib -o %s -T%s %s" \
% (self.containers_elf_out, \
self.containers_lds_out,
self.containers_S_out))
# oldwd = os.getcwd()
# os.chdir(PROJROOT)
# os.system("scons -f SConstruct.loader")
# os.chdir(oldwd)
def clean(self):
if os.path.exists(self.containers_elf_out):
shutil.rmtree(self.containers_elf_out)
if os.path.exists(self.containers_lds_out):
shutil.rmtree(self.containers_lds_out)
if os.path.exists(self.containers_S_out):
shutil.rmtree(self.containers_S_out)
if __name__ == "__main__":
all_cont_packer = AllContainerPacker([], [])

View File

View File

@@ -11,7 +11,7 @@ from os.path import join
PROJRELROOT = '../../'
SCRIPTROOT = os.path.abspath(os.path.dirname("."))
sys.path.append(os.path.abspath(PROJRELROOT))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
from config.projpaths import *
from config.configuration import *

View File

@@ -10,7 +10,7 @@ from os.path import join
PROJRELROOT = "../.."
SCRIPTROOT = os.path.abspath(os.path.dirname("."))
sys.path.append(os.path.abspath(PROJRELROOT))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
from config.projpaths import *
from config.configuration import *

View File