Added support for ATAGS for linux kernel

This commit is contained in:
Amit Mahajan
2009-10-13 11:36:01 +05:30
parent 2625d5e871
commit 61a0d5b60f
4 changed files with 112 additions and 4 deletions

View File

@@ -25,11 +25,13 @@ KERNEL_CINFO_PATH = join(PROJROOT, "src/generic/cinfo.c")
LINUXDIR = join(PROJROOT, 'conts/linux')
LINUX_KERNELDIR = join(LINUXDIR, 'linux-2.6.28.10')
LINUX_ROOTFSDIR = join(LINUXDIR, 'rootfs')
LINUX_ATAGSDIR = join(LINUXDIR, 'atags')
POSIXDIR = join(PROJROOT, 'conts/posix')
POSIX_BOOTDESCDIR = join(POSIXDIR, 'bootdesc')
projpaths = { \
'LINUX_ATAGSDIR' : LINUX_ATAGSDIR, \
'LINUX_ROOTFSDIR' : LINUX_ROOTFSDIR, \
'LINUX_KERNELDIR' : LINUX_KERNELDIR, \
'LINUXDIR' : LINUXDIR, \

View File

@@ -17,6 +17,7 @@ from config.projpaths import *
from config.configuration import *
from scripts.linux.build_linux import *
from scripts.linux.build_rootfs import *
from scripts.linux.build_atags import *
from pack import *
from packall import *
@@ -25,9 +26,12 @@ def build_linux_container(projpaths, container):
linux_builder.build_linux()
rootfs_builder = RootfsBuilder(projpaths, container)
rootfs_builder.build_rootfs()
atags_builder = AtagsBuilder(projpaths, container)
atags_builder.build_atags()
linux_container_packer = LinuxContainerPacker(container, \
linux_builder, \
rootfs_builder)
rootfs_builder, \
atags_builder)
return linux_container_packer.pack_container()
def glob_by_walk(arg, dirname, names):

View File

@@ -53,7 +53,7 @@ def source_to_builddir(srcdir, id):
return join(BUILDDIR, cont_builddir)
class LinuxContainerPacker:
def __init__(self, container, linux_builder, rootfs_builder):
def __init__(self, container, linux_builder, rootfs_builder, atags_builder):
# Here, we simply attempt to get PROJROOT/conts as
# PROJROOT/build/cont[0-9]
@@ -67,6 +67,7 @@ class LinuxContainerPacker:
'container' + str(container.id) + '.elf')
self.kernel_image_in = linux_builder.kernel_image
self.rootfs_elf_in = rootfs_builder.rootfs_elf_out
self.atags_elf_in = atags_builder.atags_elf_out
def generate_container_assembler(self, source):
with open(self.container_S_out, 'w+') as f:
@@ -92,9 +93,11 @@ class LinuxContainerPacker:
def pack_container(self):
self.generate_container_lds([self.kernel_image_in, \
self.rootfs_elf_in])
self.rootfs_elf_in, \
self.atags_elf_in])
self.generate_container_assembler([self.kernel_image_in, \
self.rootfs_elf_in])
self.rootfs_elf_in, \
self.atags_elf_in])
os.system("arm-none-linux-gnueabi-gcc " + "-nostdlib -o %s -T%s %s" \
% (self.container_elf_out, \
self.container_lds_out,

99
scripts/linux/build_atags.py Executable file
View File

@@ -0,0 +1,99 @@
#! /usr/bin/env python2.6
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
import os, sys, shelve, shutil
from os.path import join
PROJRELROOT = "../.."
SCRIPTROOT = os.path.abspath(os.path.dirname("."))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
from config.projpaths import *
from config.configuration import *
# Create linux kernel build directory path as:
# conts/linux -> build/cont[0-9]/linux
def source_to_builddir(srcdir, id):
cont_builddir = \
os.path.relpath(srcdir, \
PROJROOT).replace("conts", \
"cont" + str(id))
return join(BUILDDIR, cont_builddir)
class AtagsBuilder:
def __init__(self, pathdict, container):
self.LINUX_ATAGSDIR = pathdict["LINUX_ATAGSDIR"]
self.LINUX_ATAGS_BUILDDIR = \
source_to_builddir(self.LINUX_ATAGSDIR, container.id)
self.atags_lds_in = join(self.LINUX_ATAGSDIR, "atags.lds.in")
self.atags_lds_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.lds")
self.atags_elf_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.elf")
self.atags_S_in = join(self.LINUX_ATAGSDIR, "atags.S.in")
self.atags_S_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.S")
self.atags_c_in = join(self.LINUX_ATAGSDIR, "atags.c.in")
self.atags_c_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.c")
self.atags_h_in = join(self.LINUX_ATAGSDIR, "atags.h.in")
self.atags_h_out = join(self.LINUX_ATAGS_BUILDDIR, "atags.h")
self.cont_id = container.id
self.elf_relpath = os.path.relpath(self.atags_elf_out, \
self.LINUX_ATAGSDIR)
def build_atags(self):
print 'Building Atags for linux kenel...'
# IO files from this build
os.chdir(LINUX_ATAGSDIR)
if not os.path.exists(self.LINUX_ATAGS_BUILDDIR):
os.makedirs(self.LINUX_ATAGS_BUILDDIR)
with open(self.atags_S_in, 'r') as input:
with open(self.atags_S_out, 'w+') as output:
output.write(input.read() % self.elf_relpath)
with open(self.atags_h_out, 'w+') as output:
with open(self.atags_h_in, 'r') as input:
output.write(input.read() % {'cn' : self.cont_id})
os.system("arm-none-linux-gnueabi-cpp -I%s -P %s > %s" % \
(self.LINUX_ATAGS_BUILDDIR, self.atags_lds_in, \
self.atags_lds_out))
with open(self.atags_c_out, 'w+') as output:
with open(self.atags_c_in, 'r') as input:
output.write(input.read() % {'cn' : self.cont_id})
os.system("arm-none-linux-gnueabi-gcc " + \
"-g -ffreestanding -std=gnu99 -Wall -Werror " + \
"-nostdlib -o %s -T%s %s" % \
(self.atags_elf_out, self.atags_lds_out, self.atags_c_out))
print "Done..."
def clean(self):
print 'Cleaning Atags...'
if os.path.exists(self.LINUX_ATAGS_BUILDDIR):
shutil.rmtree(self.LINUX_ATAGS_BUILDDIR)
print 'Done...'
if __name__ == "__main__":
# This is only a default test case
container = Container()
container.id = 0
atags_builder = AtagsBuilder(projpaths, container)
if len(sys.argv) == 1:
atags_builder.build_atags()
elif "clean" == sys.argv[1]:
atags_builder.clean()
else:
print " Usage: %s [clean]" % (sys.argv[0])