Commit graph

2535 commits

Author SHA1 Message Date
Ralf Schlatterbeck de6477efa8 Fix run.sh scripts to use jumptable of bootloader
Otherwise a crash results with a bootloader compiled with a newer AVR
toolchain (e.g. Debian Jessie). If you still have an ages-old bootloader
without a jump-table, as a short-term measure you can revert this change
in your run.sh. As a long-term fix we recommend you get your bootloader
updated!
2016-02-19 17:32:09 +01:00
Harald Pichler 428131e8a8 use dynamic sleep for loop 2016-01-06 21:57:29 +01:00
Benoît Thébaudeau 69eacbddbe cc2538: Add AES-CCM* driver
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2016-01-04 00:28:27 +01:00
kkrentz 24cb05059a CC2538: Add AES-128 driver 2016-01-04 00:28:27 +01:00
Benoît Thébaudeau 3dbe4c9403 cc2538: Add crypto driver and example for AES-ECB
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
2016-01-04 00:28:26 +01:00
Antonio Lignan ca919ab0b0 Merge pull request #1196 from otcshare/x86
New platform: Intel Galileo Board
2015-12-23 12:33:47 +01:00
Antonio Lignan d9546991df Merge pull request #1424 from alignan/pull/remote-power-mgmt
RE-Mote power management support
2015-12-23 12:27:16 +01:00
Michael LeMay b4523b9130 galileo: Fix broken link in README.md
This patch fixes a broken link in README.md to serial cable connection
instructions.
2015-12-21 08:06:14 -02:00
Michael LeMay 13be942d40 galileo: Fix code style violations 2015-12-21 08:06:14 -02:00
Michael LeMay e14761c26b galileo: Document prerequisites for building on Ubuntu Linux
This patch documents the prerequisites for building on Ubuntu Linux in
the Galileo platform README.
2015-12-21 08:06:14 -02:00
Michael LeMay 09d168da04 galileo: Add support for old versions of GNU Make
This patch revises a Makefile to avoid using a feature that is
incompatible with GNU Make v.3.81.
2015-12-21 08:06:14 -02:00
Michael LeMay c75e9466f6 galileo: Fix bug in newlib build script
This patch fixes a bug in the newlib build script that causes it to
not delete an old source directory as intended prior to rebuilding the
library.
2015-12-21 08:06:14 -02:00
Michael LeMay f85654a82f x86, galileo: Add UEFI support
This patch adds support for optionally building EFI binaries in
addition to Multiboot ELF binaries.  It includes a script,
build_uefi.sh, that downloads tool and library sources from the EDK II
project, builds the GenFw tool that is used to create UEFI binaries,
and creates a makefile that is included from the main x86 common
makefile and enables UEFI support in the Contiki build system.  If the
script is not run prior to building Contiki, then an informational
message will be displayed with instructions for running build_uefi.sh
if UEFI support is desired.  This patch also adds the path to the
auto-generated makefile to .gitignore.

This patch modifies the linker script for the Intel Quark X1000 to
account for the output file section offsets and alignment expectations
of the EDK II GenFw project.

This patch also adds a newlib patch to remove the weak symbol
attribute from floating point stdio support routines.  See
<newlib>/newlib/README for an explanation of how the newlib developers
intended for _printf_float and _scanf_float to be linked.  Newlib
declares them as weak symbols with the intention that developers would
force them to be linked only when needed using a linker command line
option.  However, some but not all Contiki programs require them, so
we cannot simply always include or exclude them.  Instead, we remove
the weak symbol attributes and rely on the linker to automatically
determine whether or not they should be linked.  This avoids an issue
in which weak symbols were undefined in the intermediate DLL generated
as part of the UEFI build process.  That resulted in the GenFw program
emitting "ERROR 3000" messages when it encountered relocations
referencing such an undefined symbol.

