Add eth example code
This commit is contained in:
111
run/eth.run
Normal file
111
run/eth.run
Normal file
@@ -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/eth
|
||||
}
|
||||
|
||||
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 {
|
||||
<config verbose="yes">
|
||||
<parent-provides>
|
||||
<service name="ROM"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="PD"/>
|
||||
<service name="RM"/>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<default caps="200"/>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides> <service name="Timer"/> </provides>
|
||||
</start>
|
||||
<start name="eth" caps="200">
|
||||
<resource name="RAM" quantum="4M"/>
|
||||
<config>
|
||||
<vfs>
|
||||
<dir name="dev"> <log/> </dir>
|
||||
<dir name="socket"> <lwip dhcp="yes"/> </dir>
|
||||
</vfs>
|
||||
<libc stdout="/dev/log" stderr="/dev/log" socket="/socket"/>
|
||||
</config>
|
||||
</start>}
|
||||
|
||||
append_if [have_spec gpio] config "
|
||||
<start name=\"[gpio_drv]\" caps=\"140\">
|
||||
<resource name=\"RAM\" quantum=\"4M\"/>
|
||||
<provides><service name=\"Gpio\"/></provides>
|
||||
<config/>
|
||||
</start>"
|
||||
|
||||
append_if $use_usb_driver config {
|
||||
<start name="usb_drv" caps="120">
|
||||
<resource name="RAM" quantum="14M"/>
|
||||
<provides>
|
||||
<service name="Nic"/>
|
||||
</provides>
|
||||
<config ehci="yes">
|
||||
<nic mac="02:00:00:00:01:01" />
|
||||
</config>
|
||||
</start>}
|
||||
|
||||
append_platform_drv_config
|
||||
|
||||
append_if $use_nic_driver config {
|
||||
<start name="nic_drv" caps="130">
|
||||
<resource name="RAM" quantum="20M"/>
|
||||
<provides><service name="Nic"/></provides>
|
||||
} [nic_drv_config] {
|
||||
</start>}
|
||||
|
||||
append config {
|
||||
</config>
|
||||
}
|
||||
|
||||
install_config $config
|
||||
|
||||
#
|
||||
# Boot image
|
||||
#
|
||||
|
||||
build_boot_image { core ld.lib.so init eth 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
|
||||
48
src/app/eth/main.cc
Normal file
48
src/app/eth/main.cc
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* \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 <base/component.h>
|
||||
#include <base/log.h>
|
||||
#include <libc/component.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <util/string.h>
|
||||
|
||||
void Libc::Component::construct(Libc::Env &env)
|
||||
{
|
||||
Libc::with_libc([&] () {
|
||||
Genode::log("hello test completed");
|
||||
|
||||
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));
|
||||
|
||||
char buffer[16384];
|
||||
::recv(sd, buffer, 16383, 0);
|
||||
Genode::String<16383> s(buffer);
|
||||
Genode::log(s);
|
||||
|
||||
// ----------------------------------
|
||||
|
||||
});
|
||||
}
|
||||
3
src/app/eth/target.mk
Normal file
3
src/app/eth/target.mk
Normal file
@@ -0,0 +1,3 @@
|
||||
TARGET = eth
|
||||
SRC_CC = main.cc
|
||||
LIBS = base libc
|
||||
Reference in New Issue
Block a user