How to add my own software to a Buildroot Linux package?

后端 未结 2 352
南方客
南方客 2021-01-31 05:05

I am trying to add my own program to a small linux, created with Buildroot. What I\'ve done so far:

  • I\'ve created a new directory inside my \'buildroot/package/

2条回答
  •  伪装坚强ぢ
    2021-01-31 05:38

    Minimal tested example on top of 2016.05

    GitHub upstream: https://github.com/cirosantilli/buildroot/tree/in-tree-package-2016.05

    This example adds the package source in-tree, which is simple for educational purposes and the way to go if you want to merge back (kudos!),

    If you do not intend on merging back (booooh!), it is more likely that you will want to use Buildroot as a git submodule and either:

    • an out of tree package with BR2_EXTERNAL as shown at: https://github.com/cirosantilli/buildroot/tree/out-of-tree-2016.05
    • *_OVERRIDE_SRCDIR + other git submodules as explained at: How to modify the source of Buildroot packages for package development?

    Files modified:

    package/Config.in

    menu "Misc"
        source "package/hello/Config.in"
    endmenu
    

    package/hello/Config.in

    config BR2_PACKAGE_HELLO
        bool "hello"
        help
            Hello world package.
    
            http://example.com
    

    package/hello/hello.mk

    ################################################################################
    #
    # hello
    #
    ################################################################################
    
    HELLO_VERSION = 1.0
    HELLO_SITE = ./package/hello/src
    HELLO_SITE_METHOD = local
    
    define HELLO_BUILD_CMDS
        $(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D)
    endef
    
    define HELLO_INSTALL_TARGET_CMDS
        $(INSTALL) -D -m 0755 $(@D)/hello $(TARGET_DIR)/usr/bin
    endef
    
    $(eval $(generic-package))
    

    package/hello/src/.gitignore

    hello
    

    package/hello/src/Makefile

    CC = gcc
    
    .PHONY: clean
    
    hello: hello.c
        $(CC) -o '$@' '$<'
    
    clean:
        rm hello
    

    package/hello/src/hello.c

    #include 
    
    int main(void) {
        puts("hello");
    }
    

    Usage:

    make qemu_x86_64_defconfig
    echo 'BR2_PACKAGE_HELLO=y' >> .config
    make BR2_JLEVEL=2
    qemu-system-x86_64 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append root=/dev/vda -net nic,model=virtio -net user
    

    From inside qemu:

    hello
    

    Expected output:

    hello
    

    Tested in Ubuntu 16.04.

提交回复
热议问题