Finally, this patch updates README.md to both make some revisions to
account for the UART support introduced in previous patches as well as
to provide instructions for using the UEFI support.
2015-12-21 08:06:14 -02:00
Michael LeMay b915e7d5e3 galileo: Omit exception handling unwind tables
This patch modifies the newlib and Contiki C and C++ compiler flags to
omit exception handling unwind tables (see
http://wiki.dwarfstd.org/index.php?title=Exception_Handling).
Removing these tables saves space in debug builds and has not caused
any readily-apparent functional changes.

Here is the size listing for an example program built without this
patch:
   text	   data	    bss	    dec	    hex	filename
  76002	   1508	  21224	  98734	  181ae	all-timers.galileo

Here is the size listing for the same program with this patch:
   text	   data	    bss	    dec	    hex	filename
  72918	   1508	  21224	  95650	  175a2	all-timers.galileo

The primary motivation for this patch is to help enable UEFI support.
The .eh_frame and .eh_frame_hdr sections that are otherwise generated
are treated as code sections by the EDK2 GenFw program, since they are
read-only alloc sections.  They get grouped with the actual code
sections, ahead of the data sections.  This perturbs symbols and
complicates debugging.
2015-12-21 08:06:14 -02:00
Michael LeMay 38206e3980 galileo: Add Ethernet support
This patch adds support for Ethernet to the Intel Galileo port.  It
uses the Intel Quark X1000 Ethernet driver.  It initializes the first
Ethernet interface and starts some common network services.  By
default, it uses the following addresses:
 - Host: 192.0.2.2
 - Netmask: 255.255.255.0
 - Default gateway: 192.0.2.1
 - DNS server: (same as default gateway)
These settings can be changed by editing eth-conf.c.
2015-12-21 08:06:14 -02:00
Ricardo de Almeida Gonzaga 93c7988069 x86: Add Galileo pinmux support
This patch adds the galileo-pinmux.c and galileo-pinmux.h files,
which support access to pinmux configuration through a function
interface.

This is not 100% supported yet due to some pinmux paths
need Quark X1000 GPIO (legacy and non-legacy) configurations.

After we finish to implement Quark X1000 GPIO driver we'll add
support for this.
2015-12-21 08:06:14 -02:00
Ricardo de Almeida Gonzaga 781375f1d1 x86: Add PCA9685 support
This patch adds pwm-pca9685.c and pwm-pca9685.h files,
which support access to I2C-based PCA9685 PWM controller
configuration register through a function interface.

The PCA9685 is an I2C-bus controlled 16-channel LED controller
optimized for Red/Green/Blue/Amber (RGBA) color backlighting
applications. Each LED output has its own 12-bit resolution
(4096 steps) fixed frequency individual PWM controller that
operates at a programmable frequency from a typical of 24 Hz to
1526 Hz with a duty cycle that is adjustable from 0 % to 100 %
to allow the LED to be set to a specific brightness value.
More about PCA9685 can be found in its datasheet[1].

This driver is needed in order to configure Galileo pinmux.

[1] - http://www.nxp.com/documents/data_sheet/PCA9685.pdf
2015-12-21 08:06:14 -02:00
Ricardo de Almeida Gonzaga 495dcd659a x86: Add PCAL9535A support
This patch adds gpio-pcal9535a.c and gpio-pcal9535a.h files,
which support access to I2C-based PCAL9535A GPIO controller
configuration register through a function interface.

The PCAL9535A is a low-voltage 16-bit GPIO expander with interrupt
and reset for I2C-bus/SMBus applications. It contains the PCA9535
register set of four pairs of 8-bit Configuration, Input, Output,
and Polarity Inversion registers, and additionally, the PCAL9535A has
Agile I/O, which are additional features specifically designed to
enhance the I/O. More about PCAL9535A can be found in its datasheet[1].

This driver is needed in order to configure Galileo pinmux.

[1] - http://www.nxp.com/documents/data_sheet/PCAL9535A.pdf
2015-12-21 08:06:14 -02:00
Andre Guedes 6b433aede1 x86: Improve release binary size
This patch adds -ffunction-sections and -fdata-sections to the
'release' CFLAGS so each function and data is place into its
own section in the output file. It also adds --gc-section to
the 'release' LDFLAGS so the linker removes the sections which
are not referenced.

This patch also adds -ffunction-sections and -fdata-sections
options to CFLAGS from build_newlib.sh. This increases newlib
static libraries size, however, the Contiki image shrinks even
more since --gc-section removes "dead code" from newlib.

As a practical effect, all unused function and data (as well as
sections such as .eh_frame) are striped out from the final elf
binary. This shrinks our release binary drastically.

Finally, to prevent --gc-section from removing .multiboot section,
this patch adds KEEP(*(.multiboot)) to quarkX1000.ld.
2015-12-21 08:06:14 -02:00
Michael LeMay 0dcd5e9b5a x86: Revise CFLAGS and LDFLAGS for LLVM Clang compatibility
This patch slightly revises CFLAGS and LDFLAGS to specify the
optimization and debugging options and linker script in a way that is
compatible with using Clang as the C compiler and to invoke the linker
(i.e. CC = clang and LD = clang).
2015-12-21 08:06:14 -02:00
Michael LeMay 17b855aac9 galileo: Replace non-halting core implementation of assert with the halting one from newlib
This patch modifies the include order to include headers from newlib
ahead of those from the core of Contiki.  The only header file names
that are common between Contiki and newlib are assert.h and config.h,
but the config.h files in Contiki are only located in ports for other
CPUs so they are irrelevant to this patch.  The motivation for this
patch is to cause files that include assert.h to include the one from
newlib that halts when an assertion fails.  The assert implementation
in the core of Contiki does not halt when an assertion fails.

This patch also adds newlib syscall stubs that are required by the
newlib assert implementation and the _exit syscall function that halts
the system.

Finally, this patch updates some other newlib syscall stubs to
properly indicate their status as unsupported syscalls.
2015-12-21 08:06:14 -02:00
Michael LeMay 06e25c487a galileo: Correct README.md to explain how to verify boot with UART
This patch revises README.md to mention the UART support introduced by
earlier patches in the section about verifying that Contiki is
running.  It also revises the serial console setup instructions to
focus on the more thoroughly tested option.
2015-12-21 08:06:14 -02:00
Andre Guedes e41bed319f galileo: Revise stdlib static linking
This patch does some refactoring so we are able to statically link
against standard libraries in a more usual way.
2015-12-21 08:06:14 -02:00
Andre Guedes 7043aa41b3 galileo: Fix newlib-syscalls issue in Makefile
This patch removes 'newlib-syscalls.c' from CONTIKI_SOURCEFILES variable
and appends it to PROJECT_SOURCEFILES. This way the buildsystem will
automatically consider the newlib-syscalls object code during linking
time.
2015-12-21 08:06:14 -02:00
Andre Guedes c9020d95e7 x86: Build release image
This patch adds support for building release images. The main difference
between release images and default images is that the former is optimized
for size while the latter is "optimized" for debugging. To build a release
image, the BUILD_RELEASE variable should be set to 1. For instance, the
following command build a release image from the hello-world application:
$ cd examples/hello-world && make TARGET=galileo BUILD_RELEASE=1

To optimize for size we use the '-Os' option from gcc. This option also
enables the strict aliasing optimization. This generates lots of warning
messages since we use the '-Wall' option and lots of code in core/net/
break the strict-aliasing rules. Some test have shown that the strict
aliasing optimization it not taking effect in the final binary. For that
reasons, this patch manually disables the optimization. Also, the release
image is stripped.

For the sake of comparison, below follows the output from 'wc' and 'size'
for both debugging (default) and release images.

Default image:
$  wc -c hello-world.galileo
71112 hello-world.galileo
$ size hello-world.galileo
   text    data     bss     dec     hex filename
  20379    1188   12808   34375    8647 hello-world.galileo

Release image:
$ wc -c hello-world.galileo
26320 hello-world.galileo
$ size hello-world.galileo
   text    data     bss     dec     hex filename
  18146    1156   12808   32110    7d6e hello-world.galileo
2015-12-21 08:06:14 -02:00
Andre Guedes 6c9ab4eb6c galileo: Remove unneeded syscall stubs
This patch removes _kill_r and _getpid_r stubs since they are not
required by newlib at this moment. These stubs should not be in
the commit that introduced the initial newlib-syscalls.c file.
2015-12-21 08:06:14 -02:00
Andre Guedes d3d2b51fa2 galileo: Initial stdio support
This patch introduces the initial support for stdio library in Galileo
platform. For now, only standard output and error are supported. Both
streams use the UART1 device.

Newlib doesn't call open() for stdin, stdout, and stderr which means
that the _write_r call is the first activity the stub will see on
those streams. For that reason, we initialize the UART1 device in
Galileo's platform main() function instead of in open() system call.
2015-12-21 08:06:14 -02:00
Andre Guedes ee82304211 galileo: Implement _sbrk_r syscall
This patch implements the _sbrk_r() system call for Galileo platform. This
system call is required by newlib's malloc() implementation. Next patch
will introduce the initial support for stdio library which requires a
working malloc() function for proper operation.

We are not sure about the heap size we should use. Preliminary tests
have shown that stdio library requests 1032 bytes heap. So, as an initial
guess, a 2Kb heap size should be enough for now.
2015-12-21 08:06:14 -02:00
Michael LeMay 9b6b5ce5b0 galileo: Instruct developer to build C library prior to building Contiki
This patch enhances build_newlib.sh to create Makefile.libc so that
the main Galileo makefile can attempt to include Makefile.libc and
instruct the developer to run build_newlib.sh first if the definition
within Makefile.libc is not detected.
2015-12-21 08:06:14 -02:00
Michael LeMay b2e4786187 galileo: Stylistic changes to make build_newlib.sh less repetitive
This script defines new variables to represent common paths and
filenames.  It does not introduce any functional changes.
2015-12-21 08:06:14 -02:00
Michael LeMay c8cdc0c157 galileo: Check for errors after downloading newlib tarball
Repeat the file existence and MD5 checks in build_newlib.sh after the
newlib tarball is downloaded and exit if either of the checks fail.
2015-12-21 08:06:14 -02:00
Andre Guedes 96e50ec2c4 galileo: Fix Makefile.galileo
This patch moves the compiler and linking options related to QuarkX1000
SoC to Makefile.x86_quarkX1000 since it is more suitable. For instance,
'-m32' should be used in any platform based on QuarkX1000, not only
Galileo. The same rationale applies for the others options (e.g. -march,
mtune).
2015-12-21 08:06:14 -02:00
Michael LeMay 2b5efdfbe7 galileo: Revise C compiler flags for consistency.
The CFLAGS setting used for the newlib build process includes
"-mtune=i586" as does the ASFLAGS setting used for the Contiki build
process.  However, the CFLAGS setting used for the Contiki build
process did not include that flag.  This patch adds it for
consistency.
2015-12-21 08:06:14 -02:00
Michael LeMay b79fcaa7d8 galileo: Override Ubuntu's default GCC flags to avoid link errors
Ubuntu enables GCC's stack protector by default (see
https://wiki.ubuntu.com/Security/Features).  This causes link errors
like the following:

 ...undefined reference to `__stack_chk_fail'

To avoid these errors, this patch adds the "-fno-stack-protector" flag
to both the CFLAGS used by the Contiki build process and the CFLAGS
used by the newlib build process.
2015-12-21 08:06:14 -02:00
Andre Guedes a8849b2909 x86: Move bootstrap code and linker script to cpu/x86
This is a refactoring patch, no functionality is changed. It moves
loader.S and galileo.ld from platform/galileo/ to cpu/x86/ directory
since they seem to be more SoC-specific than platform-specific.

It also renames galileo.ld to quarkX1000.ld since it can be used by
any platform based on Quark X1000 SoC, not only Galileo.

Furthermore, this patch also renames loader.S to bootstrap_quarkX1000.S
since it is pretty much a bootstrap code to any platform based on Quark
X1000 SoC.
2015-12-21 08:06:14 -02:00
Jesus Sanchez-Palencia b2fa72bb98 x86: Break Makefile.x86 into common and pc specific ones
Now the cpu/x86/ provides a Makefile.x86_common and a
Makefile.x86_pc. The former includes the common Makefile
and adds legacy pc specific implementations (currently,
drivers only) into the building context, while the latter
has everything that defines the bootstrap of a x86 CPU.

This commit also fixes platform/galileo/ so it includes the
correct makefile - Makefile.x86_quarkX1000. Galileo uses
a Quark X1000 SoC which is not an IBM Generic PC-like CPU,
but it does provide most of a PCs peripherals through
its "Legacy Bridge". Thus, it makes sense that QuarkX1000's
Makefile includes code from the legacy_pc x86 cpu.
2015-12-21 08:06:14 -02:00
Jesus Sanchez-Palencia 23e8090257 x86: Move available drivers into drivers/legacy_pc/
All drivers implemented so far are for chips which are only available
on legacy x86 PCs. This commit moves them into a more appropriate folder,
also making the cpu/x86/drivers/ folder ready for other x86 based SoCs.
2015-12-21 08:06:14 -02:00
Jesus Sanchez-Palencia 9d3b9cadc4 galileo: Concentrate core implementations in platform/galileo/core/
Currently, it is common to see Contiki's core/ interfaces implementations
spread in both cpu/ and platform/. We here take one step further starting
an effort to centralize all of these in platform's code instead.

This commit starts this by adding platform/galileo/core/ and its sys/
subfolder, adding a stubbed mtarch.h and moving clock and rtimer
implementations to this new folder. From now on we should concentrate
implementation from Contiki's core/ interfaces into the appropriate
subfolder in platform/galileo/core/.

Note that this is not the current fashion followed on other platforms
and cpus folders, as most of them add the core interface implementation
into its subfolder directly. For instance, on CC2538DK,
core/dev/button-sensor.h is implemented in platform/cc2538dk/dev/
directly, while on Galileo it would sit at platform/galileo/core/dev/.
We believe ours is a better approach to organize and escalate a
platform's code base.

We also remove previous x86 mtarch.h and mtarch.c since they weren't used
at all - both native and cooja platforms have their own mtarch
implementations.
2015-12-21 08:06:14 -02:00
Andre Guedes 568f565b3d galileo: Update README.md file
This patch updates the README.md file, including information about the
current device drivers implementations as well as the Contiki APIs
supported.
2015-12-21 08:06:14 -02:00
Andre Guedes e4ff61ff6c galileo: Support for rtimer library
This patch adds support for rtimer library on Galileo's platform.

We use the PIT to implement the rtimer platform dependent
functionalities. We chose the PIT for mainly two reason: I) its
configuration is very simple II) it has a high frequency which
provides us a good clock resolution (requirement from rtimer
library).

Since we keep track of the number of ticks in software, we define
rtimer_clock_t type as uint64_t. This gives us a good amount of time
til the variable overflows. For instance, a 32-bit type would overflow
in about one hour for high clock resolution (~ 1us).

The rtimer clock frequency (RTIMER_ARCH_SECOND) is setup to 1 kHz.
There is no technical matter regarding this value. It is just an
initial guess.

Just for the record, we might want to use HPET in future to
implement the rtimer library since it seems to be more appropriate.
The reason why we don't use it at this moment is that, in order to
configure it, we need support for ACPI 2.0 which we don't. Once we
have use-cases for the rtimer library we'll probably replace PIT
by HPET or any other timer more suitable for the job.
2015-12-21 08:06:14 -02:00
Jesus Sanchez-Palencia 7c871871de galileo: Add support for Etimer and Ctimer libraries
This patch adds support for the Etimer and Ctimer libraries. To support
the Etimer library, we should poll the etimer process every time the
system clock is updated. To do this more efficiently, by taking advantage
of etimer_next_expiration_time() API, we poll the etimer process only
when an 'Event Timer' has expired.

We don't need any platform specific support in order to enable the Ctimer
library since it relies completely on Etimer.

The others timer libraries (Timer and Stime) don't required any specific
platform support as well since they rely on the system Clock module only.
2015-12-21 08:06:14 -02:00
Jesus Sanchez-Palencia eafcba5e7a galileo: Add support for Clock module
This patch adds support for Contiki's clock module. All functions from
core/sys/clock.h are implemented, except clock_set_seconds() and clock_
delay_usec(). The CLOCK_CONF_SECOND macro is set to 128. This value
seems to be good enough since several platforms used it. Finally, we
use the RTC driver to track the number of ticks from the system clock.
2015-12-21 08:06:14 -02:00
Jesus Sanchez-Palencia 11098501d8 x86: Initialize the 8259 PIC
The Programmable Interrupt Controller is a chip responsible for
translating hardware interrupts to system interrupts. When it
receives an Interrupt Request (IRQ), it triggers the appropriate
interrupt line reaching the appropriate IDT gate, following a
previously setup offset.

There are 2 daisy-chained PICs. PIC1 handles IRQs 0-7 and PIC2
handles IRQs 8-15. If no vector offset is set, an IRQ0, for instance,
would trigger the interrupt 0, clashing with the "Division by zero exception"
handler. Thus the IRQs must be remapped.

This patch implements the PICs initialization through their 4
Initialization Command Words (ICWs) in a very "canonical" way:
- ICW1: the initializing command;
- ICW2: the vector offset for the PIC1 and PIC2 (we add an offset of 32 positions);
- ICW3: the inter-PICs wiring setup (we connect PIC2 to PIC1's IRQ2);
- ICW4: extra systems information (we set PIC1 as Master and PIC2 as slave).

It then masks the Interrupt Mask Register, blocking all IRQs but #2 initially.
These must be unmasked on demand. The IMR is 8-bits long, so setting the n^th bit to 1
would DISABLE the IRQ n while setting it to 0 would ENABLE IRQ n.

As stated, this is an implementation of the legacy 8259 PIC. More
investigation is needed so we decide if it is enough or if we need
the (newer) APIC implementation instead.

This patch also adds the outb() helper function to helpers.h. The helpers
is a wrapper for assembly 'out' instruction.

Finally, since we now properly support hardware interrupts, this patch
also enables IRQs in platform main().

More information:
- Quark X1000 Datasheet, section 21.12, page 898.
- http://wiki.osdev.org/8259_PIC
- http://stanislavs.org/helppc/8259.html
2015-12-21 08:06:14 -02:00
Andre Guedes f6644d9208 x86: CPU Initialization
This patch defines the cpu_init() function which should encapsulate
all code related to x86 CPU initialization. For now, this function
initializes GDT and IDT.
2015-12-21 08:06:14 -02:00
Andre Guedes b8feaea30d x86: Add helpers.h
This patch adds the helpers.h. This file should contain only x86-related
helper functions and macros. For now, we define the BIT macro and halt()
helpers which will be used in upcoming patches.

Additionally, this patch also changes loader.S to call the halt().
2015-12-21 08:06:14 -02:00
Andre Guedes 6ecc4a7371 galileo: Implement main() function
This patch implements the main() function for Galileo platform. At this
moment, only Processes subsystem is enabled. After this patch we are
able to some rudimentary debugging to ensure that process thread from
applications are being indeed executed.

Once we properly support more Contiki subsystems, such as clock, ctimer,
etimer, and rtimer, we will add them to Galileo platform's main() as well.
2015-12-21 08:06:14 -02:00
Jesus Sanchez-Palencia 595088be09 galileo: Add a bootstrap stack for C runtime
All we need to provide to C at this point is a region in memory dedicated to
its stack. This is done by allocating a region in .bss and pushing its start
address to esp. Since the multiboot spec says it is not safe to rely on the
initial stack provided by the bootloader, this patch provides our own stack.

Galileo boards have 512Kb of SRAM and 256Mb of DDR3 RAM, so providing 8kb as
a start seems safe. Moreover, stack sizes are very application-oriented
so it may be too early to provide a bigger (or smaller) stack.
2015-12-21 08:06:14 -02:00
Andre Guedes 7a1898f73e galileo: Halt if main() returns
This patch adds extra intrunctions to loader.S so we halt if main()
returns.
2015-12-21 08:06:14 -02:00
Andre Guedes 7e13081776 galileo: Print elf sections sizes after build
This patch changes Galileo's buildsystem to print the elf sections
sizes after a new image is built. This way we can easily track how
these sections increase or decrease after any change.

To achieve that, we define a custom linking rule which is pretty much
the same as the default linking rule define in Makefile.include, but
we run 'size' command after the image is built.
2015-12-21 08:06:14 -02:00
Andre Guedes e820a8b03b galileo: Add README file
This patch adds a README file which contains general information about
the Intel Galileo board support. The file provides information about
supported features as well as instructions on how to build, run and debug
applications for this platform.
2015-12-21 08:06:14 -02:00