Skip to content

Commit

Permalink
build: use image_builder in armv7a7 based projects
Browse files Browse the repository at this point in the history
JIRA: CI-494
  • Loading branch information
nalajcie committed Sep 24, 2024
1 parent b835f1c commit 16404c3
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 104 deletions.
49 changes: 2 additions & 47 deletions _projects/armv7a7-imx6ull-evk/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export LWIP_IPSEC_BUILD=no
export LWIP_WIFI_BUILD=no

#
# Setup model of KSZ8081 On-Board Chip
# Setup model of KSZ8081 On-Board Chip
#
export EPHY_KSZ8081=RNA

Expand All @@ -37,56 +37,11 @@ export PLO_DEVICES="flash-imx6ull uart-imx6ull usbc-cdc"
#
# Project specific build
#
BOOT_DEVICE="nor0" # Default boot device
OFFS_USER_SCRIPT=$((0x20000)) # Disk image user script offset (in bytes)

KERNEL_OFFS=$((0x21000)) # Disk image kernel offset (in bytes)
export BOOT_DEVICE="nor0" # Default boot device
ERASE_SIZE=$((16 * 4096)) # Rootfs disk erase block size (in bytes)
SECTOR_SIZE=$((0x100)) # Rootfs write sector size (in bytes)
CLEANMARKER_SIZE=$((0x10)) # JFFS2 cleanmarker size (in bytes)
IMAGE_PAD_FF=y

#
# Fs data
#
FS_OFFS=$((0x100000))
FS_SZ=$((0x2000000 - FS_OFFS))

# Pre-init script is launched before user script
PREINIT_SCRIPT=(
"map ddr 0x80000000 0x87ffffff rwx"
"phfs usb0 1.2 phoenixd"
"phfs ${BOOT_DEVICE} 2.0 raw"
"console 0.0"
)


#TODO: if flash driver for imx6ull-evk implementation is introduced, psh should be replaced by imx6ull-flash and psd
# This is temporary solution for running a system image in RAM
UPLOAD_SCRIPT=(
"wait 2000"
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs ddr ddr"
"app ${BOOT_DEVICE} -x imx6ull-uart ddr ddr"
"app ${BOOT_DEVICE} -x psh ddr ddr"
"go!"
)


PRIMARY_SCRIPT=(
"wait 2000"
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs;-N;devfs;-D ddr ddr"
"app ${BOOT_DEVICE} -x imx6ull-uart ddr ddr"
"app ${BOOT_DEVICE} -x imx6ull-flashnor;-q;1;-r;0;${FS_OFFS};${FS_SZ};jffs2 ddr ddr"
"app ${BOOT_DEVICE} -x psh;-i;/etc/rc.psh ddr ddr"
"go!"
)


b_image_project () {
OFFSET="$FS_OFFS"
b_add2img "$(b_rootfs_path_get_target)" "$PHOENIX_DISK"

b_log "The images have been built for the ${TARGET} platform"
}
21 changes: 21 additions & 0 deletions _projects/armv7a7-imx6ull-evk/user.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# kernel + initrd
magic: '{{ env.MAGIC_USER_SCRIPT }}'
size: 0x1000
is_relative: True

contents:
- wait 2000
- kernel {{ env.BOOT_DEVICE }}
- app {{ env.BOOT_DEVICE }} -x dummyfs;-N;devfs;-D ddr ddr
- app {{ env.BOOT_DEVICE }} -x imx6ull-uart ddr ddr
- name: app
device: '{{ env.BOOT_DEVICE }}'
flags: EXEC
filename: imx6ull-flashnor
args:
- '-q;1'
- '-r;0;{{ nvm.flash0.rootfs.offs }};{{ nvm.flash0.rootfs.size }};jffs2'
text_map: ddr
data_maps: ddr
- app {{ env.BOOT_DEVICE }} -x psh;-i;/etc/rc.psh ddr ddr
- go!
83 changes: 26 additions & 57 deletions _targets/armv7a7/imx6ull/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,18 @@ export PORTS_CURL=y
#
# Platform dependent parameters
#
SIZE_PAGE=$((0x1000))
PAGE_MASK=$((~(SIZE_PAGE - 1)))
KERNEL_OFFS=$((0x0)) # Disk image kernel offset (in bytes)
export SIZE_PAGE=$((0x1000))
ADDR_DDR=$((0x80000000))


