Bootdesc building working

This commit is contained in:
Bahadir Balban
2009-09-30 16:31:34 +03:00
parent 1aa31bc9d5
commit 73225a0119
7 changed files with 85 additions and 223 deletions

View File

@@ -3,31 +3,26 @@
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
import os.path
import subprocess
import shutil
import sys, subprocess, shutil
from os.path import *
Import('environment', 'images')
Import('config', 'environment', 'images')
e = environment.Clone()
e.Append(LINKFLAGS = ['-T' + e['posixServicesDirectory'] + '/bootdesc/linker.lds'])
e.Append(CPPPATH = ['#' + e['includeDirectory']])
e.Append(LINKFLAGS = ['-T' + e['bootdesc_dir'] + '/linker.lds'])
#e.Append(LINKFLAGS = ['-T' + '/linker.lds'])
bootdescTemplate = \
PROJRELROOT = '../../../../'
sys.path.append(os.path.abspath(PROJRELROOT))
from config.projpaths import *
from config.configuration import *
from tools.pyelf import elf
bootdesc_template = \
'''
/* This file is autogenerated, do not edit by hand. */
@@ -54,7 +49,7 @@ struct bootdesc bootdesc = {
};
'''
imageTemplate = \
image_template = \
''' [%s] = {
.name = "%s",
.phys_start = %s,
@@ -62,36 +57,49 @@ imageTemplate = \
},
'''
def generateLocationData(image):
process = subprocess.Popen('tools/pyelf/readelf.py --lma-start-end ' + image.path, shell=True, stdout=subprocess.PIPE)
assert process.wait() == 0
return (process.stdout.readline().strip(), process.stdout.readline().strip().split()[1], process.stdout.readline().strip().split()[1])
def conv_hex(val):
hexval = hex(val)
if hexval[-1:] == 'L':
hexval = hexval[:-1]
return hexval
def generateBootdesc(target, source, env):
'''
Extracts name, start, end information from the kernel and each svc task.
Uses this information to produce bootdesc.c
'''
with open(target[0].path, 'w' ) as f:
imagesString = ''
numberOfImages = len(source) - 1
for index in range(1, len(source)):
imagesString += imageTemplate % ((index - 1,) + generateLocationData(source[index]))
f.write(bootdescTemplate % (numberOfImages, numberOfImages, imagesString))
def image_lma_start_end(img):
elffile = elf.ElfFile.from_file(img)
paddr_first = 0
paddr_start = 0
paddr_end = 0
for pheader in elffile.pheaders:
x = pheader.ai
if str(x.p_type) != "LOAD":
continue
if paddr_first == 0:
paddr_first = 1
paddr_start = x.p_paddr.value
if paddr_start > x.p_paddr.value:
paddr_start = x.p_paddr.value
if paddr_end < x.p_paddr + x.p_memsz:
paddr_end = x.p_paddr + x.p_memsz
return paddr_start, paddr_end
def relocateBootdesc(target, source, env):
name, start, end = generateLocationData(source[1])
print "arm-none-linux-gnueabi-objcopy" + " --adjust-section-vma .data=" + end + " " + source[0].path
# process = subprocess.Popen(executable='arm-none-linux-gnueabi-objcopy', args=(
# '--adjust-section-vma .data=' + end,
# source[0].path))
# assert process.wait() == 0
os.system("arm-none-linux-gnueabi-objcopy --adjust-section-vma .data=" + end + " " + source[0].path)
shutil.copyfile(source[0].path, target[0].path)
def generate_bootdesc(target, source, env):
with open(target[0].path, 'w+' ) as f:
images_string = ''
for index in range(len(source)):
start, end = image_lma_start_end(source[index].path)
images_string += image_template % (str(index), basename(source[index].path), conv_hex(start), conv_hex(end))
f.write(bootdesc_template % (len(source), len(source), images_string))
objects = e.Object(e.Command('bootdesc.c', images, generateBootdesc))
Depends(objects, e['configFiles'])
bootdesc = e.Command('bootdesc.axf', e.Program('bootdesc_intermediate', objects) + [images[1]] , relocateBootdesc)
Depends(bootdesc, e['configFiles'])
def relocate_bootdesc(target, source, env):
bootdesc_raw = source[0]
images = source[1:]
mm0 = images[0]
start, end = image_lma_start_end(mm0.path)
print "arm-none-linux-gnueabi-objcopy --adjust-section-vma .data=" + conv_hex(end) + " " + bootdesc_raw.path
os.system("arm-none-linux-gnueabi-objcopy --adjust-section-vma .data=" + conv_hex(end) + " " + bootdesc_raw.path)
shutil.copyfile(bootdesc_raw.path, target[0].path)
bootdesc_c = e.Command('bootdesc.c', images, generate_bootdesc)
bootdesc_raw = e.Program('bootdesc_raw.elf', bootdesc_c)
bootdesc = e.Command('bootdesc.elf', [bootdesc_raw, images], relocate_bootdesc)
Return('bootdesc')