免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 10856 | 回复: 12
打印 上一主题 下一主题

i386平台下怎么编译安装amd64的freebsd [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-01 12:16 |只看该作者 |倒序浏览
我想在i386(freebsd7.0)下编译安装成amd64平台。听说可以通过设置TARGET_ARCH来做到,但具体怎么做?请各位大大帮忙解答

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
2 [报告]
发表于 2008-08-01 12:36 |只看该作者

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
3 [报告]
发表于 2008-08-01 12:38 |只看该作者
Cross Building FreeBSD


I've been getting more and more questions about FreeBSD embedded systems: What is supported? How can I build for them? What can be done to improve the cross development environment? How can I help? and so on. These are all very good questions, so I thought I'd start a series of articles on the FreeBSD build system and embedding FreeBSD into products.

For this article, I'll be providing background on the FreeBSD build system as it relates to embedded systems. For an emebedded system, one usually has little more than a microcontroller with an MMU to power the entire system. While these systems work well in their target niche, they don't work so well as a general purpose platform. They lack the memory and I/O bandwidth necessary to compile applications that run on them. Server machines (or even workstations) do a much better job at these tasks, but are for a different computer architecture. One is left with the choice of compiling natively on a slow machine, or cross building on a fast machine. I'll discuss some basic aspects of cross compilation in this article.

I'll assume that you are familiar with FreeBSD's build system. If not, there are many resources available on the web. One of the better ones is the FreeBSD handbook. Future articles will build on this base, hopefully with sufficient links.

Each FreeBSD platform has a MACHINE and a MACHINE_ARCH that uniquely define it. The MACHINE_ARCH is the CPU family that executes the object code. MACHINE_ARCH is something like "i386" or "sparc64." Some CPU families come in different flavors that are mutually incompatible (such as MIPS processors using different byte ordering). These families would get a different MACHINE_ARCH for each flavor (so you'd have mipseb and mipsel, for example, to distinguish the two different flavors of MIPS CPUs). If you are familar with the gnu compilers and such, this field roughly corresponds to "CPU" field of their "CPU-MANUFACTURER-OS" identifier. I say "corresponds" because FreeBSD uses "amd64" as the MACHINE_ARCH for AMD's extensions to the x86 architecture (the official name of the architecture), while gcc uses the older x86_64 designation.

MACHINE defines the way the machine is put together. Often times machines are build with the same CPU, but with differing glue chips and support software. In cases like this, if the machines are very similar, FreeBSD will support that with one MACHINE type. In other cases, the differences are large enough to warrant an entirely separate MACHINE for that machine. What differentiates one MACHINE type from another with the same MACHINE_ARCH are things like BIOS interface, boot procedure, disk partitioning, and expansion bus technologies. For example, the FreeBSD/i386 and FreeBSD/pc98 platforms both execute on i386 compatible CPUs, but they have completely different bus topologies, boot procedures, BIOS interfaces, and disk layout.

When one builds FreeBSD on one platform to execute on another platform, that is called cross compiling. Cross compilation support is integrated into the normal FreeBSD build system. It is activated by defining TARGET and TARGET_ARCH of the machine you are targeting and using the normal make targets. For example:

   
make TARGET=arm TARGET_ARCH=arm buildworld


will build the entire userland portion of the system for an ARM machine. Similarly, the following:

   
make TARGET=arm TARGET_ARCH=arm installworld DESTDIR=/foo


will install these components into the directory tree /foo. One can even build and install a kernel for the target platform:

   
make TARGET=arm TARGET_ARCH=arm KERNCONF=BONGO kernel DESTDIR=/foo




After cross compilation support was added to the tree, the FreeBSD project added two additional make targets which allow use of the build tools outside of the build tree. The first is "buildenv." It forks a shell with the same build environment used to build FreeBSD. This target is for interactive development. Much of the Atmel AT91RM9200 port was done using this target, for example. However, there's no ability to specify a command to run in this sub-shell, nor does it lend itself well to automated building systems. The make target "buildenvvar" was created to try to fill the gap in the latter problem. This target prints the build environment variables used by the build system. We used it at my day joy to help automate building our products on an x86 processor for an embedded ARM design we're producing. This works well for many applications, but not for all. We have found that we can make it work for simple applications, but more complicated one, with more elaberate build systems, require something more sophisticated. In a future article, I'll describe how we solved that problem.

Many times, cross building can be useful for "compile testing" changes to the tree. There's a make target called "universe" that builds the entire tree for each of the Tier 1 and 2 architectures, along with all the kernels that it can find. In many cases, these "compile tests" of the system find problems that would otherwise be found by others, thus saving much embarassment. The drawback, however, to a "universe" build is that it takes several hours on a very fast machine.

I hope that you've found the above information useful, and that it answers your basic questions in this area. Feel free to leave feedback with additional questions or requests for clarification and I'll see what I can do about addressing them in the feedback section, or in future articles.

论坛徽章:
0
4 [报告]
发表于 2008-08-01 12:38 |只看该作者
老大就是老大,太感谢了

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
5 [报告]
发表于 2008-08-01 12:39 |只看该作者
呵呵,转的。。。。加个保留,放置顶索引里去。。

论坛徽章:
0
6 [报告]
发表于 2008-08-01 12:45 |只看该作者
有才
ps:您的请求来路不正确或验证字串不符,无法提交。如果您安装了某种默认屏蔽来路信息的个人防火墙软件(如 Norton Internet Security),请设置其不要禁止来路信息后再试。 什么意思,我没装任何防火墙啊

论坛徽章:
0
7 [报告]
发表于 2008-08-01 13:35 |只看该作者
我大致看了下老大引用的文章,发现他说了编译,却没有说安装,回复里有人很“无辜”地中招了。跨平台安装有一个问题,i386内核下不能安装amd64平台的world,amd64平台内核不能使用i386的world启动。我又搜了下,发现有一个邮件列表(http://unix.derkeiler.com/Mailin ... 07-11/msg00520.html)解答了一点,看了下,我自己总结的安装步骤如下(没测试过,不敢保证是对的,但原理应该就是这样):
1. 跨平台编译,先把要要安装的东西准备好
2. 卸载swap分区,这里拿swap分区作为交换分区,所以swap要大,要能存得下一个完整的基本系统
3. newfs swap分区,将swap分区建立成一个新的文件系统
4. 挂载新的分区到/mnt目录下
5. 使用DESTDIR编译选项将准备好的new-kernel和new-world安装到/mnt分区也就是swap建立的临时分区下
6. 重启,在启动菜单里选择第二个,然后输入swap分区的文件系统地址,如果是ad0sb那就是ad(0,b),从刚才安装到临时分区的新系统启动
7. 挂载原来的系统目录到/mnt下,如/mnt,/mnt/usr,/mnt/tmp,/mnt/var等等,当然不用加swap(因为已经没了)
8. mount -t nullfs /mnt/usr/src /usr/src <and> /mnt/usr/obj /usr/obj
9. cd /usr/src
10. make installkernel/installworld DESTDIR=/mnt ,将新的系统从临时分区安装到原来的文件系统下

大致思想是这样,我觉得从原理上讲是可行的

论坛徽章:
2
亥猪
日期:2014-03-19 16:36:35午马
日期:2014-11-23 23:48:46
8 [报告]
发表于 2008-08-01 13:53 |只看该作者
可以尝试下你总结的方法。

成功的话,保留升精华

论坛徽章:
0
9 [报告]
发表于 2008-08-02 19:08 |只看该作者
现在有一个问题,怎么修改启动分区,我在handbook上面查出来可以用bsdlabel -B来做到,不知道是不是可以?

论坛徽章:
0
10 [报告]
发表于 2008-12-04 21:34 |只看该作者
想不通,在i386平台上编译amd64还说得过去,安装amd64干嘛?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP