OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [scripts/] [linux/] [build_rootfs.py] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 RootfsBuilder:
28
 
29
    def __init__(self, pathdict, container):
30
        self.LINUX_ROOTFSDIR = pathdict["LINUX_ROOTFSDIR"]
31
        self.LINUX_ROOTFS_BUILDDIR = \
32
            source_to_builddir(self.LINUX_ROOTFSDIR, container.id)
33
 
34
        self.rootfs_lds_in = join(self.LINUX_ROOTFSDIR, "rootfs.lds.in")
35
        self.rootfs_lds_out = join(self.LINUX_ROOTFS_BUILDDIR, "rootfs.lds")
36
 
37
        self.rootfs_h_in = join(self.LINUX_ROOTFSDIR, "rootfs.h.in")
38
        self.rootfs_h_out = join(self.LINUX_ROOTFS_BUILDDIR, "rootfs.h")
39
 
40
        self.rootfs_elf_out = join(self.LINUX_ROOTFS_BUILDDIR, "rootfs.elf")
41
        self.cont_id = container.id
42
 
43
    def build_rootfs(self, config):
44
        print 'Building the root filesystem...'
45
        # IO files from this build
46
        os.chdir(LINUX_ROOTFSDIR)
47
        if not os.path.exists(self.LINUX_ROOTFS_BUILDDIR):
48
            os.makedirs(self.LINUX_ROOTFS_BUILDDIR)
49
 
50
        with open(self.rootfs_h_out, 'w+') as output:
51
            with open(self.rootfs_h_in, 'r') as input:
52
                output.write(input.read() % {'cn' : self.cont_id})
53
 
54
        os.system(config.toolchain_userspace + "cpp -I%s -P %s > %s" % \
55
                  (self.LINUX_ROOTFS_BUILDDIR, self.rootfs_lds_in, \
56
                   self.rootfs_lds_out))
57
        os.system(config.toolchain_userspace + "gcc " + \
58
                  "-nostdlib -o %s -T%s rootfs.S" % (self.rootfs_elf_out, \
59
                                                     self.rootfs_lds_out))
60
        print "Done..."
61
 
62
    def clean(self):
63
        print 'Cleaning the built root filesystem...'
64
        if os.path.exists(self.LINUX_ROOTFS_BUILDDIR):
65
            shutil.rmtree(self.LINUX_ROOTFS_BUILDDIR)
66
        print 'Done...'
67
 
68
if __name__ == "__main__":
69
    # This is only a default test case
70
    container = Container()
71
    container.id = 0
72
    rootfs_builder = RootfsBuilder(projpaths, container)
73
 
74
    if len(sys.argv) == 1:
75
        rootfs_builder.build_rootfs()
76
    elif "clean" == sys.argv[1]:
77
        rootfs_builder.clean()
78
    else:
79
        print " Usage: %s [clean]" % (sys.argv[0])

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.