From cff737a8dc81ed7121954eb02b3d05573849ec7f Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Fri, 29 Jun 2018 17:43:19 +0300 Subject: [PATCH] apeos for posix --- .gitignore | 1 + GNUmakefile | 21 ++++++++++++ doc/boot.txt | 7 ++-- include/apeos/apeos.h | 36 +++++++++++++++++++++ include/apeos/boot.h | 28 ++++++++++++++++ include/apeos/hw.h | 27 ++++++++++++++++ posix.mk | 24 ++++++++++++++ program.mk | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/boot.c | 30 +++++++++++++++++ src/posix.c | 60 ++++++++++++++++++++++++++++++++++ 10 files changed, 320 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 GNUmakefile create mode 100644 include/apeos/apeos.h create mode 100644 include/apeos/boot.h create mode 100644 include/apeos/hw.h create mode 100644 posix.mk create mode 100644 program.mk create mode 100644 src/boot.c create mode 100644 src/posix.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..e62d7ff --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,21 @@ +# Copyright 2018 apeos contributors +# +# apeos main makefile, GNU make +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +APEOS_VERSION := $(shell printf "%s" "$(shell git rev-parse HEAD)"; if test -n "$(shell git status -s)"; then printf "%s" -dirty; fi) +ifndef MAKE_RESTARTS +$(warning APEOS_VERSION="$(APEOS_VERSION)") +endif diff --git a/doc/boot.txt b/doc/boot.txt index 85636f3..35e07a1 100644 --- a/doc/boot.txt +++ b/doc/boot.txt @@ -1,6 +1,5 @@ Copyright 2018 apeos contributors -Boot process is the esp-idf boot process, with bootloader, partition -table and at least one application partition. The bootloader and -application messages showing boot progress are sent to UART0. Then -the application provides text shell through UART0. +Boot process starts at apeos_boot() function, in boot.c +Messages showing boot progress are sent to UART0. Then +text shell accessible through UART0 is started. diff --git a/include/apeos/apeos.h b/include/apeos/apeos.h new file mode 100644 index 0000000..cab513c --- /dev/null +++ b/include/apeos/apeos.h @@ -0,0 +1,36 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * Copyright 2018 apeos contributors + * + * apeos common definitions + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef APEOS_H__6253DA2F_EC5A_4D19_82AE_BA63F09A32D7__INCLUDED +#define APEOS_H__6253DA2F_EC5A_4D19_82AE_BA63F09A32D7__INCLUDED + +/* c runtime */ +#include +#include +#include +#include +#include + +/* posix */ +#include +#include +#include +#include + +#endif /* #ifndef APEOS_H__6253DA2F_EC5A_4D19_82AE_BA63F09A32D7__INCLUDED */ diff --git a/include/apeos/boot.h b/include/apeos/boot.h new file mode 100644 index 0000000..22cdd62 --- /dev/null +++ b/include/apeos/boot.h @@ -0,0 +1,28 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * Copyright 2018 apeos contributors + * + * apeos boot + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef BOOT_H__5A0C61BE_63F3_433A_8C7F_822B61DDDDA3__INCLUDED +#define BOOT_H__5A0C61BE_63F3_433A_8C7F_822B61DDDDA3__INCLUDED + +/** + * This function is the apeos boot entry + */ +void apeos_boot(void); + +#endif /* #ifndef BOOT_H__5A0C61BE_63F3_433A_8C7F_822B61DDDDA3__INCLUDED */ diff --git a/include/apeos/hw.h b/include/apeos/hw.h new file mode 100644 index 0000000..5dcfb47 --- /dev/null +++ b/include/apeos/hw.h @@ -0,0 +1,27 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * Copyright 2018 apeos contributors + * + * apeos hardware interface functions + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef HW_H__A9C789E7_16C2_4F4C_A982_90F8483D0CBF__INCLUDED +#define HW_H__A9C789E7_16C2_4F4C_A982_90F8483D0CBF__INCLUDED + +void hw_init(void); +void hw_uninit(void); +void hw_info(void); + +#endif /* #ifndef HW_H__A9C789E7_16C2_4F4C_A982_90F8483D0CBF__INCLUDED */ diff --git a/posix.mk b/posix.mk new file mode 100644 index 0000000..e63a69f --- /dev/null +++ b/posix.mk @@ -0,0 +1,24 @@ +# Copyright 2018 apeos contributors +# +# apeos GNU makefile, build native apeos on posix host +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +BIN := apeos + +# files in /src/ to build apeos posix binary from +SRCS := posix.c +SRCS += boot.c + +include program.mk diff --git a/program.mk b/program.mk new file mode 100644 index 0000000..de2c130 --- /dev/null +++ b/program.mk @@ -0,0 +1,90 @@ +# Copyright 2018 apeos contributors +# +# apeos partial GNU makefile, build binary program from C sources +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# variables that have to be set before evaulating this program: +# +# BIN - name of the resulting binary program +# SRCS - whitespace separated list of source filenames in /src/, +# without /src/ prefix. + +TOP_DIR := $(shell pwd) +#$(warning TOP_DIR=$(TOP_DIR)) +BUILD_DIR_BASE := $(TOP_DIR)/build +#$(warning BUILD_DIR_BASE=$(BUILD_DIR_BASE)) +BUILD_PREFIX := $(BUILD_DIR_BASE)/$(BIN)- +#$(warning BUILD_PREFIX=$(BUILD_PREFIX)) +SRC_DIR := $(TOP_DIR)/src + +BIN_PATH := $(BUILD_DIR_BASE)/$(BIN) + +# by default, create the resulting binary file +.PHONY: default +default: $(BIN_PATH) + @file $(BIN_PATH) + +#$(warning SRC_DIR=$(SRC_DIR)) +SRCS_PREFIXED := $(addprefix $(SRC_DIR)/,$(SRCS)) +#$(warning SRCS_PREFIXED="$(SRCS_PREFIXED)") +OBJS := $(addprefix $(BUILD_PREFIX),$(patsubst %.c,%.o,$(SRCS))) +#$(warning OBJS="$(OBJS)") + +BUILT_FILES := $(OBJS) $(BIN) + +$(BUILT_FILES): program.mk + +CPPFLAGS := -I include + +CFLAGS := -pipe +LDFLAGS := + +ifeq ($(CFG),debug) +CFLAGS += -O0 +CFLAGS += -g +LDFLAGS += -g +endif +ifeq ($(CFG),size) +CFLAGS := -Os +endif + +CFLAGS += -static +LDFLAGS += -static + +# gcc +CC := $(GCC_PREFIX)gcc +LD := $(GCC_PREFIX)gcc + +ifneq ($(V),1) +CC := @$(CC) +LD := @$(LD) +endif + +$(BUILD_DIR_BASE): + @mkdir -v $@ + +$(BUILT_FILES): $(BUILD_DIR_BASE) + +$(BUILD_PREFIX)%.o: $(SRC_DIR)/%.c + @echo [CC] $(shell basename $<) + $(CC) -c $< $(CPPFLAGS) $(CFLAGS) -o $@ + +$(BIN_PATH): $(OBJS) + @echo [LD] $(BIN) + $(LD) $(OBJS) $(LDFLAGS) -o $@ + +.PHONY: clean +clean: + @rm -vf $(BUILT_FILES) diff --git a/src/boot.c b/src/boot.c new file mode 100644 index 0000000..fcc96c8 --- /dev/null +++ b/src/boot.c @@ -0,0 +1,30 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * Copyright 2018 apeos contributors + * + * apeos boot entry + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +void apeos_boot(void) +{ + hw_init(); + hw_info(); + hw_uninit(); +} diff --git a/src/posix.c b/src/posix.c new file mode 100644 index 0000000..aedaaf7 --- /dev/null +++ b/src/posix.c @@ -0,0 +1,60 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * Copyright 2018 apeos contributors + * + * host apeos on posix system + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include +#include +#include + +void hw_init(void) +{ + printf("apeos booting\n"); +} + +void hw_uninit(void) +{ + exit(0); +} + +void hw_info(void) +{ + struct utsname info; + + printf("POSIX"); + if (uname(&info) == 0) + { + printf( + " %s [%s %s %s] %s", + info.machine, + info.sysname, + info.release, + info.version, + info.nodename); + } + printf("\n"); +} + +int main(void) +{ + apeos_boot(); +} -- 2.11.4.GIT