Mips linux uclibc gcc

Компиляция своих пакетов на С для OpenWrt

Здравствуйте! Подскажите, пожалуйста, такая проблема, сам уже не в силах разобраться. Не компилируется файл на С для Openwrt. Пробовал на Убунту 12, 14, 18 и на всякий пожарный на CentOS 7. Качаю исходники Openwrt, запускаю make menuconfig, мой пакет видит. Пытаюсь компилировать. В конце вылетает ошибка

cp: cannot stat ‘/home/dmitry/openwrt/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/lib/libgcc_s.so.*’: No such file or directory make[2]: *** [/home/dmitry/openwrt/bin/targets/ar71xx/generic/packages/libgcc_unknown-1_mips_24kc.ipk] Error 1 make[2]: Leaving directory /home/dmitry/openwrt/package/libs/toolchain’ make[1]: *** [package/libs/toolchain/compile] Error 2 make[1]: Leaving directory /home/dmitry/openwrt’ make: *** [package/program1/compile] Error 2

Что с этим можно сделать? Или кто-то подскажет как скомпилировать программу на С для Openwrt? Пробовал через гцц на виртуалке, но когда с виртуалки закидываю в роутер Микротик, у него syntax error, я так понимаю, платформа не подходит?

Для чего, собственно, это нужно, что б не было скриптов .sh. Пробовал через shc, он из .sh делает .с, но у openwrt syntax error все равно, хотя убунту .с запускает.

ЯННП. Что значит «скомпилировать из С в Openwrt?» Это всё равно, что «скомпилировать из Pascal в RedHat», то есть, белиберда какая-то. И чем тебе помешали .sh, что ты от них избавиться хочешь?

ты бы makefile-ы хоть показал

Так написал просто, изменил

как скомпилировать программу на С для Openwrt?

Так же, как и для любого другого дистрибутива. Короче, показывай Makefile, как уже выше писали

cp: cannot stat ‘/home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libuClibc-*.so’: No such file or directory cp: cannot stat ‘/home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libcrypt-*.so’: No such file or directory cp: cannot stat ‘/home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libm-*.so’: No such file or directory make[2]: *** [/home/dmitry/archive/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/.built] Error 1 make[2]: Leaving directory /home/dmitry/archive/package/libs/toolchain’ make[1]: *** [package/libs/toolchain/compile] Error 2 make[1]: Leaving directory /home/dmitry/archive’ make: *** [package/program1/compile] Error 2

PKG_NAME:=program1
PKG_VERSION:=1.0
PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk
define Package/program1
SECTION:=utils
CATEGORY:=Utilities
TITLE:=program1 — Test program
endef

define Package/program1/description
program1 — Test program
endef

define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
$(TARGET_CC) $(TARGET_CFLAGS) -c -o
$(PKG_BUILD_DIR)/program1.o $(PKG_BUILD_DIR)/program1.c
$(TARGET_CC) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/program1 $(PKG_BUILD_DIR)/program1.o
endef

define Package/program1/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/program1 $(1)/bin/
endef

$(eval $(call BuildPackage,program1))

Я, конечно, Make плохо знаю, но вот это выглядит довольно странно:

Ты директорией назначаешь сишник. Может, sergej , который тоже хотел Makefile, меня поправит, но мне кажется, что это неправильно.

Далее, оно у тебя ругается на cp:

cp: cannot stat ‘/home/dmitry/openwrt/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/lib/libgcc_s.so.*’: No such file or directory

Я не вижу, где бы оно явно дёргалось в твоём мейкфайле, поэтому попробуй убедиться, что твой модуль не пытается собраться до того, как соберётся тулчейн

Да, исправил на SOURCE_DIR:=/home/dmitry/archive/package/program1/src

Вот полный вывод по команде make package/program1/compile V=s

Collecting package info: done
make[1]: Entering directory /home/dmitry/archive’ make[2]: Entering directory /home/dmitry/archive/package/libs/toolchain’
cp -fpR /home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libuClibc-.so /home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libcrypt-.so /home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libm-.so /home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libpthread-.so /home/dmitry/archive/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/
cp: cannot stat ‘/home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libuClibc-*.so’: No such file or directory
cp: cannot stat ‘/home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libcrypt-*.so’: No such file or directory
cp: cannot stat ‘/home/dmitry/archive/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/libm-*.so’: No such file or directory
make[2]: *** [/home/dmitry/archive/build_dir/target-mips_34kc_uClibc-0.9.33.2/toolchain/.built] Error 1
make[2]: Leaving directory /home/dmitry/archive/package/libs/toolchain’ make[1]: *** [package/libs/toolchain/compile] Error 2 make[1]: Leaving directory /home/dmitry/archive’
make: *** [package/program1/compile] Error 2

