From f14f9aba4109c6693ce1db0b87c73e5d2cb03f08 Mon Sep 17 00:00:00 2001 From: Jesus Sanchez-Palencia Date: Wed, 1 Jul 2015 16:43:42 -0300 Subject: [PATCH] galileo: Initial support for Intel Galileo Platform This patch adds the initial support for Intel Galileo Platform. It contains the minimum set of code required to boot a dummy Contiki image. For Galileo initial support, we implemented a linker script, a minimal bootstrap code, a set of stubbed functions required by newlib, and a very simple main() function. Moreover, we also define some header files and macros required by Contiki. To build applications for this platform you should first build newlib (in case it wasn't already built). To build newlib you can run the following command: $ platform/galileo/bsp/libc/build_newlib.sh Once newlib is built, you can build applications. To build applications for Galileo platform you should set TARGET variable to 'galileo'. For instance, building the hello-world application should look like this: $ cd examples/hello-world/ && make TARGET=galileo This will generate the 'hello-world.galileo' file which is a multiboot- compliant [1] ELF image. This image can be booted by any multiboot- complaint bootloader such as Grub. Finally, this patch should be used as a guideline to add the initial support for others platforms based on x86 SoCs. [1] https://www.gnu.org/software/grub/manual/multiboot/multiboot.html --- .gitignore | 3 + platform/galileo/Makefile.galileo | 20 ++++++ platform/galileo/contiki-conf.h | 45 +++++++++++++ platform/galileo/contiki-main.c | 35 ++++++++++ platform/galileo/galileo.ld | 69 +++++++++++++++++++ platform/galileo/loader.S | 45 +++++++++++++ platform/galileo/newlib-syscalls.c | 102 +++++++++++++++++++++++++++++ platform/galileo/rtimer-arch.h | 34 ++++++++++ 8 files changed, 353 insertions(+) create mode 100644 platform/galileo/Makefile.galileo create mode 100644 platform/galileo/contiki-conf.h create mode 100644 platform/galileo/contiki-main.c create mode 100644 platform/galileo/galileo.ld create mode 100644 platform/galileo/loader.S create mode 100644 platform/galileo/newlib-syscalls.c create mode 100644 platform/galileo/rtimer-arch.h diff --git a/.gitignore b/.gitignore index 299193bae..02b314dfc 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,6 @@ platform/galileo/bsp/libc/i586-elf/ platform/galileo/bsp/libc/newlib-2.2.0-1* platform/galileo/bsp/grub/src/ platform/galileo/bsp/grub/bin/ + +# galileo build artefacts +*.galileo diff --git a/platform/galileo/Makefile.galileo b/platform/galileo/Makefile.galileo new file mode 100644 index 000000000..ead4e7441 --- /dev/null +++ b/platform/galileo/Makefile.galileo @@ -0,0 +1,20 @@ +LIBC=$(CONTIKI)/platform/galileo/bsp/libc/i586-elf +LIBGCC_PATH = /usr/lib/gcc/$(shell gcc -dumpmachine)/$(shell gcc -dumpversion) + +CONTIKI_TARGET_DIRS = . +CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o} +CONTIKI_SOURCEFILES += contiki-main.c newlib-syscalls.c loader.S + +LINKERSCRIPT = $(CONTIKI)/platform/galileo/galileo.ld + +CONTIKI_CPU=$(CONTIKI)/cpu/x86 +include $(CONTIKI)/cpu/x86/Makefile.x86 + +CFLAGS += -m32 -march=i586 -nostdinc -isystem $(LIBC)/include -isystem $(LIBGCC_PATH)/include -isystem $(LIBGCC_PATH)/include-fixed +LDFLAGS += -m32 -nostdlib -T $(LINKERSCRIPT) +ASFLAGS += --32 -march=i586 -mtune=i586 + +# Ideally, this should be part of LDFLAGS (-lc -lm etc). However, we found out that archive +# static files (.a) must be linked after our own object files, otherwise the linker gets lost +# and we get undefined references only. +TARGET_LIBFILES = $(OBJECTDIR)/newlib-syscalls.o $(LIBC)/lib/libm.a $(LIBC)/lib/libc.a $(LIBGCC_PATH)/32/libgcc.a diff --git a/platform/galileo/contiki-conf.h b/platform/galileo/contiki-conf.h new file mode 100644 index 000000000..4df707d8a --- /dev/null +++ b/platform/galileo/contiki-conf.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015, Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CONTIKI_CONF_H +#define CONTIKI_CONF_H + +#include + +/* We define the following macros and types otherwise Contiki does not + * compile. + */ +#define CCIF +#define CLIF + +typedef unsigned long clock_time_t; +typedef unsigned short uip_stats_t; + +#endif /* CONTIKI_CONF_H */ diff --git a/platform/galileo/contiki-main.c b/platform/galileo/contiki-main.c new file mode 100644 index 000000000..76ad75e57 --- /dev/null +++ b/platform/galileo/contiki-main.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2015, Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +int +main(void) +{ + return 0; +} diff --git a/platform/galileo/galileo.ld b/platform/galileo/galileo.ld new file mode 100644 index 000000000..e703b9f1d --- /dev/null +++ b/platform/galileo/galileo.ld @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2015, Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +OUTPUT_FORMAT("elf32-i386") + +ENTRY(start) + +SECTIONS { + /* + OS-Dev Wiki says it is common for kernels to start at 1M. Addresses before that + are used by BIOS/EFI, the bootloader and memory-mapped I/O. + */ + . = 1M; + + .text ALIGN (4K) : + { + *(.multiboot) + *(.text) + } + + .rodata ALIGN (4K) : + { + *(.rodata*) + } + + .data ALIGN (4K) : + { + *(.data) + } + + .bss ALIGN (4K) : + { + *(COMMON) + *(.bss) + } + + /* Put this here so it doesn't sit above the multiboot section. */ + .note.gnu.build-id : + { + *(.note.gnu.build-id) + } +} diff --git a/platform/galileo/loader.S b/platform/galileo/loader.S new file mode 100644 index 000000000..66edacd08 --- /dev/null +++ b/platform/galileo/loader.S @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015, Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +.set MAGIC_NUMBER, 0x1BADB002 +.set FLAGS, 0x0 +.set CHECKSUM, -MAGIC_NUMBER + +.section .multiboot +.align 4 +.long MAGIC_NUMBER +.long FLAGS +.long CHECKSUM + +.section .text +.global start +start: + cli + call main diff --git a/platform/galileo/newlib-syscalls.c b/platform/galileo/newlib-syscalls.c new file mode 100644 index 000000000..5a7831857 --- /dev/null +++ b/platform/galileo/newlib-syscalls.c @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2015, Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +int +_close_r(struct _reent *ptr, int file) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return -1; +} +/*---------------------------------------------------------------------------*/ +int +_isatty_r(struct _reent *ptr, int file) +{ + /* Stubbed function */ + return 0; +} +/*---------------------------------------------------------------------------*/ +int +_read_r(struct _reent *ptr, int file, char *buf, int len) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return 0; +} +/*---------------------------------------------------------------------------*/ +int +_write_r(struct _reent *ptr, int file, const char *buf, int len) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return -1; +} +/*---------------------------------------------------------------------------*/ +int +_lseek_r(struct _reent *ptr, int file, int p, int dir) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return 0; +} +/*---------------------------------------------------------------------------*/ +int +_fstat_r(struct _reent *ptr, int file, struct stat *st) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return -1; +} +/*---------------------------------------------------------------------------*/ +caddr_t +_sbrk_r(struct _reent *ptr, int incr) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return NULL; +} +/*---------------------------------------------------------------------------*/ +void +_kill_r(struct _reent *ptr) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; +} +/*---------------------------------------------------------------------------*/ +int +_getpid_r(struct _reent *ptr) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return 1; +} diff --git a/platform/galileo/rtimer-arch.h b/platform/galileo/rtimer-arch.h new file mode 100644 index 000000000..086602aa2 --- /dev/null +++ b/platform/galileo/rtimer-arch.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015, Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RTIMER_ARCH_H +#define RTIMER_ARCH_H + +#endif /* RTIMER_ARCH_H */