#
# Project specific build
#
BOOT_DEVICE="flash0" # Default boot device
NAME_USER_SCRIPT="user.plo" # User script name
MAGIC_USER_SCRIPT=$((0xdabaabad)) # User script magic value
OFFS_USER_SCRIPT=$((0x0)) # Disk image user script offset (in bytes)
OFFS_ROOTFS=$((0x1000)) # Disk image rootfs offset (in 512 byte sectors)
ERASE_SIZE=$((64 * 4096)) # Rootfs disk erase block size (in bytes)
CLEANMARKER_SIZE=$((0)) # JFFS2 cleanmarker size (in bytes)



# Pre-init script is launched before user script
PREINIT_SCRIPT=(
"map ddr 0x80000000 0x87ffffff rwx"
"phfs usb0 1.2 phoenixd"
"console 0.0"
)

export BOOT_DEVICE="flash0"
export MAGIC_USER_SCRIPT="dabaabad"

#TODO: if flash driver for imx6ull-evk implementation is introduced, psh should be replaced by imx6ul-flash and psd
# This is temporary solution for running a system image in RAM
UPLOAD_SCRIPT=(
"wait 2000"
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs ddr ddr"
"app ${BOOT_DEVICE} -x imx6ull-uart ddr ddr"
"app ${BOOT_DEVICE} -x psh ddr ddr"
"go!"
)


PRIMARY_SCRIPT=(
"wait 2000"
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs ddr ddr"
"app ${BOOT_DEVICE} -x imx6ull-uart ddr ddr"
"app ${BOOT_DEVICE} -x psh ddr ddr"
"go!"
)
# TODO: move to nvm.yaml
ERASE_SIZE=$((64 * 4096)) # Rootfs disk erase block size (in bytes)


