This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 532a5af5721273a905dd4eee73ca54af7a2a4df0 Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> AuthorDate: Wed May 31 13:12:48 2023 +0200 libc: Add newlib-nano support If default baselibc does not provide functionality application needs it is possible now to set syscfg LIBC to nano to disable baselibc and enabled gcc provided newlib-nano Signed-off-by: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl> --- libc/nano/pkg.yml | 31 +++++++++++++++++++ libc/nano/src/start.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ libc/nano/src/syscalls.c | 69 +++++++++++++++++++++++++++++++++++++++++ libc/pkg.yml | 29 ++++++++++++++++++ libc/syscfg.yml | 27 ++++++++++++++++ 5 files changed, 236 insertions(+) diff --git a/libc/nano/pkg.yml b/libc/nano/pkg.yml new file mode 100644 index 000000000..e9391eacd --- /dev/null +++ b/libc/nano/pkg.yml @@ -0,0 +1,31 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: libc/nano +pkg.description: Newlib nano for embedded mynewt. +pkg.keywords: + - libc + +pkg.deps: + +pkg.lflags: + - -specs=nano.specs + - -u_close + - -u_sbrk + diff --git a/libc/nano/src/start.c b/libc/nano/src/start.c new file mode 100644 index 000000000..4aaaf997e --- /dev/null +++ b/libc/nano/src/start.c @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdlib.h> +#include "os/mynewt.h" + +extern int main(int argc, char **argv); +void __libc_init_array(void); + +/* + * Rudimentary startup function. + */ +void _start(void) +{ + /* + * Run global objects constructors. + * Call to this function is ofter found in startup files. + * mynewt did not use this pattern hence we have single place + * for all MCU just here + */ + __libc_init_array(); + +#if !MYNEWT_VAL(OS_SCHEDULING) + int rc; + + rc = main(0, NULL); + exit(rc); +#else + os_init(main); + os_start(); +#endif +} + +__attribute__((weak)) void +_init(void) +{ +} + +__attribute__((weak)) void +_fini(void) +{ +} + +extern void (*__preinit_array_start[])(void); +extern void (*__preinit_array_end[])(void); +extern void (*__init_array_start[])(void); +extern void (*__init_array_end[])(void); + +void +__libc_init_array(void) +{ + size_t count; + size_t i; + + count = __preinit_array_end - __preinit_array_start; + for (i = 0; i < count; i++) + __preinit_array_start[i](); + + _init(); + + count = __init_array_end - __init_array_start; + for (i = 0; i < count; i++) + __init_array_start[i](); +} diff --git a/libc/nano/src/syscalls.c b/libc/nano/src/syscalls.c new file mode 100644 index 000000000..644cf0672 --- /dev/null +++ b/libc/nano/src/syscalls.c @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <sys/stat.h> +#include <syscfg/syscfg.h> + +#include <console/console.h> + +int +_write(int fd, char *ptr, int len) +{ + (void)fd, (void)ptr; + + if (fd == 1 || fd == 2) { + console_write(ptr, len); + } + return len; +} + +int +_close(int fd) +{ + (void)fd; + return 0; +} + +int +_fstat(int fd, struct stat *st) +{ + (void)fd, (void)st; + return 0; +} + +int +_isatty(int fd) +{ + (void)fd; + return 0; +} + +int +_read(int fd, char *ptr, int len) +{ + (void)fd, (void)ptr, (void)len; + return 0; +} + +int +_lseek(int fd, int ptr, int dir) +{ + (void)fd, (void)ptr, (void)dir; + return 0; +} diff --git a/libc/pkg.yml b/libc/pkg.yml new file mode 100644 index 000000000..ba7caa8ed --- /dev/null +++ b/libc/pkg.yml @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: libc +pkg.description: Standard C library selector. +pkg.keywords: + - libc + +pkg.deps.'LIBC=="baselibc"': + - libc/baselibc + +pkg.deps.'LIBC=="nano"': + - libc/nano diff --git a/libc/syscfg.yml b/libc/syscfg.yml new file mode 100644 index 000000000..c4a242b1c --- /dev/null +++ b/libc/syscfg.yml @@ -0,0 +1,27 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +syscfg.defs: + LIBC: + description: "Chooses c library implementation" + value: baselibc + choices: + - baselibc + # nano is provided by gcc + - nano