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, shutil
|
9 |
|
|
from os.path import join
|
10 |
|
|
|
11 |
|
|
PROJRELROOT = "../.."
|
12 |
|
|
SCRIPTROOT = os.path.abspath(os.path.dirname("."))
|
13 |
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
|
14 |
|
|
|
15 |
|
|
from config.projpaths import *
|
16 |
|
|
from config.configuration import *
|
17 |
|
|
|
18 |
|
|
# Create linux kernel build directory path as:
|
19 |
|
|
# conts/linux -> build/cont[0-9]/linux
|
20 |
|
|
def source_to_builddir(srcdir, id):
|
21 |
|
|
cont_builddir = \
|
22 |
|
|
os.path.relpath(srcdir, \
|
23 |
|
|
PROJROOT).replace("conts", \
|
24 |
|
|
"cont" + str(id))
|
25 |
|
|
return join(BUILDDIR, cont_builddir)
|
26 |
|
|
|
27 |
|
|
class AtagsBuilder:
|
28 |
|
|
|
29 |
|
|
def __init__(self, pathdict, container):
|
30 |
|
|
self.LINUX_ATAGSDIR = pathdict["LINUX_ATAGSDIR"]
|
31 |
|
|
self.LINUX_ATAGS_BUILDDIR = \
|
32 |
|
|
source_to_builddir(self.LINUX_ATAGSDIR, container.id)
|
33 |
|
|
|
34 |
|
|
self.atags_lds_in = join(self.LINUX_ATAGSDIR, "atags.lds.in")
|
35 |
|
|
self.atags_lds_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.lds")
|
36 |
|
|
|
37 |
|
|
self.atags_elf_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.elf")
|
38 |
|
|
|
39 |
|
|
self.atags_S_in = join(self.LINUX_ATAGSDIR, "atags.S.in")
|
40 |
|
|
self.atags_S_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.S")
|
41 |
|
|
|
42 |
|
|
self.atags_c_in = join(self.LINUX_ATAGSDIR, "atags.c.in")
|
43 |
|
|
self.atags_c_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.c")
|
44 |
|
|
|
45 |
|
|
self.atags_h_in = join(self.LINUX_ATAGSDIR, "atags.h.in")
|
46 |
|
|
self.atags_h_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.h")
|
47 |
|
|
|
48 |
|
|
self.cont_id = container.id
|
49 |
|
|
self.elf_relpath = os.path.relpath(self.atags_elf_out, \
|
50 |
|
|
self.LINUX_ATAGSDIR)
|
51 |
|
|
|
52 |
|
|
def build_atags(self, config):
|
53 |
|
|
print 'Building Atags for linux kenel...'
|
54 |
|
|
# IO files from this build
|
55 |
|
|
os.chdir(LINUX_ATAGSDIR)
|
56 |
|
|
if not os.path.exists(self.LINUX_ATAGS_BUILDDIR):
|
57 |
|
|
os.makedirs(self.LINUX_ATAGS_BUILDDIR)
|
58 |
|
|
|
59 |
|
|
with open(self.atags_S_in, 'r') as input:
|
60 |
|
|
with open(self.atags_S_out, 'w+') as output:
|
61 |
|
|
output.write(input.read() % self.elf_relpath)
|
62 |
|
|
|
63 |
|
|
with open(self.atags_h_out, 'w+') as output:
|
64 |
|
|
with open(self.atags_h_in, 'r') as input:
|
65 |
|
|
output.write(input.read() % {'cn' : self.cont_id})
|
66 |
|
|
|
67 |
|
|
os.system(config.toolchain_userspace + "cpp -I%s -P %s > %s" % \
|
68 |
|
|
(self.LINUX_ATAGS_BUILDDIR, self.atags_lds_in, \
|
69 |
|
|
self.atags_lds_out))
|
70 |
|
|
|
71 |
|
|
with open(self.atags_c_out, 'w+') as output:
|
72 |
|
|
with open(self.atags_c_in, 'r') as input:
|
73 |
|
|
output.write(input.read() % {'cn' : self.cont_id})
|
74 |
|
|
|
75 |
|
|
os.system(config.toolchain_userspace + "gcc " + \
|
76 |
|
|
"-g -ffreestanding -std=gnu99 -Wall -Werror " + \
|
77 |
|
|
"-nostdlib -o %s -T%s %s" % \
|
78 |
|
|
(self.atags_elf_out, self.atags_lds_out, self.atags_c_out))
|
79 |
|
|
print "Done..."
|
80 |
|
|
|
81 |
|
|
def clean(self):
|
82 |
|
|
print 'Cleaning Atags...'
|
83 |
|
|
if os.path.exists(self.LINUX_ATAGS_BUILDDIR):
|
84 |
|
|
shutil.rmtree(self.LINUX_ATAGS_BUILDDIR)
|
85 |
|
|
print 'Done...'
|
86 |
|
|
|
87 |
|
|
if __name__ == "__main__":
|
88 |
|
|
# This is only a default test case
|
89 |
|
|
container = Container()
|
90 |
|
|
container.id = 0
|
91 |
|
|
atags_builder = AtagsBuilder(projpaths, container)
|
92 |
|
|
|
93 |
|
|
if len(sys.argv) == 1:
|
94 |
|
|
atags_builder.build_atags()
|
95 |
|
|
elif "clean" == sys.argv[1]:
|
96 |
|
|
atags_builder.clean()
|
97 |
|
|
else:
|
98 |
|
|
print " Usage: %s [clean]" % (sys.argv[0])
|