From 3cb5e6ac14b2eaf165f9926c24627e6a89ff4f66 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Wed, 16 Jan 2019 18:02:20 +0100 Subject: [PATCH] Load and start binary over network - NOT working --- run/child.run | 111 ++++++++++++++++++++++++++++++ src/app/child/main.cc | 148 ++++++++++++++++++++++++++++++++++++++++ src/app/child/target.mk | 3 + 3 files changed, 262 insertions(+) create mode 100644 run/child.run create mode 100644 src/app/child/main.cc create mode 100644 src/app/child/target.mk diff --git a/run/child.run b/run/child.run new file mode 100644 index 0000000..f89c3aa --- /dev/null +++ b/run/child.run @@ -0,0 +1,111 @@ +# +# Build +# + +set use_usb_driver [expr [have_spec omap4] || [have_spec arndale] || [have_spec rpi]] +set use_nic_driver [expr !$use_usb_driver && ![have_spec odroid_xu] && ![have_spec linux]] + +if {[expr !$use_usb_driver && !$use_nic_driver] || + [expr [have_spec imx53] && [have_spec trustzone]]} { + puts "\n Run script is not supported on this platform. \n"; exit 0 } + +set build_components { + core init + drivers/timer drivers/nic + lib/vfs/lwip + app/child app/hello +} + +lappend_if $use_usb_driver build_components drivers/usb +lappend_if [have_spec gpio] build_components drivers/gpio + +proc gpio_drv { } { if {[have_spec rpi] && [have_spec hw]} { return hw_gpio_drv } + if {[have_spec rpi] && [have_spec foc]} { return foc_gpio_drv } + return gpio_drv } + +source ${genode_dir}/repos/base/run/platform_drv.inc +append_platform_drv_build_components + +build $build_components + +create_boot_directory + +# +# Generate config +# + +set config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if [have_spec gpio] config " + + + + + " + +append_if $use_usb_driver config { + + + + + + + + + } + +append_platform_drv_config + +append_if $use_nic_driver config { + + + + } [nic_drv_config] { + } + +append config { + +} + +install_config $config + +# +# Boot image +# + +build_boot_image { core ld.lib.so init child hello nic_drv vfs_lwip.lib.so timer libc.lib.so vfs.lib.so } + +append qemu_args " -nographic " + +append_if [have_spec lan9118] qemu_args " -net nic,macaddr=02:00:00:00:01:03 -net nic,model=lan9118 -net tap,ifname=tap0,script=no " + +run_genode_until forever diff --git a/src/app/child/main.cc b/src/app/child/main.cc new file mode 100644 index 0000000..d174b15 --- /dev/null +++ b/src/app/child/main.cc @@ -0,0 +1,148 @@ +/* + * \brief Test client for the Hello RPC interface + * \author Björn Döbel + * \author Norman Feske + * \date 2008-03-20 + */ + +/* + * Copyright (C) 2008-2017 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include + +namespace xyz { + class Parent_service : public Genode::Parent_service { + private: + Genode::Registry::Element _reg_elem; + + public: + Parent_service(Genode::Registry ®istry, Genode::Env &env, + Service::Name const &name) + : + Genode::Parent_service(env, name), _reg_elem(registry, *this) { } + }; + + class MyChild : public Genode::Child_policy { + Name const _name; + + Genode::Env &_env; + + Genode::Cap_quota const _cap_quota; + Genode::Ram_quota const _ram_quota; + + Genode::Registry &_parent_services; + + Genode::Rpc_entrypoint _child_ep; + + Init::Child_policy_provide_rom_file _binary_policy; + + Genode::Child _child; + + template + static Genode::Service *_find_service(Genode::Registry &services, + Genode::Service::Name const &name) + { + Genode::Service *service = nullptr; + services.for_each([&] (T &s) { + if (!service && (s.name() == name)) + service = &s; }); + return service; + } + + public: + + MyChild(Genode::Env &env, + Genode::Session_label const &label, + Genode::Cap_quota cap_quota, + Genode::Ram_quota ram_quota, + Genode::Registry parent_services, + Genode::Dataspace_capability binary) : + _name(label), + _env(env), + _cap_quota(Genode::Child::effective_quota(cap_quota)), + _ram_quota(Genode::Child::effective_quota(ram_quota)), + _parent_services(parent_services), + _child_ep{&_env.pd(), 12 * 1024, name().string()}, + _binary_policy(name(), binary, &_child_ep), + _child(_env.rm(), _env.ep().rpc_ep(), *this) + { }; + ~MyChild() { }; + + Name name() const override { return _name; } + + Genode::Pd_session &ref_pd() override { return _env.pd(); } + Genode::Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); } + + void init(Genode::Pd_session &session, + Genode::Pd_session_capability cap) override + { + session.ref_account(_env.pd_session_cap()); + _env.pd().transfer_quota(cap, _cap_quota); + _env.pd().transfer_quota(cap, _ram_quota); + } + + Genode::Service &resolve_session_request(Genode::Service::Name const &service_name, + Genode::Session_state::Args const &args) override + { + Genode::Service *service = nullptr; + if ((service = _binary_policy.resolve_session_request(service_name.string(), args.string()))) + { + Genode::log("Service from policy: ", service_name, "/", args); + return *service; + } + + Genode::log("Service from parent: ", service_name, "/", args); + + return *_find_service(_parent_services, service_name); + } + }; +} + +void Libc::Component::construct(Libc::Env &env) +{ + Libc::with_libc([&] () { + struct sockaddr_in srv_addr; + srv_addr.sin_port = htons(8080); + srv_addr.sin_family = AF_INET; + srv_addr.sin_addr.s_addr = inet_addr("131.159.12.17"); + + int sd = ::socket(AF_INET, SOCK_STREAM, 0); + ::connect(sd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)); + + Genode::Ram_dataspace_capability ds; + ds = env.pd().alloc(1 * 1024 * 1024); + Genode::addr_t addr = env.rm().attach(ds); + + ::recv(sd, (void *)addr, 16383, 0); + Genode::String<16383> s((const char *)addr); + Genode::log(s); + + Genode::Heap _heap { env.ram(), env.rm() }; + + Genode::Registry parent_services; + static const char *names[] = { "PD", "CPU", "LOG", "ROM", 0 }; + for (unsigned i = 0; names[i]; i++) + new (_heap) xyz::Parent_service(parent_services, env, names[i]); + xyz::MyChild child { env, Genode::Session_label("app"), Genode::Cap_quota{6}, Genode::Ram_quota{1 * 1024 * 1024}, parent_services, ds }; + + while(1) { + } + }); +} diff --git a/src/app/child/target.mk b/src/app/child/target.mk new file mode 100644 index 0000000..eb311d1 --- /dev/null +++ b/src/app/child/target.mk @@ -0,0 +1,3 @@ +TARGET = child +SRC_CC = main.cc +LIBS = base libc