宿主目标开发模型
我对嵌入式Linux编程很陌生,并没有真正理解这个概念。
谁能解释一下“宿主-目标”关系的本质?这个模型只针对“交叉编译”吗?使用它只是因为“可执行代码将在另一个环境上运行”吗?目标上的 Linux 内核有什么重要的?例如,《构建嵌入式Linux系统》一书提到了这一点,但没有解释其此类开发的动机或目标。
多谢。
I am quite new to the embedded linux programming and did not really understand this concept very well.
Can anyone explain the essence of the "host-target" relation? Is this model only specific to the "cross-compilation"? Is it used just because "executable code will be run on another enviroment"? and what matters with the linux kernel on the target? E.g., the "building the embedded linux system" book mentioned this, but did not explain its motivation or goal of this type of development.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这种模型的“动机”是嵌入式目标很少是适合开发的平台。它可能受到资源限制,没有操作系统,没有在目标上运行的编译器,没有源文件的文件系统,没有键盘或显示器,没有网络,并且可能相对较慢或您可能需要开发的任何其他内容有效地。
如果您的嵌入式系统适合运行 Linux,则可能并非所有上述限制都适用,但几乎可以肯定,这些限制足以让您避免直接在目标上进行开发。如果不是这样,那么它可能很难成为嵌入式系统。
The 'motivation' for this model is that seldom is an embedded target a suitable platform for development. It may be resource constrained, have no operating system, have no compiler that will run on the target, have no filesystem for source files, have no keyboard or display, no networking, and may be relatively slow or anything else you might need to develop effectively.
If your embedded system is suited to running Linux, it is possible that not all of the above limitations apply, but almost certainly enough of them to make you want to avoid developng directly on the target. If this were not so, they it hardly qualifies as an embedded system perhaps.
http://www.landley.net/writing/docs/cross-compiling.html看起来
很清楚。您有什么具体问题?
http://www.landley.net/writing/docs/cross-compiling.html
Seems pretty clear. What specific questions do you have?
Linux 自诞生以来就是以非常可移植的方式编写的。它可以在具有不同 CPU 的各种机器上运行,并且以可移植的方式编写被认为是一件好事,因此,例如,包维护者可以轻松地将您的程序移植到某些嵌入式 ARM 或 Cygwin 或 Amiga,或者...
所以,是的,该模型“仅”特定于交叉编译,但实际上 Linux 上的每个编译都是交叉编译的(变体),只是默认情况下构建、主机和目标自动设置为相同的值,与您运行的机器相同。
尽管如此,即使如此,您仍然可以采用 Linux-i386 编译的编译器及其源代码,并针对 Linux-amd64“交叉编译”它。生成的二进制文件在 64 位 CPU 上运行速度会快得多。
不过,它在嵌入式编程中非常重要。主要是因为您为弱 CPU 编写程序,这些 CPU 无法运行编译器或运行速度非常慢。因此,您可以在快速 CPU(例如,某些多核 Intel)上使用交叉编译器,并针对嵌入式 CPU(例如,某些低端 ARM)进行交叉编译。
“在不同的环境中”说得非常温和。当嵌入式交叉编译时,您正在做的是使用完全不同的指令集、不同的内存访问模式、不同的资源访问方法等等。与构建主机结构完全不同的机器。您的构建主机可能是运行 Cygwin 的 Windows PC。您的目标可能是智能手机内的芯片。该二进制文件与 Cygwin .exe 文件完全不同。
直接的后果是,所有内容都必须从头开始为目标进行编译。内核、系统实用程序、系统库以及目标必须运行的所有工具。问题是,如果目标是售票亭,那么为其交叉编译 Eclipse、GCC 和 Gnome,然后在“本地”环境中进行开发,在售票亭键盘上键入代码,确实没有任何意义。相反,您只需交叉编译操作系统的基本要素和您的特定应用程序。您将开发环境保留在构建机器上,并在嵌入式设备上交叉编译您需要的所有内容。
[实际上,您可以获得目标的 Linux 发行版,然后编译您需要修改的任何内容]。
Linux since its very origin was written in very portable way. It runs on a whole range of machines with very different CPUs, and it is considered the Good Thing to write in a portable way, so that, for example, package maintainer can easily port your program to some embedded ARM or Cygwin, or Amiga, or...
So, yes, the model is "only" specific to cross-compilation, but actually about every compilation on Linux is a (variant of) cross-compilation, just that by default build, host and target are automatically set to the same value, the same as the machine you run on.
Still, even then, you can take a Linux-i386 compiled compiler, sources for it, and "cross-compile" it for Linux-amd64. And the resulting binary will run much faster on a 64bit CPU.
It IS quite essential in embedded programming though. Mostly because you write programs for weak CPUs that are not capable of running a compiler or would run it at a snail pace. So you take a cross-compiler on a fast CPU (say, some multi-core Intel) and cross-compile for the embedded CPU (say, some low-end ARM).
"In different environment" is putting things very mildly. What you're doing when cross-compiling for embedded is working with entirely different instruction set, different memory access modes, different resource access methods and so on and so on. A machine of entirely different construction than the build host. Your build host may be a Windows PC running Cygwin. Your target may be a chip inside a smartphone. The binary will look nothing like the Cygwin .exe files.
As a direct consequence, -everything- must be compiled for the target from scratch. The kernel, the system utilities, the system libraries, all the tools the target must be running. Thing is, if the target is a ticket selling booth, there is really no sense cross-compiling Eclipse, GCC and Gnome for it, then developing in "local" environment, typing your code on a ticket booth keyboard. Instead, you just cross-compile the essentials of the OS, and your specific applications. You keep the development environment on the build machine, and cross-compile everything you need on the embedded device.
[in practice, you get a Linux distro for the target, and just compile whatever you need modified].