【问题标题】:Post-build step in QBSQBS 中的构建后步骤
【发布时间】:2014-06-29 17:20:39
【问题描述】:

我正在尝试将 nRF51822(Arm Cortex 微控制器)构建过程从 Make 转换为 QBS。我的编译过程正常(很多硬编码路径,但我稍后会修复)。但是,最后一步是使用objcopy 将链接器生成的.out 文件转换为.hex 文件。除了像这样创建另一个 Application 之外,我不知道如何运行我的规则(这不太好):

import qbs
import qbs.FileInfo

Project {
    CppApplication {
        type: "application" // To suppress bundle generation on Mac

        name: "nrf51_template"

        files: ["main.cpp",
            "nrf51822/Source/nrf_delay/nrf_delay.c"]

        Group {
            name: "Startup files"
            files: ["nrf51822/Source/Templates/system_" + deviceSeries + ".c",
            "nrf51822/Source/Templates/gcc/gcc_startup_" + deviceSeries + ".s"]
        }


        // The chip variant can be:
        //
        // "xxaa": The 256 kB version
        // "xxbb": The 128 kB version
        //
        // RFduino is xxaa.
        property string deviceVariant: "xxaa"

        // Must be "nrf51"
        property string deviceSeries: "nrf51"

        // The softdevice (radio firmware) to use. Can be:
        //
        // "": For no radio.
        // "s110": For BLE slave/peripheral
        // "s120": For BLE host/central
        // "s130": For BLE central and peripheral
        property string softDevice: "s110"

        // Must be cortex-m0
        property string cpu: "cortex-m0"

        cpp.includePaths: ["nrf51822/Include", "nrf51822/Include/gcc"]
        cpp.compilerName: ["arm-none-eabi-g++.exe"]
        cpp.compilerPath: ["C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-g++.exe"]
        cpp.linkerName: ["arm-none-eabi-g++.exe"]
        cpp.linkerPath: ["C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-g++.exe"]

        cpp.cxxFlags: ["-mcpu=" + cpu, "-mthumb", "-mabi=aapcs", "--std=c++11", "-mfloat-abi=soft"]
        cpp.linkerFlags: ["-L\"C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/arm-none-eabi/lib/armv6-m\"",
            "-L\"C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/lib/gcc/arm-none-eabi/4.8.3/armv6-m\"",
            "-Xlinker",
            "-Map=C:/Users/thutt/nRF51_Template/output_filename.map",
            "-mcpu=" + cpu,
            "-mthumb",
            "-mabi=aapcs",
            "-L", "C:/Users/thutt/nRF51_Template/nrf51822/Source/templates/gcc/",
            "-Tgcc_" + deviceSeries + "_" + softDevice + "_" + deviceVariant + ".ld"]

        cpp.defines: ["BOARD_PCA10001", "NRF51"]

        // Suppresses -m32 compiler option.
        cpp.architecture: "arm"

        // Suppress windows definitions and compiler options.
        cpp.minimumWindowsVersion: undefined

        cpp.executableSuffix: ".out"

        // To flash:

        // nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex

    }

    Application {
        name: "nrf51_template_hex"

        Group {
            files: "C:/Users/thutt/nRF51_Template-build/qtc_Desktop2-debug/nrf51_template.out"
            fileTags: ["out"]
        }

        Depends {
            name: "nrf51_template"
        }


        Rule {
            id: hex
            inputs: ["out"]

            Artifact {
                fileTags: ["application"]
                fileName: ".obj/" + product.name + "/" + input.baseDir + "/" + input.fileName + ".hex"
            }

            prepare: {
    //          var compilerPath = ModUtils.moduleProperty(product, "compilerPath");

                var objCopyPath = "C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-objcopy.exe";
                var args = ["-O", "ihex", input.filePath, output.filePath];
                var cmd = new Command(objCopyPath, args);

                cmd.description = "converting to hex: " + FileInfo.fileName(input.filePath);
                cmd.highlight = "linker";
                return cmd;
            }
        }
    }
}

是否可以在CppApplication 中有一个链接后步骤,而不是像这样的两个Applications?我最好用我自己的Rules 定义一个全新的Application 来进行编译和链接吗?