b_build_project() {
Expand All @@ -89,10 +54,12 @@ b_build_project() {

b_build_target() {
b_log "Building $TARGET project"
image_builder.py script --nvm "$NVM_CONFIG" --script "$PLO_SCRIPT_PREINIT" --out script.plo

if [ "$KERNEL_PLO_BOOT" = "y" ]; then
b_log "Building PLO"

b_mkscript_preinit
RAM_SCRIPT=1 image_builder.py script --nvm "$NVM_CONFIG" --script "$PLO_SCRIPT_PREINIT" --out script-ram.plo
make -C plo all

cp -a "phoenix-rtos-hostutils/psu/plo-ram-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.sdp" "$PREFIX_BOOT/plo-ram.sdp"
Expand All @@ -114,6 +81,7 @@ b_syspage_gen() {
addr=$((syspage-vectors))
sz=$((plugin-syspage))

# TODO: move the functionality to the image_builder?
"$PREFIX_BOOT/syspagen" \
-a 32\
-s "$ADDR_DDR:$addr:$sz" \
Expand All @@ -123,29 +91,24 @@ b_syspage_gen() {
}


# Defined as a function instead of a constant as $PREFIX_BOOT is not set at top level.
b_rootfs_path_get_target() {
echo "$PREFIX_BOOT/rootfs.jffs2"
}


b_image_target() {
b_log "Creating image from $PREFIX_ROOTFS"

b_mkscript_user "${UPLOAD_SCRIPT[@]}"

if [ "$KERNEL_PLO_BOOT" = "y" ]; then
b_log "Image will boot from PLO."

b_log "FLASH image"
b_mkscript_user "${PRIMARY_SCRIPT[@]}"
b_prod_image
image_builder.py -v partition --nvm "$NVM_CONFIG" --name kernel --script "$PLO_SCRIPT_USER"
else
#FIXME: this code path hasn't yet been moved to image_builder

# Parsed by syspagen for map and console commands.
b_mkscript_preinit

# Build production image
b_log "RAM Image"

#TODO: create `kernel` partition image without the script using image_builder
b_kernel_image "$PREFIX_BOOT/phoenix.img"
b_syspage_gen "$PREFIX_BOOT/phoenix.img" "$PLO_SCRIPT_DIR/$NAME_USER_SCRIPT"

Expand All @@ -154,19 +117,18 @@ b_image_target() {
# As plo is not used user script is used only to:
# - upload executable binary file instead of elf to the board(kernelimg),
# - upload required apps(app).
#TODO: create `kernel` partition image without the script using image_builder
b_mkscript_user "${PRIMARY_SCRIPT[@]}"
b_kernel_image "$PREFIX_BOOT/phoenix-kernel.img"
b_syspage_gen "$PREFIX_BOOT/phoenix-kernel.img" "$PLO_SCRIPT_DIR/$NAME_USER_SCRIPT"
cp -a "$PREFIX_BOOT/phoenix-kernel.img" "$PREFIX_BOOT/part_kernel.img"
fi

b_log "Creating rootfs"
# FIXME: does work only on macOS, for now hackish solution based on extending PATH
mtd-utils/build.sh
PATH="$(pwd)/_build/host-generic-pc/prog/:$PATH"

ROOTFS=$(b_rootfs_path_get_target)
ROOTFS="$PREFIX_BOOT/rootfs.jffs2"

if [ $CLEANMARKER_SIZE -eq 0 ]; then
if [ "$CLEANMARKER_SIZE" -eq 0 ]; then
CLEANMARKER_ARG=("-n")
else
CLEANMARKER_ARG=("-c" "$CLEANMARKER_SIZE")
Expand All @@ -179,8 +141,15 @@ b_image_target() {
mv "$ROOTFS.tmp" "$ROOTFS"
fi

FS_SZ=$(image_builder.py query --nvm "$NVM_CONFIG" '{{ nvm.flash0.rootfs.size }}')
sz=$(du -k "$ROOTFS" | awk '{ print $1 }')
echo "rootfs size: ${sz}KB"
echo "rootfs size: ${sz} kB / $((FS_SZ / 1024)) kB"
[ "$sz" -gt "$FS_SZ" ] && b_die "rootfs size exceeds the target partition!"

image_builder.py -v disk --nvm "$NVM_CONFIG" --part "rootfs=$ROOTFS" --part "plo=${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img"

# TODO: remove? CI currently has the disk filename hardcoded - maybe it should use nvm.yaml?
cp -a "${PREFIX_BOOT}/flash0.disk" "${PREFIX_BOOT}/phoenix.disk"
}


Expand Down
12 changes: 12 additions & 0 deletions _targets/armv7a7/imx6ull/nvm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
flash0:
size: 0x2000000 # 32 MB
block_size: 0x1000
padding_byte: 0xff
partitions:
- name: plo
offs: 0x0
- name: kernel
offs: 0x20000
- name: rootfs
offs: 0x100000
type: jffs2
18 changes: 18 additions & 0 deletions _targets/armv7a7/imx6ull/preinit.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
size: 0x1000
is_relative: False

contents:
#TODO: add SRAM
- map ddr 0x80000000 0x87ffffff rwx
- phfs usb0 1.2 phoenixd
- phfs {{ env.BOOT_DEVICE }} 2.0 raw
- console 0.0

- if: '{{ not(env.RAM_SCRIPT) | default(false) }}'
action: call
set_base: True
device: '{{ env.BOOT_DEVICE }}'
filename: user.plo
offset: '{{ nvm.flash0.kernel.offs }}'
target_magic: '{{ env.MAGIC_USER_SCRIPT }}'

12 changes: 12 additions & 0 deletions _targets/armv7a7/imx6ull/user.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# kernel + initrd
magic: '{{ env.MAGIC_USER_SCRIPT }}'
size: 0x1000
is_relative: True

contents:
- wait 2000
- kernel {{ env.BOOT_DEVICE }}
- app {{ env.BOOT_DEVICE }} -x dummyfs ddr ddr
- app {{ env.BOOT_DEVICE }} -x imx6ull-uart ddr ddr
- app {{ env.BOOT_DEVICE }} -x psh ddr ddr
- go!

0 comments on commit 16404c3

Please sign in to comment.