mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Merge branch 'master' into devel
This commit is contained in:
@@ -29,7 +29,7 @@ env = Environment(CC = 'arm-none-eabi-gcc',
|
||||
# such as stdarg.h e.g. for variable args, as in printk().
|
||||
CCFLAGS = ['-g', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \
|
||||
'-std=gnu99', '-Wall', '-Werror'],
|
||||
LINKFLAGS = ['-nostdlib', '-T' + "loader/linker.lds", "-u_start"],
|
||||
LINKFLAGS = ['-nostdlib', '-T' + join(BUILDDIR, 'loader/linker.lds'), "-u_start"],
|
||||
ASFLAGS = ['-D__ASSEMBLY__'],
|
||||
PROGSUFFIX = '.elf',
|
||||
ENV = {'PATH' : os.environ['PATH']},
|
||||
|
||||
@@ -39,9 +39,10 @@ CONT%(cn)d_PAGER_TASK_START 'Container %(cn)d Task Address Space Region Start'
|
||||
CONT%(cn)d_PAGER_TASK_END 'Container %(cn)d Task Address Space Region End'
|
||||
CONT%(cn)d_PAGER_UTCB_START 'Container %(cn)d UTCB Mappings Region Start'
|
||||
CONT%(cn)d_PAGER_UTCB_END 'Container %(cn)d UTCB Mappings Region End'
|
||||
|
||||
CONT%(cn)d_LINUX_ZRELADDR 'Container %(cn)d Linux ZRELADDR parameter'
|
||||
CONT%(cn)d_LINUX_PAGE_OFFSET 'Container %(cn)d Linux PAGE_OFFSET Parameter'
|
||||
CONT%(cn)d_LINUX_PHYS_OFFSET 'Container %(cn)d Linux PHYS_OFFSET Parameter'
|
||||
CONT%(cn)d_LINUX_ROOTFS_ADDRESS 'Container %(cn)d Linux ROOTFS Address'
|
||||
CONT%(cn)d_LINUX_MAPSIZE 'Container %(cn)d Linux Initial Kernel Map Size Parameter'
|
||||
|
||||
default CONT%(cn)d_PAGER_LMA from 0x0
|
||||
@@ -53,9 +54,10 @@ default CONT%(cn)d_PAGER_TASK_START from 0x0
|
||||
default CONT%(cn)d_PAGER_TASK_END from 0x0
|
||||
default CONT%(cn)d_PAGER_UTCB_START from 0x0
|
||||
default CONT%(cn)d_PAGER_UTCB_END from 0x0
|
||||
|
||||
default CONT%(cn)d_LINUX_ZRELADDR from 0x0
|
||||
default CONT%(cn)d_LINUX_PAGE_OFFSET from 0x0
|
||||
default CONT%(cn)d_LINUX_PHYS_OFFSET from 0x0
|
||||
default CONT%(cn)d_LINUX_ROOTFS_ADDRESS from 0x0
|
||||
default CONT%(cn)d_LINUX_MAPSIZE from 0x0
|
||||
|
||||
default CONT%(cn)d_VIRTMEM_REGIONS from 1
|
||||
@@ -146,8 +148,10 @@ menu cont%(cn)d_posix_pager_params
|
||||
|
||||
|
||||
menu cont%(cn)d_linux_pager_params
|
||||
CONT%(cn)d_LINUX_ZRELADDR@
|
||||
CONT%(cn)d_LINUX_PAGE_OFFSET@
|
||||
CONT%(cn)d_LINUX_PHYS_OFFSET@
|
||||
CONT%(cn)d_LINUX_ROOTFS_ADDRESS@
|
||||
CONT%(cn)d_LINUX_MAPSIZE@
|
||||
|
||||
menu cont%(cn)d_virtmem_list
|
||||
|
||||
@@ -19,8 +19,10 @@ class Container:
|
||||
self.pager_shm_region_end = 0
|
||||
self.pager_utcb_region_start = 0
|
||||
self.pager_utcb_region_end = 0
|
||||
self.linux_zreladdr = 0
|
||||
self.linux_page_offset = 0
|
||||
self.linux_phys_offset = 0
|
||||
self.linux_rootfs_address = 0
|
||||
self.linux_mapsize = 0
|
||||
self.physmem = {}
|
||||
self.physmem["START"] = {}
|
||||
@@ -120,6 +122,10 @@ class configuration:
|
||||
elif param[:len("LINUX_PHYS_OFFSET")] == "LINUX_PHYS_OFFSET":
|
||||
self.containers[id].linux_phys_offset = int(val, 0)
|
||||
self.containers[id].pager_lma += int(val, 0)
|
||||
elif param[:len("LINUX_ZRELADDR")] == "LINUX_ZRELADDR":
|
||||
self.containers[id].linux_zreladdr = int(val, 0)
|
||||
elif param[:len("LINUX_ROOTFS_ADDRESS")] == "LINUX_ROOTFS_ADDRESS":
|
||||
self.containers[id].linux_rootfs_address += int(val, 0)
|
||||
elif re.match(r"(VIRT|PHYS){1}([0-9]){1}(_){1}(START|END){1}", param):
|
||||
matchobj = re.match(r"(VIRT|PHYS){1}([0-9]){1}(_){1}(START|END){1}", param)
|
||||
virtphys, regionidstr, discard1, startend = matchobj.groups()
|
||||
|
||||
@@ -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, \
|
||||
|
||||
@@ -16,6 +16,45 @@ PROJRELROOT = '../../'
|
||||
|
||||
from config.projpaths import *
|
||||
from scripts.loader.generate_loader_asm import *
|
||||
from config.lib import *
|
||||
|
||||
# Function to determine the LMA for 'final.elf'
|
||||
def find_lma_codezero(target, source, env):
|
||||
# Start/end addresses of various physical memory regions defined
|
||||
array_start = []
|
||||
array_end = []
|
||||
|
||||
with open(join(PROJROOT, CONFIG_H), 'r')as file:
|
||||
for line in file:
|
||||
begin = line.rfind(" ")
|
||||
end = len(line)
|
||||
if re.search("(PHYS)(.)(_START)", line):
|
||||
array_start.append(int(line[begin : end], 16))
|
||||
elif re.search("(PHYS)(.)(_END)", line):
|
||||
array_end.append(int(line[begin : end], 16))
|
||||
array_start.sort()
|
||||
array_end.sort()
|
||||
|
||||
# Size of physical memory hole we need for 'final.elf' say 16MB
|
||||
mem_needed = 0x1000000
|
||||
# Default LMA = 32MB, if we have no container
|
||||
loadaddr = 0x1000000
|
||||
for index,end in enumerate(array_end):
|
||||
loadaddr = end
|
||||
if (index+1) >= len(array_start):
|
||||
# Reached end of start_array
|
||||
break
|
||||
else:
|
||||
start = array_start[index+1]
|
||||
if start-end >= mem_needed:
|
||||
break
|
||||
|
||||
# Create target file
|
||||
with open(source[1].path, 'r') as input:
|
||||
buffer = input.read()
|
||||
print 'LMA FOR FINAL.ELF IS : ' + str(conv_hex(loadaddr))
|
||||
with open(target[0].path, 'w+') as output:
|
||||
output.write(buffer % str(conv_hex(loadaddr)))
|
||||
|
||||
def ksym_to_loader(target, source, env):
|
||||
generate_ksym_to_loader(target[0].path, source[0].path)
|
||||
@@ -26,10 +65,13 @@ def gen_loader_images_S(target, source, env):
|
||||
loader_ksyms = Command(join(PROJROOT, 'loader/ksyms.S'), join(BUILDDIR, 'kernel.elf'), ksym_to_loader)
|
||||
loader_image_S = Command(join(PROJROOT, 'loader/images.S'), [join(BUILDDIR, 'kernel.elf'), join(BUILDDIR, 'conts/containers.elf')], \
|
||||
gen_loader_images_S)
|
||||
|
||||
lma_lds = Command(join(BUILDDIR, 'loader/linker.lds'), \
|
||||
[join(BUILDDIR, 'kernel.elf'), \
|
||||
join(PROJROOT, 'loader/linker.lds.in')], find_lma_codezero)
|
||||
src = Glob('*.[cS]')
|
||||
objs = env.Object(src)
|
||||
|
||||
Depends(src, lma_lds)
|
||||
Depends(src, loader_ksyms)
|
||||
Depends(src, loader_image_S)
|
||||
Depends(objs, join(BUILDDIR, 'conts/containers.elf'))
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
*
|
||||
* Copyright (C) 2008-2009 B Labs Ltd.
|
||||
*/
|
||||
|
||||
lma_codezero = %s;
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x3000000;
|
||||
. = lma_codezero;
|
||||
.text : { *(.text.head) *(.text) }
|
||||
.rodata : { *(.rodata) }
|
||||
.rodata1 : { *(.rodata1) }
|
||||
@@ -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):
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -60,6 +60,7 @@ cinfo_end = \
|
||||
pager_start = \
|
||||
'''
|
||||
\t\t[0] = {
|
||||
\t\t\t.start_address = (CONFIG_CONT%d_INIT_PROG_COUNTER),
|
||||
\t\t\t.pager_lma = __pfn(CONFIG_CONT%d_PAGER_LMA),
|
||||
\t\t\t.pager_vma = __pfn(CONFIG_CONT%d_PAGER_VMA),
|
||||
\t\t\t.pager_size = __pfn(CONFIG_CONT%d_PAGER_SIZE),
|
||||
@@ -170,9 +171,14 @@ pager_ifdefs_todotext = \
|
||||
pager_ifdefs = \
|
||||
'''
|
||||
#if defined(CONFIG_CONT%(cn)d_TYPE_LINUX)
|
||||
#define CONFIG_CONT%(cn)d_PAGER_LMA (CONFIG_CONT%(cn)d_LINUX_PHYS_OFFSET + CONFIG_CONT%(cn)d_LINUX_TEXT_OFFSET)
|
||||
#define CONFIG_CONT%(cn)d_PAGER_VMA (CONFIG_CONT%(cn)d_LINUX_PAGE_OFFSET + CONFIG_CONT%(cn)d_LINUX_TEXT_OFFSET)
|
||||
#define CONFIG_CONT%(cn)d_INIT_PROG_COUNTER \
|
||||
(CONFIG_CONT%(cn)d_LINUX_ZRELADDR - CONFIG_CONT%(cn)d_LINUX_PHYS_OFFSET + \
|
||||
CONFIG_CONT%(cn)d_LINUX_PAGE_OFFSET)
|
||||
#define CONFIG_CONT%(cn)d_PAGER_LMA (CONFIG_CONT%(cn)d_LINUX_PHYS_OFFSET)
|
||||
#define CONFIG_CONT%(cn)d_PAGER_VMA (CONFIG_CONT%(cn)d_LINUX_PAGE_OFFSET)
|
||||
#define CONFIG_CONT%(cn)d_PAGER_SIZE CONFIG_CONT%(cn)d_LINUX_MAPSIZE
|
||||
#else
|
||||
#define CONFIG_CONT%(cn)d_INIT_PROG_COUNTER (CONFIG_CONT%(cn)d_PAGER_VMA)
|
||||
#endif
|
||||
'''
|
||||
def generate_pager_memory_ifdefs(containers):
|
||||
@@ -183,7 +189,7 @@ def generate_pager_memory_ifdefs(containers):
|
||||
if linux == 0:
|
||||
pager_ifdef_string += pager_ifdefs_todotext
|
||||
linux = 1
|
||||
pager_ifdef_string += pager_ifdefs % { 'cn' : c.id }
|
||||
pager_ifdef_string += pager_ifdefs % { 'cn' : c.id }
|
||||
return pager_ifdef_string
|
||||
|
||||
def generate_kernel_cinfo(config, cinfo_path):
|
||||
@@ -202,7 +208,7 @@ def generate_kernel_cinfo(config, cinfo_path):
|
||||
# Currently only these are considered as capabilities
|
||||
total_caps = c.virt_regions + c.phys_regions + total_other_caps
|
||||
fbody += cinfo_start % (c.id, c.name)
|
||||
fbody += pager_start % (c.id, c.id, c.id, total_caps)
|
||||
fbody += pager_start % (c.id, c.id, c.id, c.id, total_caps)
|
||||
cap_index = 0
|
||||
for mem_index in range(c.virt_regions):
|
||||
fbody += cap_virtmem % { 'capidx' : cap_index, 'cn' : c.id, 'vn' : mem_index }
|
||||
|
||||
99
scripts/linux/build_atags.py
Executable file
99
scripts/linux/build_atags.py
Executable 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])
|
||||
@@ -5,7 +5,7 @@
|
||||
#
|
||||
# Copyright © 2009 B Labs Ltd
|
||||
#
|
||||
import os, sys, shelve
|
||||
import os, sys, shelve, string
|
||||
from os.path import join
|
||||
|
||||
PROJRELROOT = '../../'
|
||||
@@ -15,6 +15,7 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELR
|
||||
|
||||
from config.projpaths import *
|
||||
from config.configuration import *
|
||||
from config.lib import *
|
||||
|
||||
LINUX_KERNEL_BUILDDIR = join(BUILDDIR, os.path.relpath(LINUX_KERNELDIR, PROJROOT))
|
||||
|
||||
@@ -27,6 +28,150 @@ def source_to_builddir(srcdir, id):
|
||||
"cont" + str(id))
|
||||
return join(BUILDDIR, cont_builddir)
|
||||
|
||||
class LinuxUpdateKernel:
|
||||
|
||||
def __init__(self, container):
|
||||
# List for setting/unsetting .config params of linux
|
||||
self.config_param_list = \
|
||||
(['MAGIC_SYSRQ', 'SET'],['DEBUG_INFO', 'SET'])
|
||||
|
||||
# List of CPUIDs, to be used by linux based on codezero config
|
||||
self.cpuid_list = (['ARM926', '0x41069265'],)
|
||||
# List of ARCHIDs, to be used by linux based on codezero config
|
||||
self.archid_list = (['PB926', '0x183'],
|
||||
['AB926', '0x25E'],
|
||||
['PB1176', '0x5E0'],
|
||||
['REALVIEW_EB', '33B'],)
|
||||
|
||||
# Replace line(having input_pattern) in filename with new_data
|
||||
def replace_line(self, filename, input_pattern, new_data, prev_line):
|
||||
with open(filename, 'r+') as f:
|
||||
flag = 0
|
||||
temp = 0
|
||||
x = re.compile(input_pattern)
|
||||
for line in f:
|
||||
if '' != prev_line:
|
||||
if temp == prev_line and re.match(x, line):
|
||||
flag = 1
|
||||
break
|
||||
temp = line
|
||||
else:
|
||||
if re.match(x, line):
|
||||
flag = 1
|
||||
break
|
||||
|
||||
if flag == 0:
|
||||
print 'Warning: No match found for the parameter'
|
||||
return
|
||||
else:
|
||||
# Prevent recompilation in case kernel parameter is same
|
||||
if new_data != line:
|
||||
f.seek(0)
|
||||
l = f.read()
|
||||
|
||||
# Need to truncate file because, size of contents to be
|
||||
# written may be less than the size of original file.
|
||||
f.seek(0)
|
||||
f.truncate(0)
|
||||
|
||||
# Write back to file
|
||||
f.write(l.replace(line, new_data))
|
||||
|
||||
def update_kernel_params(self, container):
|
||||
# Update TEXT_START
|
||||
file = join(LINUX_KERNELDIR, 'arch/arm/boot/compressed/Makefile')
|
||||
param = str(conv_hex(container.linux_phys_offset))
|
||||
new_data = ('ZTEXTADDR' + '\t' + ':= ' + param + '\n')
|
||||
data_to_replace = "(ZTEXTADDR)(\t)(:= 0)"
|
||||
prev_line = ''
|
||||
self.replace_line(file, data_to_replace, new_data, prev_line)
|
||||
|
||||
# Update PHYS_OFFSET
|
||||
file = join(LINUX_KERNELDIR, 'arch/arm/mach-versatile/include/mach/memory.h')
|
||||
param = str(conv_hex(container.linux_phys_offset))
|
||||
new_data = ('#define PHYS_OFFSET UL(' + param + ')\n')
|
||||
data_to_replace = "(#define PHYS_OFFSET)"
|
||||
prev_line = ''
|
||||
self.replace_line(file, data_to_replace, new_data, prev_line)
|
||||
|
||||
# Update PAGE_OFFSET
|
||||
file = join(LINUX_KERNELDIR, 'arch/arm/Kconfig')
|
||||
param = str(conv_hex(container.linux_page_offset))
|
||||
new_data = ('\t' + 'default ' + param + '\n')
|
||||
data_to_replace = "(\t)(default )"
|
||||
prev_line = ('\t'+'default 0x80000000 if VMSPLIT_2G' + '\n')
|
||||
self.replace_line(file, data_to_replace, new_data, prev_line)
|
||||
|
||||
# Update ZRELADDR
|
||||
file = join(LINUX_KERNELDIR, 'arch/arm/mach-versatile/Makefile.boot')
|
||||
param = str(conv_hex(container.linux_zreladdr))
|
||||
new_data = (' zreladdr-y' + '\t' + ':= ' + param + '\n')
|
||||
data_to_replace = "(\s){3}(zreladdr-y)(\t)(:= )"
|
||||
prev_line = ''
|
||||
self.replace_line(file, data_to_replace, new_data, prev_line)
|
||||
|
||||
# Update ARCHID, CPUID and ATAGS ADDRESS
|
||||
def modify_register_values(self, container):
|
||||
# Patterns as defined in config.h
|
||||
cpuid_pattern = '#define CONFIG_CPU_'
|
||||
archid_pattern = '#define CONFIG_PLATFORM_'
|
||||
|
||||
config_h_path = join(PROJROOT, CONFIG_H)
|
||||
|
||||
for pattern in cpuid_pattern, archid_pattern:
|
||||
with open(config_h_path, 'r') as f:
|
||||
for line in f:
|
||||
start = string.find(line, pattern)
|
||||
if start == -1:
|
||||
continue
|
||||
else:
|
||||
end = start + len(pattern)
|
||||
start = end
|
||||
while line[end] != ' ':
|
||||
end = end + 1
|
||||
if pattern == cpuid_pattern:
|
||||
cpu_type = line[start:end]
|
||||
elif pattern == archid_pattern:
|
||||
arch_type = line[start:end]
|
||||
break
|
||||
for i in self.cpuid_list:
|
||||
if i[0] == cpu_type:
|
||||
cpuid = i[1]
|
||||
break
|
||||
for i in self.archid_list:
|
||||
if i[0] == arch_type:
|
||||
archid = i[1]
|
||||
break
|
||||
|
||||
file = join(LINUX_KERNELDIR, 'arch/arm/kernel/head.S')
|
||||
prev_line = ''
|
||||
new_data = ('cpuid: .word ' + cpuid + '\n')
|
||||
data_to_replace = "(cpuid:)"
|
||||
self.replace_line(file, data_to_replace, new_data, prev_line)
|
||||
|
||||
new_data = ('archid: .word ' + archid + '\n')
|
||||
data_to_replace = "(archid:)"
|
||||
self.replace_line(file, data_to_replace, new_data, prev_line)
|
||||
# Atags will be present at PHYS_OFFSET + 0x100(=256)
|
||||
new_data = ('atags: .word ' + \
|
||||
str(conv_hex(container.linux_phys_offset + 0x100)) + '\n')
|
||||
data_to_replace = "(atags:)"
|
||||
self.replace_line(file, data_to_replace, new_data, prev_line)
|
||||
|
||||
def modify_kernel_config(self):
|
||||
file = join(LINUX_KERNELDIR, 'arch/arm/configs/versatile_defconfig')
|
||||
for i in self.config_param_list:
|
||||
param = 'CONFIG_' + i[0]
|
||||
prev_line = ''
|
||||
if i[1] == 'SET':
|
||||
data_to_replace = ('# ' + param)
|
||||
new_data = (param + '=y' + '\n')
|
||||
else:
|
||||
data_to_replace = param
|
||||
new_data = ('# ' + param + ' is not set' + '\n')
|
||||
|
||||
self.replace_line(file, data_to_replace, new_data, prev_line)
|
||||
|
||||
class LinuxBuilder:
|
||||
|
||||
def __init__(self, pathdict, container):
|
||||
@@ -36,22 +181,55 @@ class LinuxBuilder:
|
||||
self.LINUX_KERNEL_BUILDDIR = \
|
||||
source_to_builddir(LINUX_KERNELDIR, container.id)
|
||||
|
||||
self.linux_lds_in = join(self.LINUX_KERNELDIR, "linux.lds.in")
|
||||
self.linux_lds_out = join(self.LINUX_KERNEL_BUILDDIR, "linux.lds")
|
||||
self.linux_S_in = join(self.LINUX_KERNELDIR, "linux.S.in")
|
||||
self.linux_S_out = join(self.LINUX_KERNEL_BUILDDIR, "linux.S")
|
||||
|
||||
self.linux_h_in = join(self.LINUX_KERNELDIR, "linux.h.in")
|
||||
self.linux_h_out = join(self.LINUX_KERNEL_BUILDDIR, "linux.h")
|
||||
|
||||
self.linux_elf_out = join(self.LINUX_KERNEL_BUILDDIR, "linux.elf")
|
||||
|
||||
self.container = container
|
||||
self.kernel_binary_image = \
|
||||
join(os.path.relpath(self.LINUX_KERNEL_BUILDDIR, LINUX_KERNELDIR), \
|
||||
"arch/arm/boot/Image")
|
||||
self.kernel_image = None
|
||||
self.kernel_updater = LinuxUpdateKernel(self.container)
|
||||
|
||||
def build_linux(self):
|
||||
print '\nBuilding the linux kernel...'
|
||||
os.chdir(self.LINUX_KERNELDIR)
|
||||
if not os.path.exists(self.LINUX_KERNEL_BUILDDIR):
|
||||
os.makedirs(self.LINUX_KERNEL_BUILDDIR)
|
||||
|
||||
self.kernel_updater.modify_kernel_config()
|
||||
self.kernel_updater.update_kernel_params(self.container)
|
||||
self.kernel_updater.modify_register_values(self.container)
|
||||
|
||||
os.system("make defconfig ARCH=arm O=" + self.LINUX_KERNEL_BUILDDIR)
|
||||
os.system("make ARCH=arm " + \
|
||||
"CROSS_COMPILE=arm-none-linux-gnueabi- O=" + \
|
||||
self.LINUX_KERNEL_BUILDDIR)
|
||||
|
||||
with open(self.linux_h_out, 'w+') as output:
|
||||
with open(self.linux_h_in, 'r') as input:
|
||||
output.write(input.read() % {'cn' : self.container.id})
|
||||
|
||||
with open(self.linux_S_in, 'r') as input:
|
||||
with open(self.linux_S_out, 'w+') as output:
|
||||
content = input.read() % self.kernel_binary_image
|
||||
output.write(content)
|
||||
|
||||
os.system("arm-none-linux-gnueabi-cpp -I%s -P %s > %s" % \
|
||||
(self.LINUX_KERNEL_BUILDDIR, self.linux_lds_in, \
|
||||
self.linux_lds_out))
|
||||
os.system("arm-none-linux-gnueabi-gcc -nostdlib -o %s -T%s %s" % \
|
||||
(self.linux_elf_out, self.linux_lds_out, self.linux_S_out))
|
||||
|
||||
# Get the kernel image path
|
||||
self.kernel_image = \
|
||||
join(self.LINUX_KERNEL_BUILDDIR, \
|
||||
'arch/arm/boot/compressed/vmlinux')
|
||||
self.kernel_image = self.linux_elf_out
|
||||
|
||||
print 'Done...'
|
||||
|
||||
|
||||
@@ -34,7 +34,12 @@ class RootfsBuilder:
|
||||
|
||||
self.rootfs_lds_in = join(self.LINUX_ROOTFSDIR, "rootfs.lds.in")
|
||||
self.rootfs_lds_out = join(self.LINUX_ROOTFS_BUILDDIR, "rootfs.lds")
|
||||
|
||||
self.rootfs_h_in = join(self.LINUX_ROOTFSDIR, "rootfs.h.in")
|
||||
self.rootfs_h_out = join(self.LINUX_ROOTFS_BUILDDIR, "rootfs.h")
|
||||
|
||||
self.rootfs_elf_out = join(self.LINUX_ROOTFS_BUILDDIR, "rootfs.elf")
|
||||
self.cont_id = container.id
|
||||
|
||||
def build_rootfs(self):
|
||||
print 'Building the root filesystem...'
|
||||
@@ -43,8 +48,14 @@ class RootfsBuilder:
|
||||
os.chdir(LINUX_ROOTFSDIR)
|
||||
if not os.path.exists(self.LINUX_ROOTFS_BUILDDIR):
|
||||
os.makedirs(self.LINUX_ROOTFS_BUILDDIR)
|
||||
os.system("arm-none-linux-gnueabi-cpp -P " + \
|
||||
"%s > %s" % (self.rootfs_lds_in, self.rootfs_lds_out))
|
||||
|
||||
with open(self.rootfs_h_out, 'w+') as output:
|
||||
with open(self.rootfs_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_ROOTFS_BUILDDIR, self.rootfs_lds_in, \
|
||||
self.rootfs_lds_out))
|
||||
os.system("arm-none-linux-gnueabi-gcc " + \
|
||||
"-nostdlib -o %s -T%s rootfs.S" % (self.rootfs_elf_out, \
|
||||
self.rootfs_lds_out))
|
||||
|
||||
@@ -105,7 +105,7 @@ int init_pager(struct pager *pager,
|
||||
}
|
||||
|
||||
/* Initialize ktcb */
|
||||
task_init_registers(task, pager->start_vma);
|
||||
task_init_registers(task, pager->start_address);
|
||||
|
||||
/* Initialize container/pager relationships */
|
||||
pager->tcb = task;
|
||||
|
||||
@@ -417,6 +417,7 @@ int copy_pager_info(struct pager *pager, struct pager_info *pinfo)
|
||||
struct capability *cap;
|
||||
struct cap_info *cap_info;
|
||||
|
||||
pager->start_address = pinfo->start_address;
|
||||
pager->start_lma = __pfn_to_addr(pinfo->pager_lma);
|
||||
pager->start_vma = __pfn_to_addr(pinfo->pager_vma);
|
||||
pager->memsize = __pfn_to_addr(pinfo->pager_size);
|
||||
|
||||
Reference in New Issue
Block a user