Revision: 391 Author: nieklinnenbank Date: Sat Oct 16 19:56:53 2010Log: Added Binary() builder to convert a binary file to a C unsigned char[] symbol.
http://code.google.com/p/freenos/source/detail?r=391 Added: /branches/scratch/site_scons/binary.py Modified: /branches/scratch/site_scons/build.py /branches/scratch/system/x86/pc/SConscript ======================================= --- /dev/null +++ /branches/scratch/site_scons/binary.py Sat Oct 16 19:56:53 2010 @@ -0,0 +1,82 @@ +# +# Copyright (C) 2010 Niek Linnenbank +# +# 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/>. +# + +import os +import binascii + +# +# Produces an C symbol from a given binary. +# +def binary_func(target, source, env): + + # Open source and target files. + fin = open(str(source[0]), "r") + fout = open(str(target[0]), "w") + + # Read input file. + data = binascii.hexlify(fin.read()) + symbol = os.path.basename(str(source[0])) + symbol = symbol.replace(".", "_") + + # Output header. + fout.write("/*\n" + + " * This file is auto-generated from " + str(source[0]) + "\n" + + " */\n" + "\n" + "unsigned char " + symbol + "[] = { ") + + # Loop data. + i = 0 + while i < len(data): + fout.write("0x" + data[i] + data[i+1]) + + if i < len(data) - 2: + fout.write(",") + i += 2 + + #for i in range(0, len(data)): +# +# fout.write(data[i]) +# +# if i < len(data) - 1: +# fout.write(",") + + # Output footer. + fout.write("};\n\n") + + # All done. + fin.close() + fin.close() + +def binary_str(target, source, env): + + return " GEN " + str(target[0]) + +# +# Add ourselves to the given environment. +# +def generate(env): + + builder = env.Builder(action = env.Action(binary_func, binary_str)) + env.Append(BUILDERS = { 'Binary' : builder }) + +# +# We always exist. +# +def exists(env): + + return True ======================================= --- /branches/scratch/site_scons/build.py Sat Oct 16 18:53:39 2010 +++ /branches/scratch/site_scons/build.py Sat Oct 16 19:56:53 2010 @@ -31,7 +31,7 @@ env.Append(LIBS = [ lib ]) # Create target, host and kernel environments. -target = Environment(tools = ["default", "bootimage", "iso"], +target = Environment(tools = ["default", "bootimage", "iso", "binary"], toolpath = ["site_scons"]) host = Environment() kernel = None ======================================= --- /branches/scratch/system/x86/pc/SConscript Sat Oct 16 18:53:39 2010 +++ /branches/scratch/system/x86/pc/SConscript Sat Oct 16 19:56:53 2010 @@ -23,16 +23,19 @@ # env = build_env.Clone() env.UseLibraries([ 'libc', 'libposix', 'libboot' ])-i = env.BootImage('#${BUILDROOT}/boot.img', '#system/x86/pc/config/boot_image.conf')
-p = env.Program('kernel', [ Glob('*.c'), - Glob('*.S') ]) -c = env.ISO('#${BUILDROOT}/boot.iso', - [ '#system/x86/pc/config/cd.img', - '#system/x86/pc/config/grub.cfg', - '#${BUILDROOT}/system/kernel', - '#${BUILDROOT}/boot.img' ]) - -Depends(p, i) +env.BootImage('#${BUILDROOT}/boot.img', '#system/x86/pc/config/boot_image.conf') +env.Binary('boot_image.c', '#${BUILDROOT}/boot.img') +env.Program('kernel', [ Glob('*.c'), + Glob('*.S') ]) + +# +# Make a bootable LiveCD. +# +env.ISO('#${BUILDROOT}/boot.iso', + [ '#system/x86/pc/config/cd.img', + '#system/x86/pc/config/grub.cfg', + '#${BUILDROOT}/system/kernel', + '#${BUILDROOT}/boot.img' ]) # # Register phony targets.