[freenos] r389 committed - Added BootImage() and ISO() builders.

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Sun, 17 Oct 2010 01:55:20 +0000

Revision: 389
Author: nieklinnenbank
Date: Sat Oct 16 18:53:39 2010
Log: Added BootImage() and ISO() builders.

http://code.google.com/p/freenos/source/detail?r=389

Added:
 /branches/scratch/site_scons/bootimage.py
 /branches/scratch/site_scons/iso.py
Modified:
 /branches/scratch/site_scons/build.py
 /branches/scratch/site_scons/version.py
 /branches/scratch/system/x86/pc/SConscript

=======================================
--- /dev/null
+++ /branches/scratch/site_scons/bootimage.py   Sat Oct 16 18:53:39 2010
@@ -0,0 +1,74 @@
+#
+# 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
+
+#
+# Modifies the dependency list by parsing boot image config.
+#
+def boot_image_emitter(target, source, env):
+
+    # Open boot configuration.
+    f = open(str(source[0]))
+
+    # Loop all lines.
+    for line in f.readlines():
+
+       # Skip comments, empty lines and subtrees.
+       if len(line.strip()) <= 0 or \
+              line.find('=') != -1 or \
+              line[0] == '{' or \
+              line[0] == '}' or \
+              line[0] == '#':
+           continue
+
+       # Make us depend on the program.
+       source.append('#' + env['BUILDROOT'] + '/' + line.strip())
+
+    # All done.
+    f.close()
+    return target, source
+
+#
+# Generate a boot image.
+#
+def boot_image_func(target, source, env):
+
+    # Invoke the mkimage utility to generate a boot image.
+    os.system("build/host/bin/mkimage " +
+             "system/" + env['ARCH'] + "/" +
+              env['SYSTEM'] + "/config/boot_image.conf " +
+              env['BUILDROOT'] + " " + str(target[0]))
+
+def boot_image_str(target, source, env):
+
+    return "  IMG " + str(target[0])
+
+#
+# Add ourselves to the given environment.
+#
+def generate(env):
+
+ builder = env.Builder(action = env.Action(boot_image_func, boot_image_str),
+                          emitter = boot_image_emitter)
+    env.Append(BUILDERS = { 'BootImage' : builder })
+
+#
+# We always exist.
+#
+def exists(env):
+    return True
=======================================
--- /dev/null
+++ /branches/scratch/site_scons/iso.py Sat Oct 16 18:53:39 2010
@@ -0,0 +1,61 @@
+#
+# 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 tempfile
+import shutil
+
+#
+# Generate a bootable ISO image.
+#
+def iso_func(target, source, env):
+
+    # Create a temporary directory.
+    temp = tempfile.mkdtemp()
+
+    # Copy required files to temp directory.
+    for s in source:
+       shutil.copy(str(s), temp)
+
+    # Generate the ISO.
+    os.system('mkisofs -quiet -R -b cd.img -no-emul-boot ' +
+              '-boot-load-size 4 -boot-info-table -o ' + str(target[0]) +
+              ' -V "FreeNOS ' + env['RELEASE'] + '" ' + temp);
+
+    # Clean up temporary directory.
+    shutil.rmtree(temp);
+
+#
+# String command representation for ISO builder.
+#
+def iso_str(target, source, env):
+
+    return "  ISO " + str(target[0])
+
+#
+# Add ourselves to the given environment.
+#
+def generate(env):
+
+    builder = env.Builder(action  = env.Action(iso_func, iso_str))
+    env.Append(BUILDERS = { 'ISO' : builder })
+
+#
+# We always exist.
+#
+def exists(env):
+    return Env.Detect('mkisofs')
=======================================
--- /branches/scratch/site_scons/build.py       Sun Oct 10 16:06:55 2010
+++ /branches/scratch/site_scons/build.py       Sat Oct 16 18:53:39 2010
@@ -31,7 +31,8 @@
        env.Append(LIBS    = [ lib ])

 # Create target, host and kernel environments.
-target = Environment()
+target = Environment(tools    = ["default", "bootimage", "iso"],
+                    toolpath = ["site_scons"])
 host   = Environment()
 kernel = None

=======================================
--- /branches/scratch/site_scons/version.py     Sat Oct 16 11:26:27 2010
+++ /branches/scratch/site_scons/version.py     Sat Oct 16 18:53:39 2010
@@ -61,6 +61,11 @@
 except:
     currentRev = current + "-local"

+# Set the full version revision in environments.
+target['RELEASE'] = currentRev
+kernel['RELEASE'] = currentRev
+host['RELEASE']   = currentRev
+
 # Attempt to retrieve the correct compiler version
 try:
compiler = os.popen(target['CC'] + " --version | head -n 1").read().strip()
=======================================
--- /branches/scratch/system/x86/pc/SConscript  Sun Oct 10 16:06:55 2010
+++ /branches/scratch/system/x86/pc/SConscript  Sat Oct 16 18:53:39 2010
@@ -18,21 +18,28 @@
 import phony
 Import('build_env')

+#
+# Build the x86/pc kernel.
+#
 env = build_env.Clone()
-env.UseLibraries([ 'libc', 'libposix' ])
-env.Program('kernel', [ Glob('*.c'),
-                       Glob('*.S') ])
-
-phony.Targets(iso =   'rm -f boot.iso ; ' +
-                      'rm -rf boot ; ' +
-                      'mkdir boot ; ' +
- 'cp system/x86/pc/config/cd.img system/x86/pc/config/grub.cfg build/x86/pc/system/kernel boot ; ' +
-                     'mkisofs -R -b cd.img -no-emul-boot ' +
- '-boot-load-size 4 -boot-info-table -o boot.iso -V FreeNOS boot ; ' +
-                     'rm -rf boot',
- qemu = '@qemu -kernel build/x86/pc/system/kernel -smp 4 -m 64 -nographic', - qemu_debug = 'qemu -kernel build/x86/pc/system/kernel -smp 2 -m 64 -serial stdio -s -S -d cpu_reset,int', - qemu_debug1 = 'qemu -kernel build/x86/pc/system/kernel -smp 1 -m 64 -serial stdio -s -S -d cpu_reset,int', - bochs = 'bochs -q "ata0-slave: type=cdrom, path=boot.iso, status=inserted" "boot: cdrom"', - bochs_debug = 'bochs -q "ata0-slave: type=cdrom, path=boot.iso, status=inserted" "boot: cdrom" "gdbstub: enabled=1, port=1234, text_base=0, data_base=0, bss_base=0"')
-
+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)
+
+#
+# Register phony targets.
+#
+phony.Targets(qemu  = 'qemu -cdrom ' + build_env['BUILDROOT'] +
+                     '/boot.iso -smp 4 -m 64 -nographic',
+             qemu_debug  = 'qemu -cdrom ' + build_env['BUILDROOT'] +
+                           '/boot.iso -smp 2 -m 64 -serial stdio -s -S -d 
cpu_reset,int',
+             qemu_debug1 = 'qemu -cdrom ' + build_env['BUILDROOT'] +
+                           '/boot.iso -smp 1 -m 64 -serial stdio -s -S -d 
cpu_reset,int')

Other related posts:

  • » [freenos] r389 committed - Added BootImage() and ISO() builders. - freenos