还有一个额外的问题,是否可以在 QBS 文件中指定“运行”可执行文件,以便当我在 QtCreator 中单击运行时,它实际上会运行 nrfjprog.exe 并将代码闪存到芯片上? (您可以在 IDE 中执行此操作,但我希望能够在 QBS 文件中执行此操作。)

【问题讨论】:

  • 好主意,我也想为一些 MCU 项目尝试 QBS!如果你想聊聊这个,请在​​ Twitter 上联系我 ;)

标签: build qbs nrf51


【解决方案1】:

想通了,最终目标由Application 中的type: 行确定,所以只需将其更改为:

import qbs
import qbs.FileInfo

Project {
    CppApplication {

        // The filetag to generate.
        type: "hex"

        name: "nrf51_template"

        files: ["main.cpp",
            "SaneSPI.cpp",
            "SaneSPI.h",
            "Timer.cpp",
            "Timer.h",
            "Delay.cpp",
            "Delay.h",
            "GPIO.cpp",
            "GPIO.h"]

        Group {
            name: "Startup files"
            files: ["nrf51822/Source/Templates/system_" + deviceSeries + ".c",
            "nrf51822/Source/Templates/gcc/gcc_startup_" + deviceSeries + ".s"]
        }


        // The chip variant can be:
        //
        // "xxaa": The 256 kB version
        // "xxbb": The 128 kB version
        //
        // RFduino is xxaa.
        property string deviceVariant: "xxaa"

        // Must be "nrf51"
        property string deviceSeries: "nrf51"

        // The softdevice (radio firmware) to use. Can be:
        //
        // "": For no radio.
        // "s110": For BLE slave/peripheral
        // "s120": For BLE host/central
        // "s130": For BLE central and peripheral
        property string softDevice: "s110"

        // Must be cortex-m0
        property string cpu: "cortex-m0"

        cpp.includePaths: ["nrf51822/Include",
            "nrf51822/Include/gcc",
            "nrf51822/Include/" + softDevice]
        cpp.compilerName: ["arm-none-eabi-g++.exe"]
        cpp.compilerPath: ["C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-g++.exe"]
        cpp.linkerName: ["arm-none-eabi-g++.exe"]
        cpp.linkerPath: ["C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-g++.exe"]

        cpp.cxxFlags: ["-mcpu=" + cpu, "-mthumb", "-mabi=aapcs", "--std=c++11", "-mfloat-abi=soft"]
        cpp.linkerFlags: ["-L\"C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/arm-none-eabi/lib/armv6-m\"",
            "-L\"C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/lib/gcc/arm-none-eabi/4.8.3/armv6-m\"",
            "-Xlinker",
            "-Map=C:/Users/thutt/nRF51_Template/output_filename.map",
            "-mcpu=" + cpu,
            "-mthumb",
            "-mabi=aapcs",
            "-L", "C:/Users/thutt/nRF51_Template/nrf51822/Source/templates/gcc/",
            "-Tgcc_" + deviceSeries + "_" + softDevice + "_" + deviceVariant + ".ld"]

        cpp.defines: ["BOARD_PCA10001", "NRF51"]

        // Suppresses -m32 compiler option.
        cpp.architecture: "arm"

        // Suppress windows definitions and compiler options.
        cpp.minimumWindowsVersion: undefined

        cpp.executableSuffix: ".out"

        Rule {
            id: hex
            inputs: ["application"]

            Artifact {
                fileTags: ["hex"]
                fileName: ".obj/" + product.name + "/" + input.baseDir + "/" + input.fileName + ".hex"
            }

            prepare: {
    //          var compilerPath = ModUtils.moduleProperty(product, "compilerPath");

                var objCopyPath = "C:/Program Files/GNU Tools ARM Embedded/4.8 2014q1/bin/arm-none-eabi-objcopy.exe";
                var args = ["-O", "ihex", input.filePath, output.filePath];
                var cmd = new Command(objCopyPath, args);

                cmd.description = "converting to hex: " + FileInfo.fileName(input.filePath);
                cmd.highlight = "linker";
                return cmd;
            }
        }

        // To flash:

        // nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex

    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    相关资源
    最近更新 更多