mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Managed to connect container SConstruct to main one
This commit is contained in:
@@ -4,103 +4,19 @@
|
||||
# Copyright (C) 2009 B Labs
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from os.path import join
|
||||
|
||||
linux_kernel_path = join("/opt/codezero/build/conts/linux/arch/arm/boot/compressed/vmlinux")
|
||||
rootfs_path = join("rootfs/rootfs.elf")
|
||||
Import('environment')
|
||||
|
||||
container_assembler_body = \
|
||||
'''
|
||||
.align 4
|
||||
.section .img.%d
|
||||
.incbin "%s"
|
||||
'''
|
||||
cwd = os.getcwd()
|
||||
|
||||
container_lds_start = \
|
||||
'''/*
|
||||
* Autogenerated linker script that embeds each container image.
|
||||
*
|
||||
* Copyright (C) 2009 B Labs
|
||||
*/
|
||||
os.chdir("/opt/codezero/conts/linux")
|
||||
|
||||
SECTIONS
|
||||
{'''
|
||||
os.system("scons")
|
||||
|
||||
container_lds_body = \
|
||||
'''
|
||||
.img.%d : { *(.img.%d) }'''
|
||||
image = []
|
||||
image.append(File("container.elf"))
|
||||
|
||||
container_lds_end = \
|
||||
'''
|
||||
}
|
||||
'''
|
||||
|
||||
# TODO: This might be done much more elegantly and flexibly.
|
||||
#
|
||||
# But it makes sense to put the image finding logic to a function
|
||||
# rather than hard-code it in an array at the beginning.
|
||||
def collect_images(target, source, env):
|
||||
cmd1 = "cp " + linux_kernel_path + " ./"
|
||||
cmd2 = "cp " + rootfs_path + " ./"
|
||||
os.system(cmd1)
|
||||
os.system(cmd2)
|
||||
os.system("echo " + cmd1)
|
||||
os.system("echo " + cmd2)
|
||||
|
||||
images.append("vmlinux")
|
||||
images.append("rootfs.elf")
|
||||
for i in images:
|
||||
print i
|
||||
|
||||
def generate_container_assembler(source, target, env):
|
||||
f = open("container.S", "w+")
|
||||
file_body = ""
|
||||
img_i = 0
|
||||
for img in source:
|
||||
file_body += container_assembler_body % (img_i, img)
|
||||
img_i += 1
|
||||
|
||||
f.write(file_body)
|
||||
f.close()
|
||||
|
||||
def generate_container_lds(source, target, env):
|
||||
f = open("container.lds", "w+")
|
||||
img_i = 0
|
||||
file_body = container_lds_start
|
||||
for img in source:
|
||||
file_body += container_lds_body % (img_i, img_i)
|
||||
img_i += 1
|
||||
file_body += container_lds_end
|
||||
f.write(file_body)
|
||||
f.close()
|
||||
|
||||
def build_rootfs(source, target, env):
|
||||
os.chdir("./rootfs")
|
||||
os.system("./build_rootfs.sh")
|
||||
os.chdir("..")
|
||||
|
||||
def build_linux(source, target, env):
|
||||
os.system("./build_linux.sh")
|
||||
|
||||
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
|
||||
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', \
|
||||
'-std=gnu99', '-Wall', '-Werror'],
|
||||
LINKFLAGS = ['-nostdlib'],
|
||||
PROGSUFFIX = '.elf', # The suffix to use for final executable
|
||||
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
|
||||
)
|
||||
images = []
|
||||
linux_kernel = env.Command(linux_kernel_path, "linux-2.6.28.10", build_linux)
|
||||
rootfs = env.Command(rootfs_path, "rootfs/rootfs.img", build_rootfs)
|
||||
env.Command(["vmlinux", "rootfs.elf"], [linux_kernel_path, rootfs_path], collect_images)
|
||||
container_S = env.Command("container.S", ["vmlinux", "rootfs.elf"], generate_container_assembler)
|
||||
container_lds = env.Command("container.lds", ["vmlinux", "rootfs.elf"], generate_container_lds)
|
||||
|
||||
env.Replace(LINKFLAGS = ['-nostdlib', '-Tcontainer.lds'])
|
||||
env.Replace(PROGSUFFIX = '.elf')
|
||||
objs = env.Object('container.S')
|
||||
container = env.Program('container.elf', objs)
|
||||
env.Depends(container, [linux_kernel, rootfs, container_S, container_lds])
|
||||
os.chdir(cwd)
|
||||
|
||||
Return('image')
|
||||
|
||||
Reference in New Issue
Block a user