Javascriptimport qbsimport qbs.TextFile Product { name: "my_firmware" type: ["elf","hex","bin","sh"] property string compilerPath: "/home/user/ti/gcc/bin/msp430-elf-gcc" property string objcopyPath: "/home/user/ti/gcc/bin/msp430-elf-objcopy" property string includePath: "/home/user/ti/gcc/include" property string mspdebugPath: "/usr/local/bin/mspdebug" property string hwVersion: "0.0" property string fwVersion: "0.0" property string device: "msp430f5529" property var compilerOptions: [ "-I" + includePath, "-mmcu=" + device, "-O2", "-g", "-std=gnu99", "-Wall", "-fdata-sections","-ffunction-sections", "-D HW_VERSION=" + hwVersion, "-D FW_VERSION=" + fwVersion ]; property var linkerOptions: [ "-L" + includePath, "-T"+ device +".ld", "-Wl,-gc-sections" ]; Group { name: "sources" files: 'src/*.c' fileTags: ['c'] } Group { name: "headers" files: 'src/*.h' fileTags: ['h'] } Group { name: "others" files: [ 'README', 'program.sh', 'Makefile' ] } Rule { inputs: ["c"] Artifact { fileTags: ['obj'] filePath: '.obj/' + qbs.getHash(input.baseDir) + '/' + input.fileName + '.o' } prepare: { var args = []; args = args.concat(product.compilerOptions) args.push('-c'); args.push(input.filePath); args.push('-o'); args.push(output.filePath); var cmd = new Command(product.compilerPath, args); cmd.description = 'compiling ' + input.fileName; return cmd; } } Rule { multiplex: true inputs: ['obj'] Artifact { fileTags: ['elf'] filePath: product.name + '.elf' } prepare: { var args = []; args = args.concat(product.compilerOptions) args = args.concat(product.linkerOptions) for (i in inputs["obj"]) args.push(inputs["obj"][i].filePath); args.push('-o'); args.push(output.filePath); var cmd = new Command(product.compilerPath, args); cmd.description = 'linking ' + product.name; return cmd; } } Rule { inputs: "elf" Artifact { fileTags: ["bin"] filePath: product.name + ".bin" } prepare: { var args = ["-O", "binary", input.filePath, output.filePath]; var cmd = new Command(product.objcopyPath, args); cmd.description = "converting to bin"; return cmd; } } Rule { inputs: "elf" Artifact { fileTags: ["hex"] filePath: product.name + ".hex" } prepare: { var args = ["-O", "ihex", input.filePath, output.filePath]; var cmd = new Command(product.objcopyPath, args); cmd.description = "converting to hex"; return cmd; } } Rule { inputs: "elf" Artifact { fileTags: ["sh"] } prepare: { var cmd = new JavaScriptCommand(); cmd.sourceCode = function() { var file = new TextFile(project.sourceDirectory+"/program.sh", TextFile.WriteOnly); file.write("#!/bin/bash\n"); file.write(product.mspdebugPath +" tilib \"prog " + input.filePath + " reset\""); file.close(); } cmd.description = "create program.sh script"; return cmd; } }}
Javascriptimport qbsimport qbs.Environment Project { Product { Depends { name: "cpp" } type: "hex" name: "firmware" property string workDirectory: Environment.getEnv("FIRMWARES_WORKDIR") property string hexExtractor: cpp.toolchainInstallPath + "/" + cpp.toolchainPrefix + "objcopy"; cpp.positionIndependentCode: false cpp.debugInformation: true cpp.executableSuffix: ".elf" cpp.commonCompilerFlags: [ "-mcpu=cortex-m4", "-mfpu=fpv4-sp-d16", "-mfloat-abi=hard", //"-ffunction-sections", //"-fdata-sections", //"-mthumb", //"-fno-inline", //"-flto" //"-std=c99", ] cpp.linkerFlags: [ "-flto", "-mcpu=cortex-m4", "-mfloat-abi=hard", "-specs=nosys.specs", "-Wl,--start-group", "-Wl,--gc-sections", "-lnosys", "-lgcc", "-lc", // "-mthumb", // "-mfpu=fpv4-sp-d16", ] cpp.linkerScripts: [ "tm4c123gh6.ld" ] cpp.includePaths: [ workDirectory + "/sdk/" ] files: [ "main.cpp" ] Group { qbs.install: true fileTagsFilter: ["application", "hex"] } Rule { id: hex inputs: ["application"] Artifact { fileTags: ['hex'] filePath: product.name + '.hex' } prepare: { var args = []; args.push("-j") args.push(".text") args.push("-j") args.push(".data") args.push("-O") args.push("ihex") args.push(input.filePath); args.push(output.filePath); var extractorPath = product.hexExtractor; var cmd = new Command(extractorPath, args); return cmd; } } }}