mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 19:03:15 +01:00
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
# -*- 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, startAxfS])
|
|
Depends(objects, environment['configFiles'])
|
|
Depends(objects, images)
|
|
program = environment.Program('final', objects + [environment['baremetal_crt0']])
|
|
|
|
Return('program')
|