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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [scripts/] [conts/] [packall.py] - Blame information for rev 2

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
9
from os.path import join
10
 
11
PROJRELROOT = '../../'
12
 
13
SCRIPTROOT = os.path.abspath(os.path.dirname("."))
14
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
15
 
16
from config.projpaths import *
17
from config.configuration import *
18
 
19
containers_assembler_body = \
20
'''
21
.align 4
22
.section .cont.%d
23
.incbin "%s"
24
'''
25
 
26
containers_lds_start = \
27
'''/*
28
 * Autogenerated linker script that packs all containers
29
 * in a single image.
30
 *
31
 * Copyright (C) 2009 B Labs Ltd.
32
 */
33
 
34
SECTIONS
35
{'''
36
 
37
containers_lds_body = \
38
'''
39
        .cont.%d : { *(.cont.%d) }'''
40
 
41
containers_lds_end = \
42
'''
43
}
44
'''
45
 
46
class AllContainerPacker:
47
    def __init__(self, image_list, container_list):
48
        self.cont_images_in = image_list
49
        self.cont_images_in.sort()
50
        self.containers = container_list
51
 
52
        self.CONTAINERS_BUILDDIR = join(PROJROOT, 'build/conts')
53
        self.containers_lds_out = join(self.CONTAINERS_BUILDDIR, \
54
                                      'containers.lds')
55
        self.containers_S_out = join(self.CONTAINERS_BUILDDIR, 'containers.S')
56
        self.containers_elf_out = join(self.CONTAINERS_BUILDDIR, \
57
                                      'containers.elf')
58
 
59
    def generate_container_S(self, target_path):
60
        with open(target_path, 'w+') as f:
61
            file_body = ""
62
            img_i = 0
63
            for img in self.cont_images_in:
64
                file_body += containers_assembler_body % (img_i, img)
65
                img_i += 1
66
 
67
            f.write(file_body)
68
 
69
    def generate_container_lds(self, target_path):
70
        with open(target_path, 'w+') as f:
71
            img_i = 0
72
            file_body = containers_lds_start
73
            for img in self.cont_images_in:
74
                file_body += containers_lds_body % (img_i, img_i)
75
                img_i += 1
76
            file_body += containers_lds_end
77
            f.write(file_body)
78
 
79
    def pack_all(self, config):
80
        self.generate_container_lds(self.containers_lds_out)
81
        self.generate_container_S(self.containers_S_out)
82
        os.system(config.toolchain_kernel + "gcc " + "-nostdlib -o %s -T%s %s" \
83
                  % (self.containers_elf_out, self.containers_lds_out, \
84
                     self.containers_S_out))
85
 
86
        # Return the final image to calling script
87
        return self.containers_elf_out
88
 
89
    def clean(self):
90
        if os.path.exists(self.containers_elf_out):
91
            shutil.rmtree(self.containers_elf_out)
92
        if os.path.exists(self.containers_lds_out):
93
            shutil.rmtree(self.containers_lds_out)
94
        if os.path.exists(self.containers_S_out):
95
            shutil.rmtree(self.containers_S_out)
96
 
97
if __name__ == "__main__":
98
    all_cont_packer = AllContainerPacker([], [])

powered by: WebSVN 2.1.0

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