Got the first part of the packing phase in place.

Generate kernel.S rather than have it as a manually maintained file.
This commit is contained in:
Russel Winder
2009-08-10 09:33:05 +01:00
parent fb038ab757
commit 163baa31ea
3 changed files with 95 additions and 26 deletions

View File

@@ -254,9 +254,25 @@ else :
Alias('bootdesc', bootdesc)
########## Do the packing / create loadable ########################
loaderEnvironment = baseEnvironment.Clone(
CC = 'arm-none-linux-gnueabi-gcc',
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'],
LINKFLAGS = ['-nostdlib', '-Tloader/mylink.lds'],
PROGSUFFIX = '.axf',
LIBS = [libelf, libs['baremetal'], 'gcc', libs['baremetal']],
CPPPATH = ['#libs/elf/include', '#' + buildDirectory + '/loader'])
#### TODO: Fix the tasks data structure so as to avoid all the assumptions.
loader = SConscript('loader/SConscript', variant_dir = buildDirectory + '/loader', duplicate = 0, exports = {'environment': loaderEnvironment, 'images':[startAxf, bootdesc] + tasks})
Alias('final', loader)
########## Other rules. ########################
Default(crts.values() + libs.values() + [libelf, startAxf] + tasks + bootdesc)
Default(crts.values() + libs.values() + [libelf, startAxf] + tasks + bootdesc + loader)
Clean('.', [buildDirectory])
@@ -272,6 +288,7 @@ Explicit targets are:
tasklibs -- build all the support libraries for the tasks.
tasks -- build all the tasks.
bootdesc -- build the tasks and the boot descriptor.
final -- build the loadable.
The default target is to compile everything and to do a final link.

77
loader/SConscript Normal file
View File

@@ -0,0 +1,77 @@
# -*- 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
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
import os.path
import subprocess
Import('environment', 'images')
def ksymToLds(target, source, env):
symbols = ['break_virtual']
with open(target[0].path, 'w') as asmFile:
asmFile.write('''
/*
* %s autogenerated from %s
*
* This file is included by the loader sources so that any
* kernel symbol address can be known in advance and stopped
* at by debuggers before virtual memory is enabled.
*/
''' % (target[0].name, source[0].name))
for symbol in symbols:
process = subprocess.Popen('arm-none-eabi-objdump -d ' + source[0].path + ' | grep "<' + symbol + '>"', shell=True, stdout=subprocess.PIPE)
assert process.wait() == 0
address, name = process.stdout.read().split()
assert '<' + symbol + '>:' == name
asmFile.write( '''
.section .text
.align 4
.global %s;
.type %s, function;
.equ %s, %s
''' % (symbol, symbol, symbol, (hex(int(address, 16) - 0xf0000000))))
def createKernelSFile(target, source, env):
with open(target[0].path, 'w') as asmFile:
asmFile.write('''
/* This file defines kernel symbols extracted from the kernel image in their physical address */
.include "start.axf.S"
.section .kernel
.incbin "%s"
''' % (source[0].path))
for image in source[1:]:
asmFile.write('''
.align 4
.section .%s
.incbin "%s"
''' % (os.path.splitext(image.name)[0], image.path))
startAxfS = Command('start.axf.S', images[0], ksymToLds)
kernelS = Command('kernel.S', images + [startAxfS], createKernelSFile)
objects = environment.Object(Glob('*.c') + [kernelS])
Depends(objects, environment['configFiles'])
Depends(objects, images)
program = environment.Program('final', objects)
Return('program')

View File

@@ -1,25 +0,0 @@
/* This file defines kernel symbols extracted from the kernel image in their physical address */
.include "start.axf.S"
.section .kernel
.incbin "start.axf"
.align 4
.section .bootdesc
.incbin "bootdesc.axf"
.align 4
.section .mm0
.incbin "mm0.axf"
.align 4
.section .fs0
.incbin "fs0.axf"
.align 4
.section .test0
.incbin "test0.axf"
.align 4