Buildroot Quick Start
来自Jack's Lab
(版本间的差异)
(→准备代码) |
|||
(未显示1个用户的3个中间版本) | |||
第6行: | 第6行: | ||
comcat@jackslab:~/buildroot-2020.11.2$ ls | comcat@jackslab:~/buildroot-2020.11.2$ ls | ||
arch board boot CHANGES Config.in Config.in.legacy configs COPYING DEVELOPERS dl docs fs linux Makefile Makefile.legacy output package README support system toolchain utils | arch board boot CHANGES Config.in Config.in.legacy configs COPYING DEVELOPERS dl docs fs linux Makefile Makefile.legacy output package README support system toolchain utils | ||
+ | </source> | ||
+ | |||
+ | |||
+ | Download package cache dir: | ||
+ | |||
+ | <source lang=bash> | ||
+ | dl/ | ||
</source> | </source> | ||
第94行: | 第101行: | ||
$(OBJS): %.o: %.c | $(OBJS): %.o: %.c | ||
$(CC) $(CFLAGS) -c -o $@ $< | $(CC) $(CFLAGS) -c -o $@ $< | ||
+ | </source> | ||
+ | |||
+ | or: | ||
+ | |||
+ | <source lang=bash> | ||
+ | all: tx rx loopback cad | ||
+ | |||
+ | #CC=arm-linux-gnueabi-gcc | ||
+ | |||
+ | tx: common.c tx.c | ||
+ | $(CC) $(LDFLAGS) $(CFLAGS) -I./ $^ -o $@ | ||
+ | |||
+ | rx: common.c rx.c | ||
+ | $(CC) $(LDFLAGS) $(CFLAGS) -I./ $^ -o $@ | ||
+ | |||
+ | clean: | ||
+ | rm -f tx rx loopback cad | ||
</source> | </source> | ||
第101行: | 第125行: | ||
<source lang=bash> | <source lang=bash> | ||
+ | comcat@jackslab:~/buildroot-2020.11.2$ make menuconfig | ||
+ | comcat@jackslab:~/buildroot-2020.11.2$ make | ||
+ | comcat@jackslab:~/buildroot-2020.11.2$ ls output/images/rootfs.tar | ||
+ | output/images/rootfs.tar | ||
</source> | </source> | ||
<br> | <br> |
2023年7月12日 (三) 18:13的最后版本
目录 |
[编辑] 1 Overview
目录结构:
comcat@jackslab:~/buildroot-2020.11.2$ ls arch board boot CHANGES Config.in Config.in.legacy configs COPYING DEVELOPERS dl docs fs linux Makefile Makefile.legacy output package README support system toolchain utils
Download package cache dir:
dl/
[编辑] 2 添加包
comcat@jackslab:~/buildroot-2020.11.2$ mkdir -p package/helloworld/
在该目录下新建 Config.in:
config BR2_PACKAGE_HELLOWORLD bool "helloworld" help hello world package
新建 helloworld.mk:
comcat@lab:~/buildroot-2020.11.2$ cat package/helloworld/helloworld.mk HELLOWORLD_VERSION = 1.0.0 HELLOWORLD_SITE = $(TOPDIR)/../helloworld_src HELLOWORLD_SITE_METHOD = local define HELLOWORLD_BUILD_CMDS $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D) endef define HELLOWORLD_INSTALL_TARGET_CMDS $(INSTALL) -D -m 0755 $(@D)/helloworld $(TARGET_DIR)/usr/bin/helloworld #$(INSTALL) -D -m 0755 $(@D)/helloworld-init $(TARGET_DIR)/etc/init.d/S90helloworld #$(INSTALL) -D -m 0755 $(@D)/rx $(TARGET_DIR)/usr/bin/rx endef $(eval $(generic-package))
- HELLOWORLD_SITE is the location of the helloworld.c, init script, and makefile.
- $(TOPDIR) is the top directory, in our case ~/buildroot-2020.11.2
- $(@D) is the build directory.
编辑 ~/buildroot-2020.11.2/package/Config.in,增加如下内容:
source "package/helloworld/Config.in"
[编辑] 3 准备代码
$ mkdir ~/helloworld_src
放入 helloworld.c Makefile:
helloworld.c:
#include <stdio.h> #include <unistd.h> int main(int argc, int *argv[]) { while(1) { printf("Hello world\n"); sleep(1); } return 0; }
Makefile:
OBJS=helloworld.o all: helloworld helloworld: $(OBJS) $(CC) $(LDFLAGS) -o helloworld $(OBJS) $(OBJS): %.o: %.c $(CC) $(CFLAGS) -c -o $@ $<
or:
all: tx rx loopback cad #CC=arm-linux-gnueabi-gcc tx: common.c tx.c $(CC) $(LDFLAGS) $(CFLAGS) -I./ $^ -o $@ rx: common.c rx.c $(CC) $(LDFLAGS) $(CFLAGS) -I./ $^ -o $@ clean: rm -f tx rx loopback cad
[编辑] 4 编译构建
comcat@jackslab:~/buildroot-2020.11.2$ make menuconfig comcat@jackslab:~/buildroot-2020.11.2$ make comcat@jackslab:~/buildroot-2020.11.2$ ls output/images/rootfs.tar output/images/rootfs.tar