From 1d1f09ded60a653898820b0223f67d74dfe18997 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Sat, 28 Nov 2009 14:38:15 +0530 Subject: [PATCH 1/6] Dyamic addition/deletion of baremetal projects to codezero --- config/configuration.py | 5 +- scripts/baremetal/baremetal_add_container.py | 155 +++++++++++++++++++ 2 files changed, 156 insertions(+), 4 deletions(-) create mode 100755 scripts/baremetal/baremetal_add_container.py diff --git a/config/configuration.py b/config/configuration.py index 735e281..66dd477 100644 --- a/config/configuration.py +++ b/config/configuration.py @@ -131,10 +131,7 @@ class configuration: # TODO: Carry this over to Container() as static method??? def get_container_parameter(self, id, param, val): - if param[:len("SOURCE_PATH")] == "SOURCE_PATH": - parts = val.split("\"", 3) - self.containers[id].src_path = parts[1] - elif param[:len("PAGER_LMA")] == "PAGER_LMA": + if param[:len("PAGER_LMA")] == "PAGER_LMA": self.containers[id].pager_lma = int(val, 0) elif param[:len("PAGER_VMA")] == "PAGER_VMA": self.containers[id].pager_vma = int(val, 0) diff --git a/scripts/baremetal/baremetal_add_container.py b/scripts/baremetal/baremetal_add_container.py new file mode 100755 index 0000000..aba431f --- /dev/null +++ b/scripts/baremetal/baremetal_add_container.py @@ -0,0 +1,155 @@ +#! /usr/bin/env python2.6 +# -*- mode: python; coding: utf-8; -*- +# +# Script to add/remove project to baremetal +# menu of main screen +# +# This script should be called from project root directory +# +import os, sys, shutil, re +from optparse import OptionParser +from os.path import join +from shutil import copytree + +def parse_cmdline_options(): + usage = "usage: %prog [options] arg" + parser = OptionParser(usage) + + parser.add_option("-a", "--add", action = "store_true", default = False, + dest = "addproject", help = "Add new project to baremetal projects") + parser.add_option("-d", "--del", action = "store_true", default = False, + dest = "delproject", help = "Delete existing project from baremetal projects") + parser.add_option("--desc", type = "string", dest = "projdesc", + help = "Description to be used for newly added project") + parser.add_option("--id", type = "int", dest = "srcid", + help = "If used with -a, Baremetal container id, to be used as source for source project\ + If used with -d, Baremetal container id to be deleted") + + (options, args) = parser.parse_args() + + # Sanity checks + if (not options.addproject and not options.delproject) or \ + (options.addproject and options.delproject): + parser.error("Only one of -a or -d needed, use -h argument for help") + exit() + + if options.addproject: + add_del = 1 + if not options.projdesc or not options.srcid: + parser.error("--desc or --id missing, use -h argument for help") + exit() + + if options.delproject: + add_del = 0 + if options.projdesc or not options.srcid: + parser.error("--desc provided or --id missing with -d, use -h argument for help") + exit() + + return options.projdesc, options.srcid, add_del + +def container_cml_templ_del_symbl(srcid): + cont_templ = "config/cml/container_ruleset.template" + sym = "CONT%(cn)d_BAREMETAL_PROJ" + str(srcid) + + buffer = "" + with open(cont_templ, 'r') as fin: + exist = False + # Prepare buffer for new cont_templ with new project symbols added + for line in fin: + parts = line.split() + + # Find out where baremetal symbols start in cont_templ + if len(parts) > 1 and parts[0] == sym: + exist = True + continue + elif len(parts) == 1 and parts[0] == sym: + continue + + buffer += line + if exist == False: + print "Project named baremetal" + str(srcid) + " does not exist" + exit() + + # Write new cont_templ + with open(cont_templ, 'w+') as fout: + fout.write(buffer) + + +def container_cml_templ_add_symbl(projdesc): + cont_templ = "config/cml/container_ruleset.template" + + pattern = re.compile("(CONT\%\(cn\)d_BAREMETAL_PROJ)([0-9]*)") + new_sym = "CONT%(cn)d_BAREMETAL_PROJ" + + # ID for new project + projid = -1 + + buffer = "" + with open(cont_templ, 'r') as fin: + baremetal_sym_found = False + + # Prepare buffer for new cont_templ with new project symbols added + for line in fin: + parts = line.split() + + # Find out where baremetal symbols start in cont_templ + if len(parts) > 1 and re.match(pattern, parts[0]): + baremetal_sym_found = True + # Last project id in use for baremetal conts + projid = \ + int(parts[0][len("CONT%(cn)d_BAREMETAL_PROJ"):]) + + # We are done with baremetal symbols, add new symbol to buffer + elif baremetal_sym_found == True: + baremetal_sym_found = False + sym_def = new_sym + str(int(projid) + 1) + \ + "\t\'" + projdesc + "\'\n" + buffer += sym_def + + # Search for baremetal menu and add new project symbol + elif len(parts) == 1 and parts[0] == new_sym + str(projid): + sym_reference = "\t" + new_sym + str(projid + 1) + "\n" + line += sym_reference + + buffer += line + + # Write new cont_templ + with open(cont_templ, 'w+') as fout: + fout.write(buffer) + + return projid + 1 + +def add_project(projdesc, srcid): + dest_id = container_cml_templ_add_symbl(projdesc) + + baremetal_dir = "conts/baremetal" + src_dir = join(baremetal_dir, "baremetal" + str(srcid)) + dest_dir = join(baremetal_dir, "baremetal" + str(dest_id)) + + print "Copying source files from " + src_dir + " to " + dest_dir + shutil.copytree(src_dir, dest_dir) + print "Done, New project baremetal" +str(dest_id) + \ + " is ready to be used." + +def del_project(srcid): + container_cml_templ_del_symbl(srcid) + + baremetal_dir = "conts/baremetal" + src_dir = join(baremetal_dir, "baremetal" + str(srcid)) + + print "Deleting source files from " + src_dir + shutil.rmtree(src_dir, "ignore_errors") + print "Done.." + +def main(): + projdesc, srcid, add_del = parse_cmdline_options() + + if add_del == 1: + add_project(projdesc, srcid) + else: + del_project(srcid) + + +if __name__ == "__main__": + main() + From 6e3e11d37e62590046b9a51ade7c1d370d726628 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Mon, 30 Nov 2009 15:46:13 +0530 Subject: [PATCH 2/6] Default values for various posix regions derived --- config/cml/container_ruleset.template | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index 9dba643..12ce414 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -47,12 +47,12 @@ CONT%(cn)d_LINUX_ROOTFS_ADDRESS 'Container %(cn)d Linux ROOTFS Address' default CONT%(cn)d_PAGER_LMA from CONT%(cn)d_PHYS0_START default CONT%(cn)d_PAGER_VMA from CONT%(cn)d_VIRT0_START -default CONT%(cn)d_PAGER_SHM_START from 0x40000000 -default CONT%(cn)d_PAGER_SHM_END from 0x50000000 -default CONT%(cn)d_PAGER_TASK_START from 0x30000000 -default CONT%(cn)d_PAGER_TASK_END from 0x40000000 -default CONT%(cn)d_PAGER_UTCB_START from 0xf8100000 -default CONT%(cn)d_PAGER_UTCB_END from 0xf8200000 +default CONT%(cn)d_PAGER_SHM_START from CONT%(cn)d_VIRT1_START +default CONT%(cn)d_PAGER_SHM_END from CONT%(cn)d_VIRT1_END +default CONT%(cn)d_PAGER_TASK_START from CONT%(cn)d_VIRT2_START +default CONT%(cn)d_PAGER_TASK_END from CONT%(cn)d_VIRT2_END +default CONT%(cn)d_PAGER_UTCB_START from CONT%(cn)d_VIRT3_START +default CONT%(cn)d_PAGER_UTCB_END from CONT%(cn)d_VIRT3_END default CONT%(cn)d_LINUX_ZRELADDR from (CONT%(cn)d_LINUX_PHYS_OFFSET + 0x8000) default CONT%(cn)d_LINUX_PAGE_OFFSET from CONT%(cn)d_VIRT0_START default CONT%(cn)d_LINUX_PHYS_OFFSET from CONT%(cn)d_PHYS0_START From 3caa43d756afc992d93d0e168b98d17816fef432 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Mon, 30 Nov 2009 19:22:27 +0530 Subject: [PATCH 3/6] Restrictions on naming of baremetal containers removed and we have an automation script for integrating containers in baremetal/ --- config/cml/container_ruleset.template | 38 +++++--- config/configuration.py | 12 +-- conts/baremetal/baremetal5/include/test.h | 0 .../{baremetal0 => empty}/SConstruct | 0 .../{baremetal0 => empty}/container.c | 0 .../{baremetal0 => empty}/include/test.h | 0 conts/baremetal/{baremetal0 => empty}/main.c | 0 .../{baremetal0 => empty}/src/test.c | 0 .../{baremetal1 => hello_world}/SConstruct | 0 .../{baremetal1 => hello_world}/container.c | 0 .../{baremetal1 => hello_world}/hello.c | 0 .../include/test.h | 0 .../{baremetal1 => hello_world}/main.c | 0 .../{baremetal1 => hello_world}/src/test.c | 0 .../baremetal/{baremetal2 => test}/SConstruct | 0 .../{baremetal2 => test}/container.c | 0 .../{baremetal2 => test}/include/test.h | 0 conts/baremetal/{baremetal2 => test}/main.c | 0 .../{baremetal3 => threads_demo}/SConstruct | 0 .../{baremetal3 => threads_demo}/container.c | 0 .../include/capability.h | 0 .../include/tests.h | 0 .../include/thread.h | 0 .../{baremetal3 => threads_demo}/main.c | 0 .../{baremetal3 => threads_demo}/src/arch | 0 .../src/arch-arm/new_thread.S | 0 .../src/capability.c | 0 .../src/captest.c | 0 .../src/example.c | 0 .../{baremetal3 => threads_demo}/src/thread.c | 0 .../{baremetal5 => timer_service}/SConstruct | 0 .../{baremetal5 => timer_service}/container.c | 0 .../include/capability.h | 0 .../include/container.h | 0 .../include/linker.h | 0 .../{baremetal5 => timer_service}/main.c | 0 .../{baremetal4 => timer_service}/src/test.c | 0 .../{baremetal4 => uart_service}/SConstruct | 0 .../{baremetal4 => uart_service}/container.c | 0 .../include/capability.h | 0 .../include/container.h | 0 .../include/linker.h | 0 .../{baremetal4 => uart_service}/main.c | 0 .../{baremetal5 => uart_service}/src/test.c | 0 scripts/baremetal/baremetal_add_container.py | 93 +++++++++++-------- scripts/baremetal/baremetal_generator.py | 7 +- 46 files changed, 83 insertions(+), 67 deletions(-) delete mode 100644 conts/baremetal/baremetal5/include/test.h rename conts/baremetal/{baremetal0 => empty}/SConstruct (100%) rename conts/baremetal/{baremetal0 => empty}/container.c (100%) rename conts/baremetal/{baremetal0 => empty}/include/test.h (100%) rename conts/baremetal/{baremetal0 => empty}/main.c (100%) rename conts/baremetal/{baremetal0 => empty}/src/test.c (100%) rename conts/baremetal/{baremetal1 => hello_world}/SConstruct (100%) rename conts/baremetal/{baremetal1 => hello_world}/container.c (100%) rename conts/baremetal/{baremetal1 => hello_world}/hello.c (100%) rename conts/baremetal/{baremetal1 => hello_world}/include/test.h (100%) rename conts/baremetal/{baremetal1 => hello_world}/main.c (100%) rename conts/baremetal/{baremetal1 => hello_world}/src/test.c (100%) rename conts/baremetal/{baremetal2 => test}/SConstruct (100%) rename conts/baremetal/{baremetal2 => test}/container.c (100%) rename conts/baremetal/{baremetal2 => test}/include/test.h (100%) rename conts/baremetal/{baremetal2 => test}/main.c (100%) rename conts/baremetal/{baremetal3 => threads_demo}/SConstruct (100%) rename conts/baremetal/{baremetal3 => threads_demo}/container.c (100%) rename conts/baremetal/{baremetal3 => threads_demo}/include/capability.h (100%) rename conts/baremetal/{baremetal3 => threads_demo}/include/tests.h (100%) rename conts/baremetal/{baremetal3 => threads_demo}/include/thread.h (100%) rename conts/baremetal/{baremetal3 => threads_demo}/main.c (100%) rename conts/baremetal/{baremetal3 => threads_demo}/src/arch (100%) rename conts/baremetal/{baremetal3 => threads_demo}/src/arch-arm/new_thread.S (100%) rename conts/baremetal/{baremetal3 => threads_demo}/src/capability.c (100%) rename conts/baremetal/{baremetal3 => threads_demo}/src/captest.c (100%) rename conts/baremetal/{baremetal3 => threads_demo}/src/example.c (100%) rename conts/baremetal/{baremetal3 => threads_demo}/src/thread.c (100%) rename conts/baremetal/{baremetal5 => timer_service}/SConstruct (100%) rename conts/baremetal/{baremetal5 => timer_service}/container.c (100%) rename conts/baremetal/{baremetal4 => timer_service}/include/capability.h (100%) rename conts/baremetal/{baremetal5 => timer_service}/include/container.h (100%) rename conts/baremetal/{baremetal4 => timer_service}/include/linker.h (100%) rename conts/baremetal/{baremetal5 => timer_service}/main.c (100%) rename conts/baremetal/{baremetal4 => timer_service}/src/test.c (100%) rename conts/baremetal/{baremetal4 => uart_service}/SConstruct (100%) rename conts/baremetal/{baremetal4 => uart_service}/container.c (100%) rename conts/baremetal/{baremetal5 => uart_service}/include/capability.h (100%) rename conts/baremetal/{baremetal4 => uart_service}/include/container.h (100%) rename conts/baremetal/{baremetal5 => uart_service}/include/linker.h (100%) rename conts/baremetal/{baremetal4 => uart_service}/main.c (100%) rename conts/baremetal/{baremetal5 => uart_service}/src/test.c (100%) diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index 12ce414..fbf3899 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -128,7 +128,15 @@ default CONT%(cn)d_VIRT4_END from (CONT%(cn)d_VIRT4_START + 0x10000000) default CONT%(cn)d_VIRT5_START from 0xe0000000 default CONT%(cn)d_VIRT5_END from 0xf0000000 -default CONT%(cn)d_OPT_NAME from (CONT%(cn)d_TYPE_LINUX==y) ? "linux%(cn)d" : ((CONT%(cn)d_TYPE_BAREMETAL==y) ? "baremetal%(cn)d" : "posix%(cn)d") +derive baremetal%(cn)d from +(CONT%(cn)d_BAREMETAL_PROJ_EMPTY==y) ? "empty%(cn)d" : +((CONT%(cn)d_BAREMETAL_PROJ_HELLO_WORLD==y) ? "hello_world%(cn)d" : +((CONT%(cn)d_BAREMETAL_PROJ_THREADS_DEMO==y) ? "thread_demo%(cn)d" : +((CONT%(cn)d_BAREMETAL_PROJ_TEST==y) ? "test%(cn)d" : +((CONT%(cn)d_BAREMETAL_PROJ_UART_SERVICE==y) ? "uart_service%(cn)d" : +((CONT%(cn)d_BAREMETAL_PROJ_TIMER_SERVICE==y) ? "timer_service%(cn)d" : "baremetal_noname%(cn)d" ))))) + +default CONT%(cn)d_OPT_NAME from (CONT%(cn)d_TYPE_LINUX==y) ? "linux%(cn)d" : ((CONT%(cn)d_TYPE_BAREMETAL==y) ? baremetal%(cn)d : "posix%(cn)d") when CONT%(cn)d_TYPE_LINUX==y suppress cont%(cn)d_default_pager_params unless CONT%(cn)d_TYPE_POSIX==y suppress cont%(cn)d_posix_pager_params @@ -152,22 +160,22 @@ cont%(cn)d_linux_pager_params 'Container %(cn)d Linux Pager Parameters' cont%(cn)d_default_pager_params 'Container %(cn)d Default Pager Parameters' cont%(cn)d_posix_pager_params 'Container %(cn)d POSIX Pager Parameters' -cont%(cn)d_baremetal_params 'Baremetal Project' -CONT%(cn)d_BAREMETAL_PROJ0 'Empty Project' -CONT%(cn)d_BAREMETAL_PROJ1 'Hello World' -CONT%(cn)d_BAREMETAL_PROJ2 'Thread Library Demo' -CONT%(cn)d_BAREMETAL_PROJ3 'Test Project' -CONT%(cn)d_BAREMETAL_PROJ4 'UART Service' -CONT%(cn)d_BAREMETAL_PROJ5 'Timer Service' +cont%(cn)d_baremetal_params 'Baremetal Project' +CONT%(cn)d_BAREMETAL_PROJ_EMPTY 'Empty Project' +CONT%(cn)d_BAREMETAL_PROJ_HELLO_WORLD 'Hello World' +CONT%(cn)d_BAREMETAL_PROJ_THREADS_DEMO 'Thread Library Demo' +CONT%(cn)d_BAREMETAL_PROJ_TEST 'Test Project' +CONT%(cn)d_BAREMETAL_PROJ_UART_SERVICE 'UART Service' +CONT%(cn)d_BAREMETAL_PROJ_TIMER_SERVICE 'Timer Service' choices cont%(cn)d_baremetal_params - CONT%(cn)d_BAREMETAL_PROJ0 - CONT%(cn)d_BAREMETAL_PROJ1 - CONT%(cn)d_BAREMETAL_PROJ2 - CONT%(cn)d_BAREMETAL_PROJ3 - CONT%(cn)d_BAREMETAL_PROJ4 - CONT%(cn)d_BAREMETAL_PROJ5 - default CONT%(cn)d_BAREMETAL_PROJ0 + CONT%(cn)d_BAREMETAL_PROJ_EMPTY + CONT%(cn)d_BAREMETAL_PROJ_HELLO_WORLD + CONT%(cn)d_BAREMETAL_PROJ_THREADS_DEMO + CONT%(cn)d_BAREMETAL_PROJ_TEST + CONT%(cn)d_BAREMETAL_PROJ_UART_SERVICE + CONT%(cn)d_BAREMETAL_PROJ_TIMER_SERVICE + default CONT%(cn)d_BAREMETAL_PROJ_EMPTY menu cont%(cn)d_default_pager_params CONT%(cn)d_PAGER_LMA@ diff --git a/config/configuration.py b/config/configuration.py index 66dd477..c749e5b 100644 --- a/config/configuration.py +++ b/config/configuration.py @@ -12,7 +12,6 @@ class Container: self.name = None self.type = None self.id = id - self.baremetal_id = 0 self.pager_lma = 0 self.pager_vma = 0 self.pager_size = 0 @@ -170,12 +169,11 @@ class configuration: if regionid + 1 > self.containers[id].phys_regions: self.containers[id].phys_regions = regionid + 1 elif param[:len("OPT_NAME")] == "OPT_NAME": - dirname = val[1:-1].lower() - self.containers[id].dirname = dirname - self.containers[id].name = dirname - elif param[:len("BAREMETAL_PROJ")] == "BAREMETAL_PROJ": - param1 = param.split("_", 1) - self.containers[id].baremetal_id = param1[1][-1:] + name = val[1:-1].lower() + self.containers[id].name = name + elif param[:len("BAREMETAL_PROJ_")] == "BAREMETAL_PROJ_": + param1 = param.split("_", 2) + self.containers[id].dirname = param1[2].lower() elif param[:len("CAP_")] == "CAP_": prefix, param_rest = param.split('_', 1) prepare_capability(self.containers[id], param_rest, val) diff --git a/conts/baremetal/baremetal5/include/test.h b/conts/baremetal/baremetal5/include/test.h deleted file mode 100644 index e69de29..0000000 diff --git a/conts/baremetal/baremetal0/SConstruct b/conts/baremetal/empty/SConstruct similarity index 100% rename from conts/baremetal/baremetal0/SConstruct rename to conts/baremetal/empty/SConstruct diff --git a/conts/baremetal/baremetal0/container.c b/conts/baremetal/empty/container.c similarity index 100% rename from conts/baremetal/baremetal0/container.c rename to conts/baremetal/empty/container.c diff --git a/conts/baremetal/baremetal0/include/test.h b/conts/baremetal/empty/include/test.h similarity index 100% rename from conts/baremetal/baremetal0/include/test.h rename to conts/baremetal/empty/include/test.h diff --git a/conts/baremetal/baremetal0/main.c b/conts/baremetal/empty/main.c similarity index 100% rename from conts/baremetal/baremetal0/main.c rename to conts/baremetal/empty/main.c diff --git a/conts/baremetal/baremetal0/src/test.c b/conts/baremetal/empty/src/test.c similarity index 100% rename from conts/baremetal/baremetal0/src/test.c rename to conts/baremetal/empty/src/test.c diff --git a/conts/baremetal/baremetal1/SConstruct b/conts/baremetal/hello_world/SConstruct similarity index 100% rename from conts/baremetal/baremetal1/SConstruct rename to conts/baremetal/hello_world/SConstruct diff --git a/conts/baremetal/baremetal1/container.c b/conts/baremetal/hello_world/container.c similarity index 100% rename from conts/baremetal/baremetal1/container.c rename to conts/baremetal/hello_world/container.c diff --git a/conts/baremetal/baremetal1/hello.c b/conts/baremetal/hello_world/hello.c similarity index 100% rename from conts/baremetal/baremetal1/hello.c rename to conts/baremetal/hello_world/hello.c diff --git a/conts/baremetal/baremetal1/include/test.h b/conts/baremetal/hello_world/include/test.h similarity index 100% rename from conts/baremetal/baremetal1/include/test.h rename to conts/baremetal/hello_world/include/test.h diff --git a/conts/baremetal/baremetal1/main.c b/conts/baremetal/hello_world/main.c similarity index 100% rename from conts/baremetal/baremetal1/main.c rename to conts/baremetal/hello_world/main.c diff --git a/conts/baremetal/baremetal1/src/test.c b/conts/baremetal/hello_world/src/test.c similarity index 100% rename from conts/baremetal/baremetal1/src/test.c rename to conts/baremetal/hello_world/src/test.c diff --git a/conts/baremetal/baremetal2/SConstruct b/conts/baremetal/test/SConstruct similarity index 100% rename from conts/baremetal/baremetal2/SConstruct rename to conts/baremetal/test/SConstruct diff --git a/conts/baremetal/baremetal2/container.c b/conts/baremetal/test/container.c similarity index 100% rename from conts/baremetal/baremetal2/container.c rename to conts/baremetal/test/container.c diff --git a/conts/baremetal/baremetal2/include/test.h b/conts/baremetal/test/include/test.h similarity index 100% rename from conts/baremetal/baremetal2/include/test.h rename to conts/baremetal/test/include/test.h diff --git a/conts/baremetal/baremetal2/main.c b/conts/baremetal/test/main.c similarity index 100% rename from conts/baremetal/baremetal2/main.c rename to conts/baremetal/test/main.c diff --git a/conts/baremetal/baremetal3/SConstruct b/conts/baremetal/threads_demo/SConstruct similarity index 100% rename from conts/baremetal/baremetal3/SConstruct rename to conts/baremetal/threads_demo/SConstruct diff --git a/conts/baremetal/baremetal3/container.c b/conts/baremetal/threads_demo/container.c similarity index 100% rename from conts/baremetal/baremetal3/container.c rename to conts/baremetal/threads_demo/container.c diff --git a/conts/baremetal/baremetal3/include/capability.h b/conts/baremetal/threads_demo/include/capability.h similarity index 100% rename from conts/baremetal/baremetal3/include/capability.h rename to conts/baremetal/threads_demo/include/capability.h diff --git a/conts/baremetal/baremetal3/include/tests.h b/conts/baremetal/threads_demo/include/tests.h similarity index 100% rename from conts/baremetal/baremetal3/include/tests.h rename to conts/baremetal/threads_demo/include/tests.h diff --git a/conts/baremetal/baremetal3/include/thread.h b/conts/baremetal/threads_demo/include/thread.h similarity index 100% rename from conts/baremetal/baremetal3/include/thread.h rename to conts/baremetal/threads_demo/include/thread.h diff --git a/conts/baremetal/baremetal3/main.c b/conts/baremetal/threads_demo/main.c similarity index 100% rename from conts/baremetal/baremetal3/main.c rename to conts/baremetal/threads_demo/main.c diff --git a/conts/baremetal/baremetal3/src/arch b/conts/baremetal/threads_demo/src/arch similarity index 100% rename from conts/baremetal/baremetal3/src/arch rename to conts/baremetal/threads_demo/src/arch diff --git a/conts/baremetal/baremetal3/src/arch-arm/new_thread.S b/conts/baremetal/threads_demo/src/arch-arm/new_thread.S similarity index 100% rename from conts/baremetal/baremetal3/src/arch-arm/new_thread.S rename to conts/baremetal/threads_demo/src/arch-arm/new_thread.S diff --git a/conts/baremetal/baremetal3/src/capability.c b/conts/baremetal/threads_demo/src/capability.c similarity index 100% rename from conts/baremetal/baremetal3/src/capability.c rename to conts/baremetal/threads_demo/src/capability.c diff --git a/conts/baremetal/baremetal3/src/captest.c b/conts/baremetal/threads_demo/src/captest.c similarity index 100% rename from conts/baremetal/baremetal3/src/captest.c rename to conts/baremetal/threads_demo/src/captest.c diff --git a/conts/baremetal/baremetal3/src/example.c b/conts/baremetal/threads_demo/src/example.c similarity index 100% rename from conts/baremetal/baremetal3/src/example.c rename to conts/baremetal/threads_demo/src/example.c diff --git a/conts/baremetal/baremetal3/src/thread.c b/conts/baremetal/threads_demo/src/thread.c similarity index 100% rename from conts/baremetal/baremetal3/src/thread.c rename to conts/baremetal/threads_demo/src/thread.c diff --git a/conts/baremetal/baremetal5/SConstruct b/conts/baremetal/timer_service/SConstruct similarity index 100% rename from conts/baremetal/baremetal5/SConstruct rename to conts/baremetal/timer_service/SConstruct diff --git a/conts/baremetal/baremetal5/container.c b/conts/baremetal/timer_service/container.c similarity index 100% rename from conts/baremetal/baremetal5/container.c rename to conts/baremetal/timer_service/container.c diff --git a/conts/baremetal/baremetal4/include/capability.h b/conts/baremetal/timer_service/include/capability.h similarity index 100% rename from conts/baremetal/baremetal4/include/capability.h rename to conts/baremetal/timer_service/include/capability.h diff --git a/conts/baremetal/baremetal5/include/container.h b/conts/baremetal/timer_service/include/container.h similarity index 100% rename from conts/baremetal/baremetal5/include/container.h rename to conts/baremetal/timer_service/include/container.h diff --git a/conts/baremetal/baremetal4/include/linker.h b/conts/baremetal/timer_service/include/linker.h similarity index 100% rename from conts/baremetal/baremetal4/include/linker.h rename to conts/baremetal/timer_service/include/linker.h diff --git a/conts/baremetal/baremetal5/main.c b/conts/baremetal/timer_service/main.c similarity index 100% rename from conts/baremetal/baremetal5/main.c rename to conts/baremetal/timer_service/main.c diff --git a/conts/baremetal/baremetal4/src/test.c b/conts/baremetal/timer_service/src/test.c similarity index 100% rename from conts/baremetal/baremetal4/src/test.c rename to conts/baremetal/timer_service/src/test.c diff --git a/conts/baremetal/baremetal4/SConstruct b/conts/baremetal/uart_service/SConstruct similarity index 100% rename from conts/baremetal/baremetal4/SConstruct rename to conts/baremetal/uart_service/SConstruct diff --git a/conts/baremetal/baremetal4/container.c b/conts/baremetal/uart_service/container.c similarity index 100% rename from conts/baremetal/baremetal4/container.c rename to conts/baremetal/uart_service/container.c diff --git a/conts/baremetal/baremetal5/include/capability.h b/conts/baremetal/uart_service/include/capability.h similarity index 100% rename from conts/baremetal/baremetal5/include/capability.h rename to conts/baremetal/uart_service/include/capability.h diff --git a/conts/baremetal/baremetal4/include/container.h b/conts/baremetal/uart_service/include/container.h similarity index 100% rename from conts/baremetal/baremetal4/include/container.h rename to conts/baremetal/uart_service/include/container.h diff --git a/conts/baremetal/baremetal5/include/linker.h b/conts/baremetal/uart_service/include/linker.h similarity index 100% rename from conts/baremetal/baremetal5/include/linker.h rename to conts/baremetal/uart_service/include/linker.h diff --git a/conts/baremetal/baremetal4/main.c b/conts/baremetal/uart_service/main.c similarity index 100% rename from conts/baremetal/baremetal4/main.c rename to conts/baremetal/uart_service/main.c diff --git a/conts/baremetal/baremetal5/src/test.c b/conts/baremetal/uart_service/src/test.c similarity index 100% rename from conts/baremetal/baremetal5/src/test.c rename to conts/baremetal/uart_service/src/test.c diff --git a/scripts/baremetal/baremetal_add_container.py b/scripts/baremetal/baremetal_add_container.py index aba431f..0beb599 100755 --- a/scripts/baremetal/baremetal_add_container.py +++ b/scripts/baremetal/baremetal_add_container.py @@ -7,9 +7,14 @@ # This script should be called from project root directory # import os, sys, shutil, re + +PROJRELROOT = '../../' +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT))) + from optparse import OptionParser from os.path import join from shutil import copytree +from config.projpaths import * def parse_cmdline_options(): usage = "usage: %prog [options] arg" @@ -19,11 +24,11 @@ def parse_cmdline_options(): dest = "addproject", help = "Add new project to baremetal projects") parser.add_option("-d", "--del", action = "store_true", default = False, dest = "delproject", help = "Delete existing project from baremetal projects") - parser.add_option("--desc", type = "string", dest = "projdesc", - help = "Description to be used for newly added project") - parser.add_option("--id", type = "int", dest = "srcid", - help = "If used with -a, Baremetal container id, to be used as source for source project\ - If used with -d, Baremetal container id to be deleted") + parser.add_option("-i", "--desc", type = "string", dest = "projdesc", + help = "Description of new project to be added") + parser.add_option("-s", "--src", type = "string", dest = "srcpath", + help = "With -a, Source directory for new project to be added \ + With -d, Source directory of baremetal project to be deleted") (options, args) = parser.parse_args() @@ -35,21 +40,21 @@ def parse_cmdline_options(): if options.addproject: add_del = 1 - if not options.projdesc or not options.srcid: - parser.error("--desc or --id missing, use -h argument for help") + if not options.projdesc or not options.srcpath: + parser.error("--desc or --src missing, use -h argument for help") exit() if options.delproject: add_del = 0 - if options.projdesc or not options.srcid: - parser.error("--desc provided or --id missing with -d, use -h argument for help") + if options.projdesc or not options.srcpath: + parser.error("--desc provided or --src missing with -d, use -h argument for help") exit() - return options.projdesc, options.srcid, add_del + return options.projdesc, options.srcpath, add_del -def container_cml_templ_del_symbl(srcid): +def container_cml_templ_del_symbl(projname): cont_templ = "config/cml/container_ruleset.template" - sym = "CONT%(cn)d_BAREMETAL_PROJ" + str(srcid) + sym = "CONT%(cn)d_BAREMETAL_PROJ_" + projname.upper() buffer = "" with open(cont_templ, 'r') as fin: @@ -67,7 +72,7 @@ def container_cml_templ_del_symbl(srcid): buffer += line if exist == False: - print "Project named baremetal" + str(srcid) + " does not exist" + print "Baremetal project named " + projname + " does not exist" exit() # Write new cont_templ @@ -75,18 +80,17 @@ def container_cml_templ_del_symbl(srcid): fout.write(buffer) -def container_cml_templ_add_symbl(projdesc): +def container_cml_templ_add_symbl(projdesc, projname): cont_templ = "config/cml/container_ruleset.template" - pattern = re.compile("(CONT\%\(cn\)d_BAREMETAL_PROJ)([0-9]*)") - new_sym = "CONT%(cn)d_BAREMETAL_PROJ" - - # ID for new project - projid = -1 + pattern = re.compile("(CONT\%\(cn\)d_BAREMETAL_PROJ_)(.*)") + baremetal_name_templ = "CONT%(cn)d_BAREMETAL_PROJ_" + new_sym = baremetal_name_templ + projname.upper() buffer = "" with open(cont_templ, 'r') as fin: baremetal_sym_found = False + last_baremetal_proj = "" # Prepare buffer for new cont_templ with new project symbols added for line in fin: @@ -95,20 +99,20 @@ def container_cml_templ_add_symbl(projdesc): # Find out where baremetal symbols start in cont_templ if len(parts) > 1 and re.match(pattern, parts[0]): baremetal_sym_found = True - # Last project id in use for baremetal conts - projid = \ - int(parts[0][len("CONT%(cn)d_BAREMETAL_PROJ"):]) + + # Find the name of last baremetal project already present in list + last_baremetal_proj = parts[0][len(baremetal_name_templ):] # We are done with baremetal symbols, add new symbol to buffer elif baremetal_sym_found == True: baremetal_sym_found = False - sym_def = new_sym + str(int(projid) + 1) + \ - "\t\'" + projdesc + "\'\n" + sym_def = new_sym + "\t\'" + projdesc + "\'\n" buffer += sym_def # Search for baremetal menu and add new project symbol - elif len(parts) == 1 and parts[0] == new_sym + str(projid): - sym_reference = "\t" + new_sym + str(projid + 1) + "\n" + elif len(parts) == 1 and \ + parts[0] == baremetal_name_templ + last_baremetal_proj: + sym_reference = "\t" + new_sym + "\n" line += sym_reference buffer += line @@ -117,38 +121,45 @@ def container_cml_templ_add_symbl(projdesc): with open(cont_templ, 'w+') as fout: fout.write(buffer) - return projid + 1 - -def add_project(projdesc, srcid): - dest_id = container_cml_templ_add_symbl(projdesc) +def add_project(projdesc, srcdir, projname): + container_cml_templ_add_symbl(projdesc, projname) baremetal_dir = "conts/baremetal" - src_dir = join(baremetal_dir, "baremetal" + str(srcid)) - dest_dir = join(baremetal_dir, "baremetal" + str(dest_id)) + dest_dir = join(baremetal_dir, projname) - print "Copying source files from " + src_dir + " to " + dest_dir - shutil.copytree(src_dir, dest_dir) - print "Done, New project baremetal" +str(dest_id) + \ + print "Copying source files from " + srcdir + " to " + dest_dir + shutil.copytree(srcdir, dest_dir) + print "Done, New baremetal project " + projname + \ " is ready to be used." -def del_project(srcid): - container_cml_templ_del_symbl(srcid) +def del_project(srcdir, projname): + container_cml_templ_del_symbl(projname) baremetal_dir = "conts/baremetal" - src_dir = join(baremetal_dir, "baremetal" + str(srcid)) + src_dir = join(baremetal_dir, projname) print "Deleting source files from " + src_dir shutil.rmtree(src_dir, "ignore_errors") print "Done.." def main(): - projdesc, srcid, add_del = parse_cmdline_options() + projdesc, srcdir, add_del = parse_cmdline_options() + + # Get the base directory + projpath, projname = os.path.split(srcdir) + + # Python's basename() doesnot work fine if path ends with /, + # so we need to manually correct this + if projname == "": + projpath, projname = os.path.split(projpath) if add_del == 1: - add_project(projdesc, srcid) + add_project(projdesc, srcdir, projname) else: - del_project(srcid) + del_project(srcdir, projname) + # Delete the config.cml file, so that user can see new projects + os.system("rm -f " + CML2_CONFIG_FILE) if __name__ == "__main__": main() diff --git a/scripts/baremetal/baremetal_generator.py b/scripts/baremetal/baremetal_generator.py index 2702720..4887e96 100755 --- a/scripts/baremetal/baremetal_generator.py +++ b/scripts/baremetal/baremetal_generator.py @@ -49,8 +49,7 @@ class BaremetalContGenerator: def create_baremetal_srctree(self, config, cont): # First, create the base project directory and sources - str = 'baremetal' + cont.baremetal_id - shutil.copytree(join(self.BAREMETAL_PROJ_SRC_DIR, str), self.CONT_SRC_DIR) + shutil.copytree(join(self.BAREMETAL_PROJ_SRC_DIR, cont.dirname), self.CONT_SRC_DIR) def copy_baremetal_build_desc(self, config, cont): id_header = '[Container ID]\n' @@ -114,7 +113,7 @@ class BaremetalContGenerator: for cont in config.containers: if cont.type == "baremetal": # Determine container directory name. - self.CONT_SRC_DIR = join(self.BAREMETAL_SRC_BASEDIR, cont.dirname.lower()) + self.CONT_SRC_DIR = join(self.BAREMETAL_SRC_BASEDIR, cont.name.lower()) self.build_readme_out = join(self.CONT_SRC_DIR, self.build_readme_name) self.build_desc_out = join(self.CONT_SRC_DIR, self.build_desc_name) self.linker_lds_out = join(join(self.CONT_SRC_DIR, 'include'), \ @@ -122,7 +121,7 @@ class BaremetalContGenerator: self.container_h_out = join(join(self.CONT_SRC_DIR, 'include'), \ self.container_h_name) - if not os.path.exists(join(self.BAREMETAL_SRC_BASEDIR, cont.dirname)): + if not os.path.exists(join(self.BAREMETAL_SRC_BASEDIR, cont.name)): self.create_baremetal_sources(config, cont) else: # Don't create new sources but update configuration From cf9f3aab5b47708cfe92ee8cd916445d9301ecd9 Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Tue, 1 Dec 2009 23:31:23 +0530 Subject: [PATCH 4/6] Timer service enhanced for sleep --- conts/baremetal/timer_service/include/timer.h | 36 +++++++++ conts/baremetal/timer_service/main.c | 76 ++++++++++++++++--- .../libdev/timer/sp804/include/sp804_timer.h | 4 - conts/libdev/timer/sp804/src/sp804_timer.c | 3 + 4 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 conts/baremetal/timer_service/include/timer.h diff --git a/conts/baremetal/timer_service/include/timer.h b/conts/baremetal/timer_service/include/timer.h new file mode 100644 index 0000000..260b57b --- /dev/null +++ b/conts/baremetal/timer_service/include/timer.h @@ -0,0 +1,36 @@ +#ifndef __TIMER_H__ +#define __TIMER_H__ + +/* + * Timer specific things are here + */ +#include +#include + +/* + * Structure representing the sleeping tasks, + * tgid: tgid of sleeping task + * wait_count: time left, in microseconds, after which task + * will be signalled to get out of sleep + */ +struct timer_task { + struct link list; + l4id_t tgid; + unsigned int wait_count; +}; + +/* + * Timer structure, + * base: base address of sp804 timer encapsulated + * count: Count in microseconds from the start of this timer + * tasklist: list of tasks sleeping for some value of count + * lock: lock protecting the corruption of tasklist + */ +struct sp804_timer { + unsigned int base; + unsigned int count; + struct link tasklist; + struct l4_mutex lock; +}; + +#endif /* __TIMER_H__ */ diff --git a/conts/baremetal/timer_service/main.c b/conts/baremetal/timer_service/main.c index c95c7f8..02f53df 100644 --- a/conts/baremetal/timer_service/main.c +++ b/conts/baremetal/timer_service/main.c @@ -9,11 +9,12 @@ #include #include +#include #include #include #include "sp804_timer.h" #include - +#include /* Frequency of timer in MHz */ #define TIMER_FREQUENCY 1 @@ -148,11 +149,31 @@ int timer_probe_devices(void) static struct sp804_timer timer[TIMERS_TOTAL]; +struct timer_task *get_timer_task(l4id_t tgid) +{ + /* May be we can prepare a cache for timer_task structs */ + struct timer_task *task = (struct timer_task *)kzalloc(sizeof(struct timer_task)); + + link_init(&task->list); + task->tgid = tgid; + task->wait_count = timer[0].count; + + return task; +} + +void free_timer_task(struct timer_task *task) +{ + kfree(task); +} + int timer_setup_devices(void) { for (int i = 0; i < TIMERS_TOTAL; i++) { /* Get one page from address pool */ timer[i].base = (unsigned long)l4_new_virtual(1); + timer[i].count = 0; + link_init(&timer[i].tasklist); + l4_mutex_init(&timer[i].lock); /* Map timers to a virtual address region */ if (IS_ERR(l4_map((void *)__pfn_to_addr(timer_cap[i].start), @@ -166,10 +187,12 @@ int timer_setup_devices(void) } /* Initialise timer */ - sp804_init(timer[i].base, SP804_TIMER_RUNMODE_FREERUN, \ + sp804_init(timer[i].base, SP804_TIMER_RUNMODE_PERIODIC, \ SP804_TIMER_WRAPMODE_WRAPPING, SP804_TIMER_WIDTH32BIT, \ SP804_TIMER_IRQDISABLE); + /* Request IRQ for this timer */ + /* Enable Timer */ sp804_enable(timer[i].base, 1); } @@ -226,18 +249,48 @@ void *l4_new_virtual(int npages) return address_new(&device_vaddr_pool, npages, PAGE_SIZE); } -int timer_gettime(int devno) +void timer_irq_handler(void) { - return sp804_read_value(timer[devno].base); + struct timer_task *struct_ptr, *temp_ptr; + + timer[0].count += 1; + + /* + * FIXME: + * Traverse through the sleeping process list and + * wake any process if required, we need to put this part in bottom half + */ + list_foreach_removable_struct(struct_ptr, temp_ptr, &timer[0].tasklist, list) + if (struct_ptr->wait_count == timer[0].count) { + + /* Remove task from list */ + l4_mutex_lock(&timer[0].lock); + list_remove(&struct_ptr->list); + l4_mutex_unlock(&timer[0].lock); + + /* wake the sleeping process, send wake ipc */ + + free_timer_task(struct_ptr); + } } -void timer_sleep(int sec) +int timer_gettime(void) { - /* - * TODO: We need to have a timer struct already present to be used - * as reference for us. to implement this call - */ + return timer[0].count; } + +void timer_sleep(l4id_t tgid, int sec) +{ + struct timer_task *task = get_timer_task(tgid); + + /* Check for overflow */ + task->wait_count += (sec * 1000000); + + l4_mutex_lock(&timer[0].lock); + list_insert_tail(&task->list, &timer[0].tasklist); + l4_mutex_unlock(&timer[0].lock); +} + void handle_requests(void) { u32 mr[MR_UNUSED_TOTAL]; @@ -273,11 +326,12 @@ void handle_requests(void) */ switch (tag) { case L4_IPC_TAG_TIMER_GETTIME: - timer_gettime(1); + mr[0] = timer_gettime(); break; case L4_IPC_TAG_TIMER_SLEEP: - timer_sleep(mr[0]); + timer_sleep(senderid, mr[0]); + /* TODO: Halt the caller for mr[0] seconds */ break; default: diff --git a/conts/libdev/timer/sp804/include/sp804_timer.h b/conts/libdev/timer/sp804/include/sp804_timer.h index 0da6d15..d7929a0 100644 --- a/conts/libdev/timer/sp804/include/sp804_timer.h +++ b/conts/libdev/timer/sp804/include/sp804_timer.h @@ -56,10 +56,6 @@ #define SP804_TIMERMIS 0x14 #define SP804_TIMERBGLOAD 0x18 -struct sp804_timer { - unsigned int base; -}; - void sp804_init(unsigned int timer_base, int runmode, int wrapmode, \ int width, int irq_enable); void sp804_irq_handler(unsigned int timer_base); diff --git a/conts/libdev/timer/sp804/src/sp804_timer.c b/conts/libdev/timer/sp804/src/sp804_timer.c index cbb8c11..690fb9a 100644 --- a/conts/libdev/timer/sp804/src/sp804_timer.c +++ b/conts/libdev/timer/sp804/src/sp804_timer.c @@ -10,6 +10,8 @@ #define setbit(bit, a) write(read(a) | bit, a) #define clrbit(bit, a) write(read(a) & ~bit, a) +extern void timer_irq_handler(void); + void sp804_irq_handler(unsigned int timer_base) { /* @@ -17,6 +19,7 @@ void sp804_irq_handler(unsigned int timer_base) * as it automatically reloads and wraps */ write(1, (timer_base + SP804_TIMERINTCLR)); + timer_irq_handler(); } static inline void sp804_control(unsigned int timer_base, int bit, int setclr) From fcc1e52bea3010e6179c993dbb6d0d9dea1fd62b Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Wed, 2 Dec 2009 00:14:32 +0530 Subject: [PATCH 5/6] Test and Threads_demo containers interchanged by mistake earlier. Corrected --- conts/baremetal/test/SConstruct | 40 ++--- .../include/capability.h | 0 .../{threads_demo => test}/include/tests.h | 0 .../{threads_demo => test}/include/thread.h | 0 conts/baremetal/test/main.c | 139 +++++++----------- .../baremetal/{threads_demo => test}/src/arch | 0 .../src/arch-arm/new_thread.S | 0 .../{threads_demo => test}/src/capability.c | 0 .../{threads_demo => test}/src/captest.c | 0 .../{threads_demo => test}/src/example.c | 0 .../{threads_demo => test}/src/thread.c | 0 conts/baremetal/threads_demo/SConstruct | 40 +++-- .../{test => threads_demo}/include/test.h | 0 conts/baremetal/threads_demo/main.c | 139 +++++++++++------- 14 files changed, 179 insertions(+), 179 deletions(-) rename conts/baremetal/{threads_demo => test}/include/capability.h (100%) rename conts/baremetal/{threads_demo => test}/include/tests.h (100%) rename conts/baremetal/{threads_demo => test}/include/thread.h (100%) rename conts/baremetal/{threads_demo => test}/src/arch (100%) rename conts/baremetal/{threads_demo => test}/src/arch-arm/new_thread.S (100%) rename conts/baremetal/{threads_demo => test}/src/capability.c (100%) rename conts/baremetal/{threads_demo => test}/src/captest.c (100%) rename conts/baremetal/{threads_demo => test}/src/example.c (100%) rename conts/baremetal/{threads_demo => test}/src/thread.c (100%) rename conts/baremetal/{test => threads_demo}/include/test.h (100%) diff --git a/conts/baremetal/test/SConstruct b/conts/baremetal/test/SConstruct index b497069..3d615b2 100644 --- a/conts/baremetal/test/SConstruct +++ b/conts/baremetal/test/SConstruct @@ -13,10 +13,11 @@ sys.path.append(PROJRELROOT) from config.projpaths import * from config.configuration import * +from config.lib import * config = configuration_retrieve() -platform = config.platform arch = config.arch +platform = config.platform gcc_cpu_flag = config.gcc_cpu_flag LIBL4_RELDIR = 'conts/libl4' @@ -38,32 +39,19 @@ LIBDEV_LIBPATH = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-userspace') LIBDEV_INCLUDE = [join(LIBDEV_DIR, 'uart/include')] LIBDEV_CCFLAGS = '-DPLATFORM_' + platform.upper() -LIBL4THREAD_RELDIR = 'conts/libl4thread' -LIBL4THREAD_DIR = join(PROJROOT, LIBL4THREAD_RELDIR) -LIBL4THREAD_LIBPATH = join(BUILDDIR, LIBL4THREAD_RELDIR) -LIBL4THREAD_INCLUDE = join(LIBL4THREAD_DIR, 'include') - -LIBMEM_RELDIR = 'conts/libmem' -LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR) -LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR) -LIBMEM_INCLUDE = LIBMEM_DIR - env = Environment(CC = config.user_toolchain + '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', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS], - LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"], - ASFLAGS = ['-D__ASSEMBLY__'], - PROGSUFFIX = '.elf', # The suffix to use for final executable - ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path - LIBS = ['libl4thread', 'libl4', 'libmalloc', 'c-userspace', \ - 'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines. - CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, \ - LIBC_INCLUDE, LIBL4THREAD_INCLUDE], - LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH, LIBL4THREAD_LIBPATH, \ - LIBMEM_LIBPATH], - CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h') + # 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', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS], + LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],\ + ASFLAGS = ['-D__ASSEMBLY__'], \ + PROGSUFFIX = '.elf', # The suffix to use for final executable\ + ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path\ + LIBS = ['gcc', 'libl4', 'c-userspace', 'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines. + CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, LIBC_INCLUDE], + LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH], + CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h') src = Glob('*.[cS]') src += Glob('src/*.[cS]') diff --git a/conts/baremetal/threads_demo/include/capability.h b/conts/baremetal/test/include/capability.h similarity index 100% rename from conts/baremetal/threads_demo/include/capability.h rename to conts/baremetal/test/include/capability.h diff --git a/conts/baremetal/threads_demo/include/tests.h b/conts/baremetal/test/include/tests.h similarity index 100% rename from conts/baremetal/threads_demo/include/tests.h rename to conts/baremetal/test/include/tests.h diff --git a/conts/baremetal/threads_demo/include/thread.h b/conts/baremetal/test/include/thread.h similarity index 100% rename from conts/baremetal/threads_demo/include/thread.h rename to conts/baremetal/test/include/thread.h diff --git a/conts/baremetal/test/main.c b/conts/baremetal/test/main.c index 272021e..aaa03ed 100644 --- a/conts/baremetal/test/main.c +++ b/conts/baremetal/test/main.c @@ -1,115 +1,80 @@ /* - * Main function for this container + * Main function for all tests + * + * Copyright (C) 2009 B Labs Ltd. */ +#include +#include +#include +#include +#include #include #include #include -#include -/* Symbolic constants */ -#define STACK_SIZE 0x1000 -#define NTHREADS 10 -/* Stack and utcb region */ -static char stack[NTHREADS * STACK_SIZE]; -DECLARE_UTCB_SPACE(utcb, NTHREADS) - -/* Function definitions */ -static void init_thread_lib(void) +int exit_test_thread(void *arg) { - /* Thread lib is informed about the stack region. */ - l4_set_stack_params((unsigned long)stack, - (unsigned long)(stack + sizeof(stack)), - STACK_SIZE); - - /* Thread lib is informed about the utcb region. */ - l4_set_utcb_params((unsigned long)utcb, - (unsigned long)(utcb + sizeof(utcb))); - - /* Now, we are ready to make calls to the library. */ -} - -static int do_some_work1(void *arg) -{ - struct task_ids ids; - int value = *(int *)arg; - int j; - - l4_getid(&ids); - printf("tid = %d is called with the value of (%d).\n", - __raw_tid(ids.tid), value); - - /* Wait for a while before exiting */ - j = 0x400000; - while (--j) + while (1) ; - - return ids.tid; -} - -static int do_some_work2(void *arg) -{ - struct task_ids ids; - int value = *(int *)arg; - int j; - - l4_getid(&ids); - printf("tid = %d is called with the value of (%d).\n", - __raw_tid(ids.tid), value); - - /* Wait for a while before exiting */ - j = 0x400000; - while (--j) - ; - - l4_thread_exit(ids.tid); - - /* Should never reach here */ + //l4_thread_switch(0); + //l4_exit(5); return 0; } -static int thread_demo(void) +int exit_test(void) { - struct task_ids ids[NTHREADS]; - int arg[NTHREADS]; - int j; + int ret; + struct task_ids ids; - memset(ids, 0, sizeof(ids)); + /* Create and run a new thread */ + if ((ret = thread_create(exit_test_thread, 0, + TC_SHARE_SPACE | TC_AS_PAGER, + &ids)) < 0) { + printf("Top-level simple_pager creation failed.\n"); + goto out_err; + } else + printf("Thread (%d) created successfully.\n", ids.tid); - /* Create threads. */ - for (int i = 0; i < NTHREADS; ++i) { - /* The argument passed to the thread in question. */ - arg[i] = i; + // l4_thread_switch(0); - /* Threads are created. */ - if (i % 2) - l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER, - do_some_work1, (void *)&arg[i]); - else - l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER, - do_some_work2, (void *)&arg[i]); + /* Kill it */ + printf("Killing Thread (%d).\n", ids.tid); + if ((ret = l4_thread_control(THREAD_DESTROY, &ids)) < 0) + printf("Error: Killing Thread (%d), err = %d\n", ids.tid, ret); + else + printf("Success: Killed Thread (%d)\n", ids.tid); - /* Wait for a while before launching another thread. */ - j = 0x100000; - while (--j) - ; - } - /* Wait for them to exit. */ - for (int i = 0; i < NTHREADS; ++i) - printf("tid = %d exited with (%d).\n", __raw_tid(ids[i].tid), - l4_thread_control(THREAD_WAIT, &ids[i])); +#if 0 + /* Wait on it */ + printf("Waiting on Thread (%d) to exit.\n", ids.tid); + if ((ret = l4_thread_control(THREAD_WAIT, &ids)) >= 0) + printf("Success. Paged child returned %d\n", ret); + else + printf("Error. Wait on (%d) failed. err = %d\n", + ids.tid, ret); +#endif return 0; +out_err: + BUG(); } int main(void) { - /* Before using the thread lib, we have to initialize it. */ - init_thread_lib(); + printf("%s: Container %s started\n", + __CONTAINER__, __CONTAINER_NAME__); - /* Demonstrates the usage of the thread lib. */ - thread_demo(); + capability_test(); + + //exit_test(); + + /* Now quit to demo self-paging quit */ + //l4_exit(0); + + /* Now quit by null pointer */ + // *((int *)0) = 5; return 0; } diff --git a/conts/baremetal/threads_demo/src/arch b/conts/baremetal/test/src/arch similarity index 100% rename from conts/baremetal/threads_demo/src/arch rename to conts/baremetal/test/src/arch diff --git a/conts/baremetal/threads_demo/src/arch-arm/new_thread.S b/conts/baremetal/test/src/arch-arm/new_thread.S similarity index 100% rename from conts/baremetal/threads_demo/src/arch-arm/new_thread.S rename to conts/baremetal/test/src/arch-arm/new_thread.S diff --git a/conts/baremetal/threads_demo/src/capability.c b/conts/baremetal/test/src/capability.c similarity index 100% rename from conts/baremetal/threads_demo/src/capability.c rename to conts/baremetal/test/src/capability.c diff --git a/conts/baremetal/threads_demo/src/captest.c b/conts/baremetal/test/src/captest.c similarity index 100% rename from conts/baremetal/threads_demo/src/captest.c rename to conts/baremetal/test/src/captest.c diff --git a/conts/baremetal/threads_demo/src/example.c b/conts/baremetal/test/src/example.c similarity index 100% rename from conts/baremetal/threads_demo/src/example.c rename to conts/baremetal/test/src/example.c diff --git a/conts/baremetal/threads_demo/src/thread.c b/conts/baremetal/test/src/thread.c similarity index 100% rename from conts/baremetal/threads_demo/src/thread.c rename to conts/baremetal/test/src/thread.c diff --git a/conts/baremetal/threads_demo/SConstruct b/conts/baremetal/threads_demo/SConstruct index 3d615b2..b497069 100644 --- a/conts/baremetal/threads_demo/SConstruct +++ b/conts/baremetal/threads_demo/SConstruct @@ -13,11 +13,10 @@ sys.path.append(PROJRELROOT) from config.projpaths import * from config.configuration import * -from config.lib import * config = configuration_retrieve() -arch = config.arch platform = config.platform +arch = config.arch gcc_cpu_flag = config.gcc_cpu_flag LIBL4_RELDIR = 'conts/libl4' @@ -39,19 +38,32 @@ LIBDEV_LIBPATH = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-userspace') LIBDEV_INCLUDE = [join(LIBDEV_DIR, 'uart/include')] LIBDEV_CCFLAGS = '-DPLATFORM_' + platform.upper() +LIBL4THREAD_RELDIR = 'conts/libl4thread' +LIBL4THREAD_DIR = join(PROJROOT, LIBL4THREAD_RELDIR) +LIBL4THREAD_LIBPATH = join(BUILDDIR, LIBL4THREAD_RELDIR) +LIBL4THREAD_INCLUDE = join(LIBL4THREAD_DIR, 'include') + +LIBMEM_RELDIR = 'conts/libmem' +LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR) +LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR) +LIBMEM_INCLUDE = LIBMEM_DIR + env = Environment(CC = config.user_toolchain + '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', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS], - LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],\ - ASFLAGS = ['-D__ASSEMBLY__'], \ - PROGSUFFIX = '.elf', # The suffix to use for final executable\ - ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path\ - LIBS = ['gcc', 'libl4', 'c-userspace', 'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines. - CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, LIBC_INCLUDE], - LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH], - CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h') + # 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', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS], + LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"], + ASFLAGS = ['-D__ASSEMBLY__'], + PROGSUFFIX = '.elf', # The suffix to use for final executable + ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path + LIBS = ['libl4thread', 'libl4', 'libmalloc', 'c-userspace', \ + 'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines. + CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, \ + LIBC_INCLUDE, LIBL4THREAD_INCLUDE], + LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH, LIBL4THREAD_LIBPATH, \ + LIBMEM_LIBPATH], + CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h') src = Glob('*.[cS]') src += Glob('src/*.[cS]') diff --git a/conts/baremetal/test/include/test.h b/conts/baremetal/threads_demo/include/test.h similarity index 100% rename from conts/baremetal/test/include/test.h rename to conts/baremetal/threads_demo/include/test.h diff --git a/conts/baremetal/threads_demo/main.c b/conts/baremetal/threads_demo/main.c index aaa03ed..272021e 100644 --- a/conts/baremetal/threads_demo/main.c +++ b/conts/baremetal/threads_demo/main.c @@ -1,80 +1,115 @@ /* - * Main function for all tests - * - * Copyright (C) 2009 B Labs Ltd. + * Main function for this container */ -#include -#include -#include -#include -#include #include #include #include +#include +/* Symbolic constants */ +#define STACK_SIZE 0x1000 +#define NTHREADS 10 -int exit_test_thread(void *arg) +/* Stack and utcb region */ +static char stack[NTHREADS * STACK_SIZE]; +DECLARE_UTCB_SPACE(utcb, NTHREADS) + +/* Function definitions */ +static void init_thread_lib(void) { - while (1) + /* Thread lib is informed about the stack region. */ + l4_set_stack_params((unsigned long)stack, + (unsigned long)(stack + sizeof(stack)), + STACK_SIZE); + + /* Thread lib is informed about the utcb region. */ + l4_set_utcb_params((unsigned long)utcb, + (unsigned long)(utcb + sizeof(utcb))); + + /* Now, we are ready to make calls to the library. */ +} + +static int do_some_work1(void *arg) +{ + struct task_ids ids; + int value = *(int *)arg; + int j; + + l4_getid(&ids); + printf("tid = %d is called with the value of (%d).\n", + __raw_tid(ids.tid), value); + + /* Wait for a while before exiting */ + j = 0x400000; + while (--j) ; - //l4_thread_switch(0); - //l4_exit(5); + + return ids.tid; +} + +static int do_some_work2(void *arg) +{ + struct task_ids ids; + int value = *(int *)arg; + int j; + + l4_getid(&ids); + printf("tid = %d is called with the value of (%d).\n", + __raw_tid(ids.tid), value); + + /* Wait for a while before exiting */ + j = 0x400000; + while (--j) + ; + + l4_thread_exit(ids.tid); + + /* Should never reach here */ return 0; } -int exit_test(void) +static int thread_demo(void) { - int ret; - struct task_ids ids; + struct task_ids ids[NTHREADS]; + int arg[NTHREADS]; + int j; - /* Create and run a new thread */ - if ((ret = thread_create(exit_test_thread, 0, - TC_SHARE_SPACE | TC_AS_PAGER, - &ids)) < 0) { - printf("Top-level simple_pager creation failed.\n"); - goto out_err; - } else - printf("Thread (%d) created successfully.\n", ids.tid); + memset(ids, 0, sizeof(ids)); - // l4_thread_switch(0); + /* Create threads. */ + for (int i = 0; i < NTHREADS; ++i) { + /* The argument passed to the thread in question. */ + arg[i] = i; - /* Kill it */ - printf("Killing Thread (%d).\n", ids.tid); - if ((ret = l4_thread_control(THREAD_DESTROY, &ids)) < 0) - printf("Error: Killing Thread (%d), err = %d\n", ids.tid, ret); - else - printf("Success: Killed Thread (%d)\n", ids.tid); + /* Threads are created. */ + if (i % 2) + l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER, + do_some_work1, (void *)&arg[i]); + else + l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER, + do_some_work2, (void *)&arg[i]); + /* Wait for a while before launching another thread. */ + j = 0x100000; + while (--j) + ; + } -#if 0 - /* Wait on it */ - printf("Waiting on Thread (%d) to exit.\n", ids.tid); - if ((ret = l4_thread_control(THREAD_WAIT, &ids)) >= 0) - printf("Success. Paged child returned %d\n", ret); - else - printf("Error. Wait on (%d) failed. err = %d\n", - ids.tid, ret); + /* Wait for them to exit. */ + for (int i = 0; i < NTHREADS; ++i) + printf("tid = %d exited with (%d).\n", __raw_tid(ids[i].tid), + l4_thread_control(THREAD_WAIT, &ids[i])); -#endif return 0; -out_err: - BUG(); } int main(void) { - printf("%s: Container %s started\n", - __CONTAINER__, __CONTAINER_NAME__); + /* Before using the thread lib, we have to initialize it. */ + init_thread_lib(); - capability_test(); - - //exit_test(); - - /* Now quit to demo self-paging quit */ - //l4_exit(0); - - /* Now quit by null pointer */ - // *((int *)0) = 5; + /* Demonstrates the usage of the thread lib. */ + thread_demo(); return 0; } From 3d2b87d4886d14067cc6d6355ce81c125afbf4dc Mon Sep 17 00:00:00 2001 From: Amit Mahajan Date: Fri, 4 Dec 2009 00:54:23 +0530 Subject: [PATCH 6/6] CLCD added as new capability, code note added yet --- config/cml/container_ruleset.template | 12 +- conts/baremetal/clcd_service/SConstruct | 67 +++++ conts/baremetal/clcd_service/container.c | 21 ++ .../clcd_service/include/capability.h | 12 + .../clcd_service/include/container.h | 13 + conts/baremetal/clcd_service/include/linker.h | 7 + conts/baremetal/clcd_service/main.c | 277 ++++++++++++++++++ conts/baremetal/clcd_service/src/test.c | 0 conts/libdev/SConscript | 9 +- conts/libdev/clcd/pl110/include/pl110_clcd.h | 104 +++++++ conts/libdev/clcd/pl110/src/pl110_clcd.c | 68 +++++ include/l4/platform/pb926/offsets.h | 1 + include/l4/platform/pb926/platform.h | 6 +- src/platform/pb926/platform.c | 12 +- 14 files changed, 604 insertions(+), 5 deletions(-) create mode 100644 conts/baremetal/clcd_service/SConstruct create mode 100644 conts/baremetal/clcd_service/container.c create mode 100644 conts/baremetal/clcd_service/include/capability.h create mode 100644 conts/baremetal/clcd_service/include/container.h create mode 100644 conts/baremetal/clcd_service/include/linker.h create mode 100644 conts/baremetal/clcd_service/main.c create mode 100644 conts/baremetal/clcd_service/src/test.c create mode 100644 conts/libdev/clcd/pl110/include/pl110_clcd.h create mode 100644 conts/libdev/clcd/pl110/src/pl110_clcd.c diff --git a/config/cml/container_ruleset.template b/config/cml/container_ruleset.template index fbf3899..5d47c15 100644 --- a/config/cml/container_ruleset.template +++ b/config/cml/container_ruleset.template @@ -134,7 +134,8 @@ derive baremetal%(cn)d from ((CONT%(cn)d_BAREMETAL_PROJ_THREADS_DEMO==y) ? "thread_demo%(cn)d" : ((CONT%(cn)d_BAREMETAL_PROJ_TEST==y) ? "test%(cn)d" : ((CONT%(cn)d_BAREMETAL_PROJ_UART_SERVICE==y) ? "uart_service%(cn)d" : -((CONT%(cn)d_BAREMETAL_PROJ_TIMER_SERVICE==y) ? "timer_service%(cn)d" : "baremetal_noname%(cn)d" ))))) +((CONT%(cn)d_BAREMETAL_PROJ_CLCD_SERVICE==y) ? "clcd_service%(cn)d" : +((CONT%(cn)d_BAREMETAL_PROJ_TIMER_SERVICE==y) ? "timer_service%(cn)d" : "baremetal_noname%(cn)d" )))))) default CONT%(cn)d_OPT_NAME from (CONT%(cn)d_TYPE_LINUX==y) ? "linux%(cn)d" : ((CONT%(cn)d_TYPE_BAREMETAL==y) ? baremetal%(cn)d : "posix%(cn)d") @@ -167,6 +168,7 @@ CONT%(cn)d_BAREMETAL_PROJ_THREADS_DEMO 'Thread Library Demo' CONT%(cn)d_BAREMETAL_PROJ_TEST 'Test Project' CONT%(cn)d_BAREMETAL_PROJ_UART_SERVICE 'UART Service' CONT%(cn)d_BAREMETAL_PROJ_TIMER_SERVICE 'Timer Service' +CONT%(cn)d_BAREMETAL_PROJ_CLCD_SERVICE 'CLCD Service' choices cont%(cn)d_baremetal_params CONT%(cn)d_BAREMETAL_PROJ_EMPTY @@ -175,6 +177,7 @@ choices cont%(cn)d_baremetal_params CONT%(cn)d_BAREMETAL_PROJ_TEST CONT%(cn)d_BAREMETAL_PROJ_UART_SERVICE CONT%(cn)d_BAREMETAL_PROJ_TIMER_SERVICE + CONT%(cn)d_BAREMETAL_PROJ_CLCD_SERVICE default CONT%(cn)d_BAREMETAL_PROJ_EMPTY menu cont%(cn)d_default_pager_params @@ -231,16 +234,19 @@ cont%(cn)d_cap_device_uart1 'Container %(cn)d UART1 Menu' cont%(cn)d_cap_device_uart2 'Container %(cn)d UART2 Menu' cont%(cn)d_cap_device_uart3 'Container %(cn)d UART3 Menu' cont%(cn)d_cap_device_timer1 'Container %(cn)d TIMER23 Menu' +cont%(cn)d_cap_device_clcd 'Container %(cn)d CLCD Menu' CONT%(cn)d_CAP_DEVICE_UART1_USE 'Container %(cn)d UART1 Enable' CONT%(cn)d_CAP_DEVICE_UART2_USE 'Container %(cn)d UART2 Enable' CONT%(cn)d_CAP_DEVICE_UART3_USE 'Container %(cn)d UART3 Enable' CONT%(cn)d_CAP_DEVICE_TIMER1_USE 'Container %(cn)d TIMER23 Enable' +CONT%(cn)d_CAP_DEVICE_CLCD0_USE 'Container %(cn)d CLCD Enable' default CONT%(cn)d_CAP_DEVICE_UART1_USE from n default CONT%(cn)d_CAP_DEVICE_UART2_USE from n default CONT%(cn)d_CAP_DEVICE_UART3_USE from n default CONT%(cn)d_CAP_DEVICE_TIMER1_USE from n +default CONT%(cn)d_CAP_DEVICE_CLCD0_USE from n menu cont%(cn)d_cap_device_uart1 CONT%(cn)d_CAP_DEVICE_UART1_USE @@ -254,11 +260,15 @@ menu cont%(cn)d_cap_device_uart3 menu cont%(cn)d_cap_device_timer1 CONT%(cn)d_CAP_DEVICE_TIMER1_USE +menu cont%(cn)d_cap_device_clcd + CONT%(cn)d_CAP_DEVICE_CLCD0_USE + menu cont%(cn)d_device_list cont%(cn)d_cap_device_uart1 cont%(cn)d_cap_device_uart2 cont%(cn)d_cap_device_uart3 cont%(cn)d_cap_device_timer1 + cont%(cn)d_cap_device_clcd # # Settings for Custom Capabilities diff --git a/conts/baremetal/clcd_service/SConstruct b/conts/baremetal/clcd_service/SConstruct new file mode 100644 index 0000000..7189aa4 --- /dev/null +++ b/conts/baremetal/clcd_service/SConstruct @@ -0,0 +1,67 @@ +# -*- mode: python; coding: utf-8; -*- +# +# Codezero -- Virtualization microkernel for embedded systems. +# +# Copyright © 2009 B Labs Ltd +# +import os, shelve, sys +from os.path import * + +PROJRELROOT = '../..' + +sys.path.append(PROJRELROOT) + +from config.projpaths import * +from config.configuration import * + +config = configuration_retrieve() +platform = config.platform +arch = config.arch +gcc_cpu_flag = config.gcc_cpu_flag + +LIBL4_RELDIR = 'conts/libl4' +KERNEL_INCLUDE = join(PROJROOT, 'include') +LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR) +LIBL4_INCLUDE = join(LIBL4_DIR, 'include') +LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR) + +# Locally important paths are here +LIBC_RELDIR = 'conts/libc' +LIBC_DIR = join(PROJROOT, LIBC_RELDIR) +LIBC_LIBPATH = join(BUILDDIR, LIBC_RELDIR) +LIBC_INCLUDE = [join(LIBC_DIR, 'include'), \ + join(LIBC_DIR, 'include/arch' + '/' + arch)] + +LIBDEV_RELDIR = 'conts/libdev' +LIBDEV_DIR = join(PROJROOT, LIBDEV_RELDIR) +LIBDEV_LIBPATH = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-userspace') +LIBDEV_INCLUDE = [join(LIBDEV_DIR, 'uart/include'), + join(LIBDEV_DIR, 'clcd/pl110/include')] +LIBDEV_CCFLAGS = '-DPLATFORM_' + platform.upper() + +# FIXME: Add these to autogenerated SConstruct !!! +LIBMEM_RELDIR = 'conts/libmem' +LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR) +LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR) +LIBMEM_INCLUDE = LIBMEM_DIR + +env = Environment(CC = config.user_toolchain + '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', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS], + LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"], + ASFLAGS = ['-D__ASSEMBLY__'], \ + PROGSUFFIX = '.elf', # The suffix to use for final executable\ + ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path\ + LIBS = ['gcc', 'libl4', 'libmalloc', 'c-userspace', 'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines. + CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, LIBC_INCLUDE, LIBMEM_INCLUDE], + LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH, LIBMEM_LIBPATH], + CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h') + +src = Glob('*.[cS]') +src += Glob('src/*.[cS]') + +objs = env.Object(src) +prog = env.Program('main.elf', objs) +Depends(prog, 'include/linker.lds') diff --git a/conts/baremetal/clcd_service/container.c b/conts/baremetal/clcd_service/container.c new file mode 100644 index 0000000..f570c3d --- /dev/null +++ b/conts/baremetal/clcd_service/container.c @@ -0,0 +1,21 @@ +/* + * Container entry point for pager + * + * Copyright (C) 2007-2009 B Labs Ltd. + */ + +#include +#include + + +extern void main(void); + +void __container_init(void) +{ + /* Generic L4 initialisation */ + __l4_init(); + + /* Entry to main */ + main(); +} + diff --git a/conts/baremetal/clcd_service/include/capability.h b/conts/baremetal/clcd_service/include/capability.h new file mode 100644 index 0000000..5cfce89 --- /dev/null +++ b/conts/baremetal/clcd_service/include/capability.h @@ -0,0 +1,12 @@ +#ifndef __UART_SERVICE_CAPABILITY_H__ +#define __UART_SERVICE_CAPABILITY_H__ + +#include +#include +#include + +void cap_print(struct capability *cap); +void cap_list_print(struct cap_list *cap_list); +int cap_read_all(); + +#endif /* header */ diff --git a/conts/baremetal/clcd_service/include/container.h b/conts/baremetal/clcd_service/include/container.h new file mode 100644 index 0000000..e6eece5 --- /dev/null +++ b/conts/baremetal/clcd_service/include/container.h @@ -0,0 +1,13 @@ +/* + * Autogenerated definitions for this container. + */ +#ifndef __CONTAINER_H__ +#define __CONTAINER_H__ + + +#define __CONTAINER_NAME__ "uart_service" +#define __CONTAINER_ID__ 0 +#define __CONTAINER__ "cont0" + + +#endif /* __CONTAINER_H__ */ diff --git a/conts/baremetal/clcd_service/include/linker.h b/conts/baremetal/clcd_service/include/linker.h new file mode 100644 index 0000000..e39da2f --- /dev/null +++ b/conts/baremetal/clcd_service/include/linker.h @@ -0,0 +1,7 @@ +#ifndef __LINKER_H__ +#define __LINKER_H__ + +extern char vma_start[]; +extern char __end[]; + +#endif /* __LINKER_H__ */ diff --git a/conts/baremetal/clcd_service/main.c b/conts/baremetal/clcd_service/main.c new file mode 100644 index 0000000..72a8f85 --- /dev/null +++ b/conts/baremetal/clcd_service/main.c @@ -0,0 +1,277 @@ +/* + * CLCD service for userspace + */ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include /* FIXME: Its best if this is */ +#include + +#define CLCD_TOTAL 1 + +static struct capability caparray[32]; +static int total_caps = 0; + +struct capability clcd_cap[CLCD_TOTAL]; + +int cap_read_all() +{ + int ncaps; + int err; + + /* Read number of capabilities */ + if ((err = l4_capability_control(CAP_CONTROL_NCAPS, + 0, 0, 0, &ncaps)) < 0) { + printf("l4_capability_control() reading # of" + " capabilities failed.\n Could not " + "complete CAP_CONTROL_NCAPS request.\n"); + BUG(); + } + total_caps = ncaps; + + /* Read all capabilities */ + if ((err = l4_capability_control(CAP_CONTROL_READ, + 0, 0, 0, caparray)) < 0) { + printf("l4_capability_control() reading of " + "capabilities failed.\n Could not " + "complete CAP_CONTROL_READ_CAPS request.\n"); + BUG(); + } + + return 0; +} + +/* + * Scans for up to CLCD_TOTAL clcd devices in capabilities. + */ +int clcd_probe_devices(void) +{ + int clcds = 0; + + /* Scan for clcd devices */ + for (int i = 0; i < total_caps; i++) { + /* Match device type */ + if (cap_devtype(&caparray[i]) == CAP_DEVTYPE_CLCD) { + /* Copy to correct device index */ + memcpy(&clcd_cap[cap_devnum(&caparray[i])], + &caparray[i], sizeof(clcd_cap[0])); + clcds++; + } + } + + if (clcds != CLCD_TOTAL) { + printf("%s: Error, not all clcd could be found. " + "total clcds=%d\n", __CONTAINER_NAME__, clcds); + return -ENODEV; + } + return 0; +} + +/* + * 1MB frame buffer, + * FIXME: can we do dma in this buffer? + */ +#define CLCD_FRAMEBUFFER_SZ 0x100000 +static char framebuffer[CLCD_FRAMEBUFFER_SZ]; + +static struct pl110_clcd clcd[CLCD_TOTAL]; + +int clcd_setup_devices(void) +{ + for (int i = 0; i < CLCD_TOTAL; i++) { + /* Get one page from address pool */ + clcd[i].virt_base = (unsigned long)l4_new_virtual(1); + + /* Map clcd to a virtual address region */ + if (IS_ERR(l4_map((void *)__pfn_to_addr(clcd_cap[i].start), + (void *)clcd[i].virt_base, clcd_cap[i].size, + MAP_USR_IO_FLAGS, + self_tid()))) { + printf("%s: FATAL: Failed to map CLCD device " + "%d to a virtual address\n", + __CONTAINER_NAME__, + cap_devnum(&clcd_cap[i])); + BUG(); + } + + /* Initialize clcd */ + pl110_initialise(&clcd[i], framebuffer); + } + return 0; +} + +static struct address_pool device_vaddr_pool; + +/* + * Initialize a virtual address pool + * for mapping physical devices. + */ +void init_vaddr_pool(void) +{ + for (int i = 0; i < total_caps; i++) { + /* Find the virtual memory region for this process */ + if (cap_type(&caparray[i]) == CAP_TYPE_MAP_VIRTMEM && + __pfn_to_addr(caparray[i].start) == + (unsigned long)vma_start) { + + /* + * Do we have any unused virtual space + * where we run, and do we have enough + * pages of it to map all clcd? + */ + if (__pfn(page_align_up(__end)) + + CLCD_TOTAL <= caparray[i].end) { + /* + * Yes. We initialize the device + * virtual memory pool here. + * + * We may allocate virtual memory + * addresses from this pool. + */ + address_pool_init(&device_vaddr_pool, + page_align_up(__end), + __pfn_to_addr(caparray[i].end), + CLCD_TOTAL); + return; + } else + goto out_err; + } + } + +out_err: + printf("%s: FATAL: No virtual memory " + "region available to map " + "devices.\n", __CONTAINER_NAME__); + BUG(); +} + +void *l4_new_virtual(int npages) +{ + return address_new(&device_vaddr_pool, npages, PAGE_SIZE); +} + +void handle_requests(void) +{ + u32 mr[MR_UNUSED_TOTAL]; + l4id_t senderid; + u32 tag; + int ret; + + printf("%s: Initiating ipc.\n", __CONTAINER__); + if ((ret = l4_receive(L4_ANYTHREAD)) < 0) { + printf("%s: %s: IPC Error: %d. Quitting...\n", + __CONTAINER__, __FUNCTION__, ret); + BUG(); + } + + /* Syslib conventional ipc data which uses first few mrs. */ + tag = l4_get_tag(); + senderid = l4_get_sender(); + + /* Read mrs not used by syslib */ + for (int i = 0; i < MR_UNUSED_TOTAL; i++) + mr[i] = read_mr(MR_UNUSED_START + i); + + /* + * TODO: + * + * Maybe add tags here that handle requests for sharing + * of the requested cld device with the client? + * + * In order to be able to do that, we should have a + * shareable/grantable capability to the device. Also + * the request should (currently) come from a task + * inside the current container + */ + + /* + * FIXME: Right now we are talking to CLCD by default, we need to define protocol + * for sommunication with CLCD service + */ + switch (tag) { + + default: + printf("%s: Error received ipc from 0x%x residing " + "in container %x with an unrecognized tag: " + "0x%x\n", __CONTAINER__, senderid, + __cid(senderid), tag); + } + + /* Reply */ + if ((ret = l4_ipc_return(ret)) < 0) { + printf("%s: IPC return error: %d.\n", __FUNCTION__, ret); + BUG(); + } +} + +/* + * UTCB-size aligned utcb. + * + * BIG WARNING NOTE: + * This in-place declaration is legal if we are running + * in a disjoint virtual address space, where the utcb + * declaration lies in a unique virtual address in + * the system. + */ +#define DECLARE_UTCB(name) \ + struct utcb name ALIGN(sizeof(struct utcb)) + +DECLARE_UTCB(utcb); + +/* Set up own utcb for ipc */ +int l4_utcb_setup(void *utcb_address) +{ + struct task_ids ids; + struct exregs_data exregs; + int err; + + l4_getid(&ids); + + /* Clear utcb */ + memset(utcb_address, 0, sizeof(struct utcb)); + + /* Setup exregs for utcb request */ + memset(&exregs, 0, sizeof(exregs)); + exregs_set_utcb(&exregs, (unsigned long)utcb_address); + + if ((err = l4_exchange_registers(&exregs, ids.tid)) < 0) + return err; + + return 0; +} + +void main(void) +{ + int err; + + /* Read all capabilities */ + cap_read_all(); + + /* Scan for clcd devices in capabilities */ + clcd_probe_devices(); + + /* Initialize virtual address pool for clcds */ + init_vaddr_pool(); + + /* Map and initialize clcd devices */ + clcd_setup_devices(); + + /* Setup own utcb */ + if ((err = l4_utcb_setup(&utcb)) < 0) { + printf("FATAL: Could not set up own utcb. " + "err=%d\n", err); + BUG(); + } + + /* Listen for clcd requests */ + while (1) + handle_requests(); +} + diff --git a/conts/baremetal/clcd_service/src/test.c b/conts/baremetal/clcd_service/src/test.c new file mode 100644 index 0000000..e69de29 diff --git a/conts/libdev/SConscript b/conts/libdev/SConscript index 96e5a46..1432a6f 100644 --- a/conts/libdev/SConscript +++ b/conts/libdev/SConscript @@ -24,13 +24,18 @@ LIBDEV_UART_PATH = join(PROJROOT, 'conts/libdev/uart') # Path for timer files LIBDEV_TIEMR_PATH = join(PROJROOT, 'conts/libdev/timer/sp804') +# Path for clcd files +LIBDEV_CLCD_PATH = join(PROJROOT, 'conts/libdev/clcd/pl110') + e = env.Clone() -e.Append(CPPPATH = [LIBDEV_UART_PATH + '/include', LIBDEV_TIEMR_PATH + '/include'], +e.Append(CPPPATH = [LIBDEV_UART_PATH + '/include', LIBDEV_TIEMR_PATH + '/include', + LIBDEV_CLCD_PATH + '/include',], CCFLAGS = ['-nostdinc', '-DVARIANT_' + variant.upper(), '-DPLATFORM_' + platform.upper()]) source = Glob('uart/src' + '/*.c') + \ - Glob('timer/sp804/src' + '/*.c') + Glob('timer/sp804/src' + '/*.c') + \ + Glob('clcd/pl110/src' + '/*.c') objects = e.StaticObject(source) library = e.StaticLibrary('libdev-' + variant, objects) diff --git a/conts/libdev/clcd/pl110/include/pl110_clcd.h b/conts/libdev/clcd/pl110/include/pl110_clcd.h new file mode 100644 index 0000000..b1f7777 --- /dev/null +++ b/conts/libdev/clcd/pl110/include/pl110_clcd.h @@ -0,0 +1,104 @@ + +#ifndef __PL110_CLCD_H__ +#define __PL110_CLCD_H__ + +/* Register offsets */ +#define PL110_CLCD_TIMING0 0x000 /* Horizontal Axis Panel Control*/ +#define PL110_CLCD_TIMING1 0x004 /* Vertical Axis Panel Control */ +#define PL110_CLCD_TIMING2 0x008 /* Clock and Polarity Signal Control*/ +#define PL110_CLCD_TIMING3 0x00c /* Line End Control */ +#define PL110_CLCD_UPBASE 0x010 /* Upper Panel Frame Base Address*/ +#define PL110_CLCD_LPBASE 0x014 /* Lower Panel Frame Base Address */ +#define PL110_CLCD_IMSC 0x018 /* Interrupt Mast Set Clear */ +#define PL110_CLCD_CONTROL 0x01c /* CLCD Control */ +#define PL110_CLCD_RIS 0x020 /* Raw Interrupt Status */ +#define PL110_CLCD_MIS 0x024 /* Masked Interrupt Status */ +#define PL110_CLCD_ICR 0x028 /* Interrupt Clear */ +#define PL110_CLCD_UPCURR 0x02c /* Upper Panel Current Address Value */ +#define PL110_CLCD_LPCURR 0x030 /* Lower Panel Current Address Value */ +//#define PL110_LCD_PALETTE +#define PL110_CLCD_PERIPHID0 0xfe0 /* Peripheral Identification */ +#define PL110_CLCD_PERIPHID1 0xfe4 /* Peripheral Identification */ +#define PL110_CLCD_PERIPHID2 0xfe8 /* Peripheral Identification */ +#define PL110_CLCD_PERIPHID3 0xfec /* Peripheral Identification */ +#define PL110_CLCD_PCELLID0 0xff0 /* Peripheral Identification */ +#define PL110_CLCD_PCELLID1 0xff4 /* PrimeCell Identification */ +#define PL110_CLCD_PCELLID2 0xff8 /* PrimeCell Identification */ +#define PL110_CLCD_PCELLID3 0xffc /* PrimeCell Identification */ + +/* Scan mode */ +#define SCAN_VMODE_NONINTERLACED 0 /* non interlaced */ +#define SCAN_VMODE_INTERLACED 1 /* interlaced */ +#define SCAN_VMODE_DOUBLE 2 /* double scan */ +#define SCAN_VMODE_ODD_FLD_FIRST 4 /* interlaced: top line first */ +#define SCAN_VMODE_MASK 255 + +/* Control Register Bits */ +#define PL110_CNTL_LCDEN (1 << 0) +#define PL110_CNTL_LCDBPP1 (0 << 1) +#define PL110_CNTL_LCDBPP2 (1 << 1) +#define PL110_CNTL_LCDBPP4 (2 << 1) +#define PL110_CNTL_LCDBPP8 (3 << 1) +#define PL110_CNTL_LCDBPP16 (4 << 1) +#define PL110_CNTL_LCDBPP16_565 (6 << 1) +#define PL110_CNTL_LCDBPP24 (5 << 1) +#define PL110_CNTL_LCDBW (1 << 4) +#define PL110_CNTL_LCDTFT (1 << 5) +#define PL110_CNTL_LCDMONO8 (1 << 6) +#define PL110_CNTL_LCDDUAL (1 << 7) +#define PL110_CNTL_BGR (1 << 8) +#define PL110_CNTL_BEBO (1 << 9) +#define PL110_CNTL_BEPO (1 << 10) +#define PL110_CNTL_LCDPWR (1 << 11) +#define PL110_CNTL_LCDVCOMP(x) ((x) << 12) +#define PL110_CNTL_LDMAFIFOTIME (1 << 15) +#define PL110_CNTL_WATERMARK (1 << 16) + +#define PL110_TIM2_CLKSEL (1 << 5) +#define PL110_TIM2_IVS (1 << 11) +#define PL110_TIM2_IHS (1 << 12) +#define PL110_TIM2_IPC (1 << 13) +#define PL110_TIM2_IOE (1 << 14) +#define PL110_TIM2_BCD (1 << 26) + + + +struct videomode { + const char *name; /* optional */ + unsigned int refresh; /* optional */ + unsigned int xres; + unsigned int yres; + unsigned int pixclock; + unsigned int left_margin; + unsigned int right_margin; + unsigned int upper_margin; + unsigned int lower_margin; + unsigned int hsync_len; + unsigned int vsync_len; + unsigned int sync; + unsigned int vmode; + unsigned int flag; +}; + +struct pl110_clcd_panel { + struct videomode mode; + signed short width; /* width in mm */ + signed short height; /* height in mm */ + unsigned int tim2; + unsigned int tim3; + unsigned int cntl; + unsigned int bpp:8, + fixedtimings:1, + grayscale:1; + unsigned int connector; +}; + +struct pl110_clcd { + unsigned int virt_base; + struct pl110_clcd_panel *panel; + char *frame_buffer; +}; + +void pl110_initialise(struct pl110_clcd *clcd, char *buf); + +#endif /* __PL110_CLCD_H__ */ diff --git a/conts/libdev/clcd/pl110/src/pl110_clcd.c b/conts/libdev/clcd/pl110/src/pl110_clcd.c new file mode 100644 index 0000000..2ff23fd --- /dev/null +++ b/conts/libdev/clcd/pl110/src/pl110_clcd.c @@ -0,0 +1,68 @@ + + +#include + +#define read(a) *((volatile unsigned int *)(a)) +#define write(v, a) (*((volatile unsigned int *)(a)) = v) +#define setbit(bit, a) write(read(a) | bit, a) +#define clrbit(bit, a) write(read(a) & ~bit, a) + +/* + * Default panel, we will use this for now + * Seems like qemu has support for this + */ +static struct pl110_clcd_panel vga = { + .mode = { + .name = "VGA", + .refresh = 60, + .xres = 640, + .yres = 480, + .pixclock = 39721, + .left_margin = 40, + .right_margin = 24, + .upper_margin = 32, + .lower_margin = 11, + .hsync_len = 96, + .vsync_len = 2, + .sync = 0, + .vmode = SCAN_VMODE_NONINTERLACED, + }, + .width = -1, + .height = -1, + .tim2 = PL110_TIM2_BCD | PL110_TIM2_IPC, + .cntl = PL110_CNTL_LCDTFT | PL110_CNTL_LCDVCOMP(1), + .bpp = 16, +}; + +static void pl110_clcd_set_uppanel_fb(unsigned int clcd_base, + unsigned int fb_base) +{ + write(fb_base, (clcd_base + PL110_CLCD_UPBASE)); +} + +#if 0 +static void pl110_clcd_set_lwrpanel_fb(unsigned int clcd_base, unsigned int fb_base) +{ + write(fb_base, (clcd_base +PL110_CLCD_LPBASE)); +} + +static unsigned int pl110_clcd_get_uppanel_fb(unsigned int clcd_base) +{ + return read((clcd_base +PL110_CLCD_UPBASE)); +} + +static unsigned int pl110_clcd_get_lwrpanel_fb(unsigned int clcd_base) +{ + return read((clcd_base +PL110_CLCD_LPBASE)); +} +#endif + +void pl110_initialise(struct pl110_clcd *clcd, char *buf) +{ + clcd->panel = &vga; + clcd->frame_buffer = buf; + + pl110_clcd_set_uppanel_fb(clcd->virt_base, (unsigned int)(buf)); + +} + diff --git a/include/l4/platform/pb926/offsets.h b/include/l4/platform/pb926/offsets.h index d8949ec..262ef51 100644 --- a/include/l4/platform/pb926/offsets.h +++ b/include/l4/platform/pb926/offsets.h @@ -24,6 +24,7 @@ #define PB926_UART1_BASE 0x101F2000 /* Console port (UART1) */ #define PB926_UART2_BASE 0x101F3000 /* Console port (UART2) */ #define PB926_UART3_BASE 0x10009000 /* Console port (UART3) */ +#define PB926_CLCD_BASE 0x10120000 /* Color LCD */ /* * Uart virtual address until a file-based console access diff --git a/include/l4/platform/pb926/platform.h b/include/l4/platform/pb926/platform.h index 035f26a..c131d6e 100644 --- a/include/l4/platform/pb926/platform.h +++ b/include/l4/platform/pb926/platform.h @@ -28,17 +28,21 @@ #define PB926_UART_SIZE 0x1000 #define PB926_TIMER_SIZE 0x1000 +#define PB926_CLCD_SIZE 0x1000 #define PLATFORM_UART1_BASE PB926_UART1_BASE #define PLATFORM_UART2_BASE PB926_UART2_BASE #define PLATFORM_UART3_BASE PB926_UART3_BASE - #define PLATFORM_UART1_SIZE PB926_UART_SIZE #define PLATFORM_UART2_SIZE PB926_UART_SIZE #define PLATFORM_UART3_SIZE PB926_UART_SIZE + #define PLATFORM_TIMER1_BASE PB926_TIMER23_BASE #define PLATFORM_TIMER1_SIZE PB926_TIMER_SIZE +#define PLATFORM_CLCD0_BASE PB926_CLCD_BASE +#define PLATFORM_CLCD0_SIZE PB926_CLCD_SIZE + int platform_setup_device_caps(struct kernel_resources *kres); void platform_irq_enable(int irq); void platform_irq_disable(int irq); diff --git a/src/platform/pb926/platform.c b/src/platform/pb926/platform.c index c1b96d4..5ecdeee 100644 --- a/src/platform/pb926/platform.c +++ b/src/platform/pb926/platform.c @@ -26,7 +26,7 @@ */ int platform_setup_device_caps(struct kernel_resources *kres) { - struct capability *uart[4], *timer[4]; + struct capability *uart[4], *timer[4], *clcd[1]; /* Setup capabilities for userspace uarts and timers */ uart[1] = alloc_bootmem(sizeof(*uart[1]), 0); @@ -66,6 +66,16 @@ int platform_setup_device_caps(struct kernel_resources *kres) link_init(&timer[1]->list); cap_list_insert(timer[1], &kres->devmem_free); + /* Setup clcd capability as free */ + clcd[0] = alloc_bootmem(sizeof(*clcd[0]), 0); + clcd[0]->start = __pfn(PB926_CLCD_BASE); + clcd[0]->end = clcd[0]->start + 1; + clcd[0]->size = clcd[0]->end - clcd[0]->start; + cap_set_devtype(clcd[0], CAP_DEVTYPE_CLCD); + cap_set_devnum(clcd[0], 0); + link_init(&clcd[0]->list); + cap_list_insert(clcd[0], &kres->devmem_free); + return 0; }