mirror of
https://github.com/drasko/codezero.git
synced 2026-01-20 23:03:16 +01:00
Initial commit
This commit is contained in:
123
tasks/bootdesc/SConstruct
Normal file
123
tasks/bootdesc/SConstruct
Normal file
@@ -0,0 +1,123 @@
|
||||
#
|
||||
# Build script to autogenerate a bootdesc image
|
||||
#
|
||||
# Copyright (C) 2007 Bahadir Balban
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from os.path import join
|
||||
|
||||
# The root directory of the repository where this file resides:
|
||||
project_root = "../.."
|
||||
tools_root = "../../tools"
|
||||
|
||||
kernel = join(project_root, "build/start.axf")
|
||||
mm0 = join(project_root, "tasks/mm0/mm0.axf")
|
||||
# fs0 = join(project_root, "tasks/fs0/fs0.axf")
|
||||
test0 = join(project_root, "tasks/test0/test0.axf")
|
||||
test1 = join(project_root, "tasks/test1/test1.axf")
|
||||
#blkdev0 = join(project_root, "tasks/fsbin/blkdev0.axf")
|
||||
|
||||
images = [kernel, mm0, test0, test1]
|
||||
autogen_templ = "bootdesc.c.append"
|
||||
|
||||
def get_image_name_start_end(image, target):
|
||||
'''
|
||||
Using readelf.py utility, extracts name, start, end triplet from an arm-elf image.
|
||||
'''
|
||||
rest, name = os.path.split(image)
|
||||
if name[-4] == ".":
|
||||
name = name[:-4]
|
||||
os.system(join(tools_root, "pyelf/readelf.py --lma-start-end " + \
|
||||
image + " > " + target))
|
||||
|
||||
bootdesc_template = \
|
||||
'''
|
||||
struct bootdesc bootdesc = {
|
||||
.desc_size = sizeof(struct bootdesc) + sizeof(struct svc_image) * %s,
|
||||
.total_images = %s,
|
||||
.images = {
|
||||
%s
|
||||
},
|
||||
};
|
||||
'''
|
||||
|
||||
images_template = \
|
||||
''' [%s] = {
|
||||
.name = "%s",
|
||||
.phys_start = %s,
|
||||
.phys_end = %s,
|
||||
},
|
||||
'''
|
||||
|
||||
images_template_end = \
|
||||
'''
|
||||
},
|
||||
'''
|
||||
|
||||
def generate_bootdesc(source, target, env):
|
||||
'''
|
||||
Extracts name, start, end information from the kernel and each svc task.
|
||||
Uses this information to produce bootdesc.c
|
||||
'''
|
||||
source.sort()
|
||||
images = []
|
||||
images_string = ""
|
||||
for node in source:
|
||||
if str(node)[-4:] == ".axf":
|
||||
rest, imgname = os.path.split(str(node))
|
||||
images.append((str(node), imgname[:-4]))
|
||||
elif str(node) [-6:] == ".templ":
|
||||
# Static template that has type definitions.
|
||||
#rest, original_template = os.path.split(str(node))
|
||||
original_template = str(node)
|
||||
index = 0
|
||||
for imgpath, imgname in images:
|
||||
get_image_name_start_end(imgpath, imgname + ".txt")
|
||||
if imgname != "start":
|
||||
f = open(imgname + ".txt", "r")
|
||||
svc_name = f.readline()[:-1]
|
||||
[start, startval] = str.split(f.readline()[:-1])
|
||||
[end, endval] = str.split(f.readline()[:-1])
|
||||
f.close()
|
||||
images_string += images_template % (str(index), svc_name, \
|
||||
hex(int(startval, 16)), hex(int(endval, 16)))
|
||||
index += 1
|
||||
|
||||
# Autogenerated template with actual data.
|
||||
autogen_template = open(autogen_templ, "w+")
|
||||
autogen_template.write(bootdesc_template % (str(index), str(index), images_string))
|
||||
autogen_template.close()
|
||||
|
||||
os.system("cat " + original_template + " > " + str(target[0]))
|
||||
os.system("cat " + autogen_templ + " >> " + str(target[0]))
|
||||
|
||||
def relocate_bootdesc(source, target, env):
|
||||
f = open("start.txt", "r")
|
||||
kernel_name = f.readline()[:-1]
|
||||
[start, startval] = str.split(f.readline()[:-1])
|
||||
[end, endval] = str.split(f.readline()[:-1])
|
||||
os.system("arm-none-linux-gnueabi-objcopy --adjust-section-vma .data=" + \
|
||||
hex(int(endval,16)) + " " + str(source[0]))
|
||||
os.system("mv " + str(source[0]) + " " + str(target[0]))
|
||||
# The kernel build environment:
|
||||
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
|
||||
# We don't use -nostdinc because sometimes we need standard headers,
|
||||
# such as stdarg.h e.g. for variable args, as in printk().
|
||||
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'],
|
||||
LINKFLAGS = ['-nostdlib','-Tlinker.lds'],
|
||||
ASFLAGS = ['-D__ASSEMBLY__'],
|
||||
PROGSUFFIX = '.axf', # The suffix to use for final executable
|
||||
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
|
||||
LIBS = 'gcc', # libgcc.a - This is required for division routines.
|
||||
CPPPATH = '#include') # `hash' ('#') is a shorthand meaning `relative to
|
||||
# the root directory'. But this only works for
|
||||
# well-defined variables, not all paths, and only
|
||||
# if we use a relative build directory for sources.
|
||||
|
||||
bootdesc_src = env.Command("bootdesc.c", ["bootdesc.c.templ"] + images, generate_bootdesc)
|
||||
objs = env.Object('bootdesc.c')
|
||||
bootdesc = env.Program('bootdesc_data', objs)
|
||||
bootdesc_relocated = env.Command("bootdesc.axf", "bootdesc_data.axf", relocate_bootdesc)
|
||||
env.Depends(bootdesc_relocated, bootdesc)
|
||||
23
tasks/bootdesc/bootdesc.c.append
Normal file
23
tasks/bootdesc/bootdesc.c.append
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
struct bootdesc bootdesc = {
|
||||
.desc_size = sizeof(struct bootdesc) + sizeof(struct svc_image) * 3,
|
||||
.total_images = 3,
|
||||
.images = {
|
||||
[0] = {
|
||||
.name = "mm0",
|
||||
.phys_start = 0x208000,
|
||||
.phys_end = 0x213140,
|
||||
},
|
||||
[1] = {
|
||||
.name = "test0",
|
||||
.phys_start = 0x218000,
|
||||
.phys_end = 0x21aedc,
|
||||
},
|
||||
[2] = {
|
||||
.name = "romfs",
|
||||
.phys_start = 0x220000,
|
||||
.phys_end = 0x268800,
|
||||
},
|
||||
|
||||
},
|
||||
};
|
||||
39
tasks/bootdesc/bootdesc.c.orig
Normal file
39
tasks/bootdesc/bootdesc.c.orig
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
|
||||
/* Supervisor task at load time. */
|
||||
struct svc_image {
|
||||
char name[16];
|
||||
unsigned int phys_start;
|
||||
unsigned int phys_end;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
/* Supervisor task descriptor at load time */
|
||||
struct bootdesc {
|
||||
int desc_size;
|
||||
int total_images;
|
||||
struct svc_image images[];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
|
||||
struct bootdesc bootdesc = {
|
||||
.desc_size = sizeof(struct bootdesc) + sizeof(struct svc_image) * 3,
|
||||
.total_images = 3,
|
||||
.images = {
|
||||
[0] = {
|
||||
.name = "inittask",
|
||||
.phys_start = 0x208000,
|
||||
.phys_end = 0x213260,
|
||||
},
|
||||
[1] = {
|
||||
.name = "roottask",
|
||||
.phys_start = 0x218000,
|
||||
.phys_end = 0x21b344,
|
||||
},
|
||||
[2] = {
|
||||
.name = "testtask",
|
||||
.phys_start = 0x220000,
|
||||
.phys_end = 0x223344,
|
||||
},
|
||||
|
||||
},
|
||||
};
|
||||
16
tasks/bootdesc/bootdesc.c.templ
Normal file
16
tasks/bootdesc/bootdesc.c.templ
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
/* Supervisor task at load time. */
|
||||
struct svc_image {
|
||||
char name[16];
|
||||
unsigned int phys_start;
|
||||
unsigned int phys_end;
|
||||
} __attribute__((__packed__));
|
||||
|
||||
/* Supervisor task descriptor at load time */
|
||||
struct bootdesc {
|
||||
int desc_size;
|
||||
int total_images;
|
||||
struct svc_image images[];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
3
tasks/bootdesc/fs0.txt
Normal file
3
tasks/bootdesc/fs0.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
fs0
|
||||
image_start 0x218000
|
||||
image_end 0x21B26C
|
||||
3
tasks/bootdesc/inittask.txt
Normal file
3
tasks/bootdesc/inittask.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
inittask
|
||||
image_start 0x208000
|
||||
image_end 0x213260
|
||||
8
tasks/bootdesc/linker.lds
Normal file
8
tasks/bootdesc/linker.lds
Normal file
@@ -0,0 +1,8 @@
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
_start = .;
|
||||
.data : { *(.data) }
|
||||
_end = .;
|
||||
}
|
||||
3
tasks/bootdesc/mm0.txt
Normal file
3
tasks/bootdesc/mm0.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
mm0
|
||||
image_start 0x208000
|
||||
image_end 0x213140
|
||||
3
tasks/bootdesc/romfs.txt
Normal file
3
tasks/bootdesc/romfs.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
romfs
|
||||
image_start 0x220000
|
||||
image_end 0x268800
|
||||
3
tasks/bootdesc/roottask.txt
Normal file
3
tasks/bootdesc/roottask.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
roottask
|
||||
image_start 0x218000
|
||||
image_end 0x21B344
|
||||
3
tasks/bootdesc/start.txt
Normal file
3
tasks/bootdesc/start.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
start
|
||||
image_start 0x100000
|
||||
image_end 0x205800
|
||||
3
tasks/bootdesc/test0.txt
Normal file
3
tasks/bootdesc/test0.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
test0
|
||||
image_start 0x218000
|
||||
image_end 0x21AEDC
|
||||
3
tasks/bootdesc/testtask.txt
Normal file
3
tasks/bootdesc/testtask.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
testtask
|
||||
image_start 0x220000
|
||||
image_end 0x223344
|
||||
Reference in New Issue
Block a user