У тебя тулчейн не собран. Собери для начала его

ОК. Сначала собрал make tools/install. Собралось
Собираю

/home/dmitry/archive# make toolchain/install
make[1] toolchain/install
make[2] -C toolchain/gdb prepare
make[2] -C toolchain/gdb compile
make[2] -C toolchain/gdb install
make[2] -C toolchain/binutils prepare
make[2] -C toolchain/binutils compile
make[2] -C toolchain/binutils install
make[2] -C toolchain/gcc/minimal prepare
make[2] -C toolchain/gcc/minimal compile
make[2] -C toolchain/gcc/minimal install
make[2] -C toolchain/kernel-headers prepare
make -r toolchain/install: build failed. Please re-run make with V=s to see what’s going on
make: *** [toolchain/install] Error 1

Читайте также:  Windows need to format disk before use

С ключом V=s вывод (весь писать не буду, там он коннектится к зеркалам и ничего не находит.

Download failed.
No more mirrors to try — giving up.
make[2]: *** [/home/dmitry/archive/dl/linux-3.10.49.tar.xz] Error 2
make[2]: Leaving directory /home/dmitry/archive/toolchain/kernel-headers’ make[1]: *** [toolchain/kernel-headers/prepare] Error 2 make[1]: Leaving directory /home/dmitry/archive’
make: *** [toolchain/install] Error 2

Что-то не может скачать — нет зеркал. Либо у тебя набор сорцов старый, и нужно взять посвежее, либо имеющиеся зеркала с того компа недоступны, и разбираться стоит с этим

Источник

Toolchains

A toolchain is a complete collection of compiler and binutils programs and can be run either as a cross-compiler, or native on the target (if performance allows).

Contents

Pre-built/Build Kits

MIPS SDE

MIPS Technologies UK maintains their own source tree for the toolchain components. SDE combines all necessary GNU tools, is infrequently resynchronized with mainstream GNU releases (which inevitably have bugs for less widely used architectures such as MIPS) and focuses on supporting the full range of ISAs, ASEs and cores, as well as providing the most reliable, best-performing compiler for the largest range of MIPS CPUs. See MIPS SDE Installation. Note that the pre-built cross-compiler is only suitable for building a Linux kernel, and cannot be used to create Linux applications or shared objects. Note: We have been using the sde toolkit for both shared objects and applications. Maybe the issue was fixed?

Maciej W. Rozycki

A stable set of toolchain components provided by Maciej can be downloaded from ftp://ftp.linux-mips.org/pub/linux/mips/people/macro/. This is based on GCC 2.95.3 (patched) and up-to-date binutils. Versions 4.0.1 and 4.1.2 of GCC are available too.

The former mirror at ftp.rfc822.org is now gone. Thanks, Florian, for providing this service over the years.

Dan Kegel

Dan Kegel has a page at http://kegel.com/crosstool/ with a nice script to automatize the build procedure. Crosstool can only generate toolchains that use the GNU C Library, support for the smaller C Library http://www.uclibc.org uClibc might be added in the future.

H.J.Lu distributes a toolchain as part of his Red Hat 7.1 port. It can be found at ftp://ftp.linux-mips.org/pub/linux/mips/redhat/7.1/ . This toolchain-20020423-1.rpm is based on the RedHat’s GCC 2.96, binutils 2.13 and glibc 2.2.5 .

uClibc Toolchain and Buildroot

uClibc developers provide tools to generate toolchains and root filesystems with the uClibc standard C library.

The Toolchain tool allows to generate a toolchain for a variety of architectures, including MIPS and MIPSel.

The Buildroot tool allows to generate both a toolchain and a root filesystem for a variety of architectures, including MIPS and MIPSel. Using a configuration tool (similar to the one used for the Linux Kernel), you can select compiler version, binutils version, and all softwares that should be included in the root filesystem. Then the Makefiles will automatically download, configure, compile, install and generate the toolchain and the root filesystem image.

OpenEmbedded

The OpenEmbedded meta distribution also includes an automatic build of a full cross-toolchain for it’s target architecture. http://www.openembedded.org

DENX ELDK

DENX Software Engineering provides the ELDK (Embedded Linux Development Kit), which includes both cross development and native tools for big and little endian MIPS processors (also for ARM and PowerPC). As it is Free Software it can be downloaded for FREE. See http://www.denx.de/wiki/DULG/ELDK

Gentoo crossdev

Gentoo provides a tool for creating full cross-compiling toolchains for a number of targets. On any Gentoo system, set up PORTAGE_OVERLAY in make.conf, then emerge crossdev to install it. Using a small startup shell script, these toolchains can be used with distcc as well, to allow distribution of a compile job over a cluster.

Debian

Embedded Debian project provides cross toolchains for various platforms, including mips and mipsel.

An alternative repository with newer toolchains built from Debian sources is available from [1].

Читайте также:  Install mac os high sierra dmg

Sourcery CodeBench Lite Edition

Mentor Graphics provides pre-built MIPS toolchains for x86 and x86_64 hosts. Apart from the core toolchain components (binutils, gcc), the package also includes gdb, gdbserver and qemu. As of the time of writing, the N32 ABI is not supported by this toolchain.

Commercial Toolchains

All commercial Linux/MIPS distributions come with appropriate toolchain deliverables.

Cygwin

Here is a first attempt at GCC 4.9.2 and Binutils 2.25 compiled on/for 32-bit Cygwin and targeting mips-unknown-linux-gnu. Untested for Linux kernel builds.

Roll-your-own

You’re adverse to using someone else’s toolchains, and cannot remember how to build one yourself, no matter how hard you try. Fear not. Outlined here is the proceedure to build a bootstrap toolchain; one which is minus the C library and is just enough to build the kernel.

Prologue

What you’ll need:

Note that in general you want to use the latest versions released by the time a kernel was released. The versions listed here are known to be working well for recent kernels as of the time of writing. Using tools more recent than the kernel means that combination will not have been tested exhaustively so the likelihood of encountering incompatibilities increases. Sometimes tool compatibility versions are fixed in -stable but there is no guarantee that this also covers your favorite esoteric configuration.

Now, export a few environment variables for your convenience. If you’re building for big-endian MIPS, your TARGET should be mips-unknown-linux-gnu instead. If you wish to install to a different location other than /opt/cross/, substitute in your PREFIX accordingly. A common alternative is /usr/local/.

You’ll need to re-export your PATH with the new install location so when building a bootstrap gcc, it may locate the shiny new cross-binutils:

Now change to the staging directory:

Binutils

Extract, configure, build and install:

You should now have the cross-binutils installed under $ /bin/ with names prefixed by mipsel-unknown-linux-gnu-* (or mips-unknown-linux-gnu-* if you’re building for big-endian MIPS).

Extract, configure, build and install a bootstrap GCC.

Enable any other language front-ends as you see fit. For building the kernel however, you can get away with just the C language front-end. Also, tell the configure script not to look for target libc headers — we don’t have them, and don’t need them at this point.

You’ll need this for debugging either the kernel (with KGDB) or userspace (natively or with gdbserver ). If this doesn’t apply in your case, you may safely skip this section.

Extract, configure, build and install:

Summary

Your shiny new toolchain should be in your PATH , given you re-exported it earlier. Otherwise, you’ll need to prefix your PATH with:

Источник

Mips linux uclibc gcc

mips-linux-uclibc cross-toolchain on Gentoo

This document aims to guide the reader to creating their own mips-linux-uclibc toolchain using tools provided by Gentoo linux. The versions and configurations used here are not totally vanilla and thus need more hands-on involvement than just running a long magic command.

Resulting (stage 3) toolchain will contain following versions of various packages (excluding Gentoo revisions):

  • gcc-6.4.0 C-compiler (different/more recent version may probably be used freely)
  • binutils-2.29.1 (different/more recent version may probably be used freely)
  • uclibc-0.9.33.2 (must mostly match TARGET uclibc version)
  • linux-headers-2.6.10 (must mostly match TARGET kernel version)

Caveat: Originally the TARGET would have needed uclibc-0.9.30 but as that does not work with recent binutils and sufficiently old version (i.e. binutils-0.20 ) is not easily found, 0.9.33.2 is used here. It may work with 0.9.30 libc on TARGET, but ymmv.

This documentation is licensed under CC-BY-SA-4.0. The files/1-makefile.patch is licensed under GNU General Public License 2.

  • mips1 TARGET CPU. (mips1..mips4 and mips32..mips32r5 probably work.)
  • Gentoo linux HOST with root shell. sudo works too if that is installed and preferred. All commands here are to be run as root unless otherwise noted.
  • sys-devel/crossdev . Version 20171230 is used in this guide, more recent may work, ymmv.
  • sys-devel/binutils is at version 2.29.1-r1 , and sys-libs/binutils-libs has same (‘ish) or more recent version.
  • Portage contains sys-libs/uclibc-0.9.33.2-r15 . The 0.9.33.9999 version can also be used.
  • The HOST Gentoo has local portage overlay configured. If not, follow Defining a custom repository in Gentoo handbook.
Читайте также:  Домашний медиа сервер для windows 10 как настроить

Setting up the custom ebuilds

The required 2.6.10 is not found on portage anymore, but 2.4.36 still is. Here we use that as a base for the required 2.6.10 version.

Next we need a patch file to fix the linux-headers-2.6.10 source package. The 1-makefile.patch (in raw form) must be copied in the previously created files -directory, or more specifically, into /usr/local/portage/sys-kernel/linux-headers/files . After that, the 2.6.10 ebuild must be modified of few variables so that the patch is actually applied, and no other patches are tried, and that the package is actually supported on mips:

To finish this step, build Manifest of the ebuild, patch, and source package (which is downloaded automatically):

Checkup: Ensure that running the find -command below results in list below (order may vary). This may be done as regular user.

By the time of writing this, the uclibc-0.9.* ebuilds are not working correctly, due a bug. Fortunately, the ticket contains a fix in comment #5. Download that attachment (named uclibc.ebuild-001-mips.patch ) to somewhere, e.g. /tmp

Checkup: As before, ensure stuff are in correct places. The actual ebuilds may differ if optional steps were followed in above snippet.

Ebuilds prepared we can now use the Gentoo Cross-toolchain generator aka crossdev to build the toolchain. For gcc we disable PIE (although this may not be required). For uclibc we disable nptl as there seems to not be support for it in mips. Please note of the amount of dashes, equal signs and hyphens.

Somewhat detailed description:

  • -ol and -ok guide crossdev to read libc and kernel-/linux-headers ebuilds from given overlay (instead of Gentoo portage), as we just created thoose.
  • -s3 makes crossdev to build stage3 toolchain containing binutils ( -s0 ), gcc ( -s1 ), kernel headers ( -s2 ) and libc ( -s3 ).
  • —genv and —lenv adds environment variables to gcc and libc build processes, respectively.
  • —b declares binutils ebuild version to use.
  • —l declares libc ebuild version to use.
  • —k declares linux-headers ebuild version to use.
  • —g declares gcc ebuild version to use.
  • —target mips-example-linux-uclibc declares the toolchain name in form ARCH-VENDOR-OS-LIBC [crossdev —help].
  • Optional -P -v adds -v to portage command line, giving verbose output from the build process.

The command creates a new category cross-mips-example-linux-uclibc in the portage for the cross-toolchain located in the local overlay: /usr/local/portage/cross-mips-example-linux-uclibc . The new sysroot resides in /usr/mips-example-linux-uclibc . Files in the installed packages can be seen with equery files as usual, but the cross-category should be included in the requested name, e.g. equery files cross-mips-example-linux-uclibc/gcc ( equery tool belongs to app-portage/gentoolkit package).

Write into hello.c :

Then run the newly created compiler on the file:

Then copy the resulting ELF binary to the MIPS machine and run it.

Removing the toolchain (totally optional)

To remove the installed toolchain parts, the toolchain portage package category and configuration files related to the toolchain, run following:

This does not remove the self-created ebuilds in overlay, allowing to continue from Actual building later if needed.

About

Guide for building cross-toolchain on Gentoo for mips with kernel 2.6.10 and uclibc-0.9.3x

Источник

Оцените статью