From 6f3d3fdf49e6368e7838049264ea0314b829c146 Mon Sep 17 00:00:00 2001 From: Russel Winder Date: Wed, 5 Aug 2009 18:33:37 +0100 Subject: [PATCH] Got the bootdesc building. --- SConstruct | 19 ++++++- tasks/bootdesc/.gitignore | 2 - tasks/bootdesc/SConscript | 91 +++++++++++++++++++++++++++++++++ tasks/bootdesc/bootdesc.c.templ | 16 ------ 4 files changed, 109 insertions(+), 19 deletions(-) delete mode 100644 tasks/bootdesc/.gitignore create mode 100644 tasks/bootdesc/SConscript delete mode 100644 tasks/bootdesc/bootdesc.c.templ diff --git a/SConstruct b/SConstruct index 863b62e..2df9203 100644 --- a/SConstruct +++ b/SConstruct @@ -237,9 +237,26 @@ else : Alias ('tasks', tasks) +########## Create the boot description ######################## + + taskName = 'bootdesc' + + bootdescEnvironment = baseEnvironment.Clone( + CC = 'arm-none-linux-gnueabi-gcc', + CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'], + LINKFLAGS = ['-nostdlib', '-Ttasks/' + taskName + '/linker.lds'], + ASFLAGS = ['-D__ASSEMBLY__'], + PROGSUFFIX = '.axf', + LIBS = ['gcc'], + CPPPATH = ['#' + includeDirectory]) + + bootdesc = SConscript('tasks/' + taskName + '/SConscript', variant_dir = buildDirectory + '/tasks/' + taskName, duplicate = 0, exports = {'environment': bootdescEnvironment, 'images': [startAxf] + tasks}) + + Alias('bootdesc', bootdesc) + ########## Other rules. ######################## - Default(crts.values() + libs.values() + [libelf, startAxf] + tasks) + Default(crts.values() + libs.values() + [libelf, startAxf] + tasks + bootdesc) Clean('.', [buildDirectory]) diff --git a/tasks/bootdesc/.gitignore b/tasks/bootdesc/.gitignore deleted file mode 100644 index 1af9725..0000000 --- a/tasks/bootdesc/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.txt -bootdesc.c.append diff --git a/tasks/bootdesc/SConscript b/tasks/bootdesc/SConscript new file mode 100644 index 0000000..748a5ec --- /dev/null +++ b/tasks/bootdesc/SConscript @@ -0,0 +1,91 @@ +# -*- mode: python; coding: utf-8; -*- + +# 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 +# . +# +# Author: Russel Winder + +import os.path +import subprocess +import shutil + +Import('environment', 'images') + +bootdescTemplate = \ +''' +/* This file is autogenerated, do not edit by hand. */ + +/* Supervisor task at load time. */ +struct svc_image { + char name[16]; + unsigned int phys_start; + unsigned int phys_end; +} __attribute__((__packed__)); + +/* Supervisor task descriptor at load time */ +struct bootdesc { + int desc_size; + int total_images; + struct svc_image images[]; +} __attribute__((__packed__)); + +struct bootdesc bootdesc = { + .desc_size = sizeof(struct bootdesc) + sizeof(struct svc_image) * %s, + .total_images = %s, + .images = { +%s + }, +}; +''' + +imageTemplate = \ +''' [%s] = { + .name = "%s", + .phys_start = %s, + .phys_end = %s, + }, +''' + +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 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 relocateBootdesc(target, source, env): + name, start, end = generateLocationData(source[1]) + process = subprocess.Popen(executable='arm-none-linux-gnueabi-objcopy', args=( + '--adjust-section-vma .data=' + end, + source[0].path)) + assert process.wait() == 0 + shutil.copyfile(source[0].path, target[0].path) + +bootdescSource = environment.Command('bootdesc.c', images, generateBootdesc) +objects = environment.Object(bootdescSource) +Depends(objects, environment['configFiles']) +bootdesc = environment.Command('bootdesc.axf', environment.Program('bootdesc_intermediate', objects) + [images[0]] , relocateBootdesc) + +Return('bootdesc') diff --git a/tasks/bootdesc/bootdesc.c.templ b/tasks/bootdesc/bootdesc.c.templ deleted file mode 100644 index 0b6aa49..0000000 --- a/tasks/bootdesc/bootdesc.c.templ +++ /dev/null @@ -1,16 +0,0 @@ - - -/* Supervisor task at load time. */ -struct svc_image { - char name[16]; - unsigned int phys_start; - unsigned int phys_end; -} __attribute__((__packed__)); - -/* Supervisor task descriptor at load time */ -struct bootdesc { - int desc_size; - int total_images; - struct svc_image images[]; -} __attribute__((__packed__)); -