Deploying Your First Application
This chapter describes how to write a "hello world" application on the Pico-G1 board, build it into the rootfs, flash it, and run it — completing the full flow from writing source code to running it on the board.
Step-by-Step Operations
1. Create a New Project
For a clean and maintainable project structure, place the application under SDK/source/app:
mkdir -p source/app/helloworld # Create the helloworld application
cd source/app/helloworld/ # Change directory
touch helloworld.c # Create the .c file
touch Makefile # Create the Makefile2. Write the Application
vim helloworld.chelloworld.c is as follows:
#include <stdio.h>
int main(void)
{
printf("hello world from firmware!\n");
return 0;
}3. Write the Makefile
vim MakefileThe Makefile is as follows:
# SDK root directory.
# This Makefile is located under source/app/helloworld/.
# Going up three levels returns to the SDK root.
SDK_DIR := $(shell cd $(shell pwd)/../../.. && /bin/pwd)
# Include the common SDK build configuration.
# This defines the cross-compiler, compile flags, link flags, rootfs output directory, and other variables.
include $(SDK_DIR)/build/base.mk
# Final executable file name.
TARGET := helloworld
# Source file list.
SRCS := helloworld.c
# Derive the object file name from the source file name.
# For example, helloworld.c -> helloworld.o
OBJS := $(SRCS:.c=.o)
# Declare phony targets to avoid conflicts with same-named files.
.PHONY: all clean install
# Default target.
# Running make first builds the final program.
all: $(TARGET)
# Link rule.
# Links the .o object files into the final executable.
$(TARGET): $(OBJS)
$(CC) $(SDK_LD_CFLAGS) -o $@ $^
# Compile rule.
# Compiles a .c source file into a .o object file.
%.o: %.c
$(CC) $(SDK_USR_CFLAGS) -c -o $@ $<
# Install into rootfs.
# The final on-board path will be /usr/bin/helloworld
install: all
@mkdir -p $(XMEDIA_ROOTFS_DIR)/usr/bin
@cp -f $(TARGET) $(XMEDIA_ROOTFS_DIR)/usr/bin/$(TARGET)
@chmod 755 $(XMEDIA_ROOTFS_DIR)/usr/bin/$(TARGET)
@echo "Installed $(TARGET) to $(XMEDIA_ROOTFS_DIR)/usr/bin/$(TARGET)"
# Clean build artifacts.
clean:
rm -f $(TARGET) $(OBJS)4. Build
Build the application
# Run from the SDK root directory:
make -C source/app/helloworld clean # Clean the previous build results
make -C source/app/helloworld # Re-cross-compile to generate the board-runnable helloworldBuild rootfs
# Run from the SDK root directory:
make rootfs_clean
make rootfsInstall the application into the rootfs directory
# Run from the SDK root directory:
make -C source/app/helloworld installExpected output:
ljh@lcwt-KNPP-D32-R-Series:~/GK7206$ make -C source/app/helloworld install
make: Entering directory '/home/diskh/ljh/GK7206/source/app/helloworld'
Installed helloworld to /home/diskh/ljh/GK7206/out/xm7206v12a/rootfs/usr/bin/helloworld
make: Leaving directory '/home/diskh/ljh/GK7206/source/app/helloworld'
#### make "-C source/app/helloworld install" completed successfully! ####At this point, switching to the
/out/xm7206v12a/rootfs/usr/bindirectory shows thehelloworldapplication.ls -l out/xm7206v12a/rootfs/usr/bin/helloworld
5. Package
make fs_image6. Flash
See Flashing chapter: Image Flashing to flash the SPI image.
7. Run the Application
Use SSH or serial port to enter the board's shell (command-line) environment.
cd /usr/bin/
helloworldThe following is printed:
hello world from firmware!