Skip to content

Commit

Permalink
build: use image_builder in armv7a9-zynq7000 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 4c3f19e commit fe0b4c4
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 114 deletions.
17 changes: 17 additions & 0 deletions _projects/armv7a9-zynq7000-qemu/nvm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
flash0:
size: 0x1000000 # 16 MB
block_size: 512
padding_byte: 0xff
partitions:
- name: plo
offs: 0x0
- name: kernel
offs: 0x10000
# bitstream is not used in qemu, make larger rootfs instead
- name: rootfs
offs: 0x400000
size: 0xc00000
type: jffs2
# provide empty virtual bitstr region for _target generic approach to work
- name: bitstr
virtual: True
20 changes: 20 additions & 0 deletions _projects/armv7a9-zynq7000-qemu/user.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# kernel + initrd
magic: '{{ env.MAGIC_USER_SCRIPT }}'
size: 0x1000
is_relative: True

contents:
- wait 500
- kernel {{ env.BOOT_DEVICE }}
- app {{ env.BOOT_DEVICE }} -x dummyfs;-N;devfs;-D ddr ddr
- app {{ env.BOOT_DEVICE }} -x zynq7000-uart ddr ddr
- app {{ env.BOOT_DEVICE }} -x psh;-i;/etc/rc.psh ddr ddr
- if: True
name: app
device: '{{ env.BOOT_DEVICE }}'
flags: EXEC
filename: zynq7000-flash
args: '-r;/dev/mtd0:{{ nvm.flash0.rootfs.offs }}:{{ nvm.flash0.rootfs.size }}:jffs2'
text_map: ddr
data_maps: ddr
- go!
28 changes: 1 addition & 27 deletions _projects/armv7a9-zynq7000-zedboard/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,12 @@
[ "${BASH_SOURCE[0]}" -ef "$0" ] && echo "You should source this script, not execute it!" && exit 1


# Example of the NOR flash memory layout for Spansion s25fl256s1 (32 MB) placed on Zedboard
# region 1 <0:0x1ffff> # region 2 <0x20000:1xFFDFFFF> #
# /dev/mtd0 # /dev/mtd1 #
export FS_SZ=$((0x1000000))
# TODO: why? because we're always erasing partition in PLO beforehand (it writes eraseblocks automatically)
export FS_WRITE_CLEANMARKERS=n

# No networking
export BUSYBOX_CONFIG="${PROJECT_PATH}/busybox_config"

# Pre-init script is launched before user script
PREINIT_SCRIPT=(
"map kddr 0x100000 0x12ffff rwx"
"map ddr 0x130000 0x900000 rwx"
"map ocram1 0x00000000 0x00030000 rwx"
"phfs usb0 1.2 phoenixd"
"phfs uart0 0.0 phoenixd"
"phfs uart1 0.1 raw"
"phfs flash0 2.0 raw"
"console 0.1")


# Production user script contains applications to run Phoenix-RTOS
USER_SCRIPT=(
"wait 500"
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs;-N;devfs;-D ddr ddr"
"app ${BOOT_DEVICE} -x zynq7000-uart ddr ddr"
"app ${BOOT_DEVICE} -x psh;-i;/etc/rc.psh ddr ddr"
"app ${BOOT_DEVICE} -x zynq7000-flash;-r;/dev/mtd1:$((FS_OFFS-0x20000)):${FS_SZ}:jffs2;-p;/dev/mtd1:0x1800000:0x4e0000 ddr ddr"
"go!")


b_image_project () {
b_log "The images have been built for the ${TARGET} platform"
}
32 changes: 32 additions & 0 deletions _projects/armv7a9-zynq7000-zedboard/nvm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
flash0:
size: 0x2000000 # 32 MB
block_size: 0x1000
padding_byte: 0xff
partitions:
- name: plo
offs: 0x0
- name: kernel
offs: 0x10000
- name: bitstr
offs: 0x400000
- name: rootfs
offs: 0x900000
size: 0x1000000
type: jffs2
- name: data
size: 0x4e0000
empty: True # TODO: remove when it will be actually used


# Spansion s25fl256s1 has 2 regions with 4kB / 64kB erase blocks
# currently zynq7000-flash creates separate device for every region
- name: mtd0
virtual: True
offs: 0x0
size: 0x20000
# eraseblock_size: 4 kB
- name: mtd1
virtual: True
offs: 0x20000
size: 0x1FE0000
# eraseblock_size: 64 kB
22 changes: 22 additions & 0 deletions _projects/armv7a9-zynq7000-zedboard/user.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# kernel + initrd
magic: '{{ env.MAGIC_USER_SCRIPT }}'
size: 0x1000
is_relative: True

contents:
- wait 500
- kernel {{ env.BOOT_DEVICE }}
- app {{ env.BOOT_DEVICE }} -x dummyfs;-N;devfs;-D ddr ddr
- app {{ env.BOOT_DEVICE }} -x zynq7000-uart ddr ddr
- app {{ env.BOOT_DEVICE }} -x psh;-i;/etc/rc.psh ddr ddr
# WARN: for mounting partitions in mtd1 region we need to subtract mtd1 base offset
- name: app
device: '{{ env.BOOT_DEVICE }}'
flags: EXEC
filename: zynq7000-flash
args:
- '-r;/dev/mtd1:{{ nvm.flash0.rootfs.offs - nvm.flash0.mtd1.offs }}:{{ nvm.flash0.rootfs.size }}:jffs2'
- '-p;/dev/mtd1:{{ nvm.flash0.data.offs - nvm.flash0.mtd1.offs }}:{{ nvm.flash0.data.size }}'
text_map: ddr
data_maps: ddr
- go!
24 changes: 0 additions & 24 deletions _projects/armv7a9-zynq7000-zturn/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,11 @@

[ "${BASH_SOURCE[0]}" -ef "$0" ] && echo "You should source this script, not execute it!" && exit 1

export FS_SZ=$((0x800000))
export FS_WRITE_CLEANMARKERS=n

# No networking
export BUSYBOX_CONFIG="${PROJECT_PATH}/busybox_config"

# Pre-init script is launched before user script
PREINIT_SCRIPT=(
"map kddr 0x100000 0x12ffff rwx"
"map ddr 0x130000 0x900000 rwx"
"map ocram1 0x00000000 0x00030000 rwx"
"phfs usb0 1.2 phoenixd"
"phfs uart0 0.0 phoenixd"
"phfs uart1 0.1 raw"
"phfs flash0 2.0 raw"
"console 0.1")


# Production user script contains applications to run Phoenix-RTOS
USER_SCRIPT=(
"wait 500"
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs;-N;devfs;-D ddr ddr"
"app ${BOOT_DEVICE} -x zynq7000-uart ddr ddr"
"app ${BOOT_DEVICE} -x psh;-i;/etc/rc.psh ddr ddr"
"app ${BOOT_DEVICE} -x zynq7000-flash;-r;/dev/mtd0:${FS_OFFS}:${FS_SZ}:jffs2; ddr ddr"
"go!")


b_image_project () {
b_log "The images have been built for the ${TARGET} platform"
}
15 changes: 15 additions & 0 deletions _projects/armv7a9-zynq7000-zturn/nvm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
flash0:
size: 0x2000000 # 32 MB
block_size: 512
padding_byte: 0xff
partitions:
- name: plo
offs: 0x0
- name: kernel
offs: 0x10000
- name: bitstr
offs: 0x400000
- name: rootfs
offs: 0x800000
size: 0x800000
type: jffs2
19 changes: 19 additions & 0 deletions _projects/armv7a9-zynq7000-zturn/user.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# kernel + initrd
magic: '{{ env.MAGIC_USER_SCRIPT }}'
size: 0x1000
is_relative: True

contents:
- wait 500
- kernel {{ env.BOOT_DEVICE }}
- app {{ env.BOOT_DEVICE }} -x dummyfs;-N;devfs;-D ddr ddr
- app {{ env.BOOT_DEVICE }} -x zynq7000-uart ddr ddr
- app {{ env.BOOT_DEVICE }} -x psh;-i;/etc/rc.psh ddr ddr
- name: app
device: '{{ env.BOOT_DEVICE }}'
flags: EXEC
filename: zynq7000-flash
args: '-r;/dev/mtd0:{{ nvm.flash0.rootfs.offs }}:{{ nvm.flash0.rootfs.size }}:jffs2'
text_map: ddr
data_maps: ddr
- go!
86 changes: 24 additions & 62 deletions _targets/armv7a9/zynq7000/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,16 @@ export PORTS_BUSYBOX=y
#
# Default platform dependent parameters
#
SIZE_PAGE=$((0x1000))
PAGE_MASK=$((~(SIZE_PAGE - 1)))
KERNEL_OFFS=$((0x11000))
FS_OFFS=$((0x800000))
BS_OFFS=$((0x400000))
if [ -f "${PROJECT_PATH}/bitstream.bin" ]; then
BS_SZ=$(wc -c "${PROJECT_PATH}/bitstream.bin" | cut -f1 -d" ")
else
BS_SZ=0
fi
export SIZE_PAGE=$((0x1000))

#
# Project specific build
#

BOOT_DEVICE="flash0"
NAME_USER_SCRIPT="user.plo"
OFFS_USER_SCRIPT=$((0x10a00))
MAGIC_USER_SCRIPT=$((0xdabaabad))
export BOOT_DEVICE="flash0"
export MAGIC_USER_SCRIPT="dabaabad"


# Pre-init script is launched before user script
PREINIT_SCRIPT=(
"map kddr 0x100000 0x12ffff rwx"
"map ddr 0x130000 0x900000 rwx"
"map ocram1 0x00000000 0x00030000 rwx"
"phfs usb0 1.2 phoenixd"
"phfs uart0 0.0 phoenixd"
"phfs uart1 0.1 raw"
"phfs flash0 2.0 raw"
"console 0.1")


# Production user script contains applications to run basic version of Phoenix-RTOS
USER_SCRIPT=(
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs ddr ddr"
"app ${BOOT_DEVICE} -x zynq7000-uart ddr ddr"
"app ${BOOT_DEVICE} -x psh ddr ddr"
"app ${BOOT_DEVICE} -x zynq7000-flash ddr ddr"
"wait 500"
"go!")


b_build_project() {
b_log "Building user applications"
Expand All @@ -72,18 +39,15 @@ b_build_target() {
b_log "Building $TARGET project"

b_log "Building phoenix-rtos-loader"
b_mkscript_preinit
image_builder.py script --nvm "$NVM_CONFIG" --script "$PLO_SCRIPT_PREINIT" --out script.plo
RAM_SCRIPT=1 image_builder.py script --nvm "$NVM_CONFIG" --script "$PLO_SCRIPT_PREINIT" --out script-ram.plo
make -C plo base ram

# plo image is reused only in loading system via qemu
if [ "${TARGET_PROJECT}" = "qemu" ]; then
cp "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" "$PREFIX_BOOT/plo.img"
fi

phoenix-rtos-build/scripts/mkimg-boot-zynq7000.sh \
"${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" \
"${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" \
0

# Copy plo.elf with symbols to provide loading plo using gdb
cp "${PREFIX_PROG}plo-ram-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.elf" "$PREFIX_BOOT/plo-gdb.elf"
Expand All @@ -96,6 +60,7 @@ b_build_target() {
}


#TODO: move the functionality to the image_builder?
b_write_cleanmarkers() {
local rootfs_file="$1"
local erase_sz="$2"
Expand Down Expand Up @@ -126,45 +91,42 @@ b_write_cleanmarkers() {


b_image_target() {
b_mkscript_user "${USER_SCRIPT[@]}"
b_prod_image
# FIXME: DEV_USER_SCRIPT is unset here - can't build dev image
#b_dev_image
# prepare necessary BootROM flash header
mkimg-boot-zynq7000.sh \
"${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" \
"${PREFIX_BOOT}/part_plo.img" \
0

# Function needs external variables to be defined in a project file:
: "${FS_SZ:?variable unset}" # root filesystem size
: "${FS_WRITE_CLEANMARKERS:?variable unset}" # define writing cleanmarkers to final image
# kernel / syspage
image_builder.py -v partition --nvm "$NVM_CONFIG" --name kernel --script "$PLO_SCRIPT_USER"

b_log "Creating rootfs"
# !!! NOTE: For non-standard NOR flash memories, erase_sz should be changed.
local erase_sz=$((0x10000))

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

# Create jffs2 image with padding at the end of the final erase block
mkfs.jffs2 -U -c 12 -m none -e $erase_sz -s $SIZE_PAGE -n -r "$PREFIX_ROOTFS"/ -o "$ROOTFS" -p

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!"
#TODO: add summary nodes and check performance?

# Write cleanmarkers to the rootfs partition
: "${FS_WRITE_CLEANMARKERS:?variable unset}" # define writing cleanmarkers to final image
[ "${FS_WRITE_CLEANMARKERS}" = "y" ] && b_write_cleanmarkers "$ROOTFS" "$erase_sz" "$FS_SZ"

PATH="$OLD_PATH"
BITSTREAM_PART=none
[ -f "${PREFIX_BOOT}/bitstream.bin" ] && BITSTREAM_PART="${PREFIX_BOOT}/bitstream.bin"

# Add bitstream to PHOENIX_DISK
if [ -f "${PREFIX_BOOT}/bitstream.bin" ]; then
printf "Copying "${PREFIX_BOOT}/bitstream.bin" (offs="$((BS_OFFS/4096))" blocks)\n"
dd if="${PREFIX_BOOT}/bitstream.bin" of="$PHOENIX_DISK" bs=4096 seek=$((BS_OFFS/4096)) conv=notrunc 2>/dev/null
fi
# create full disk image
image_builder.py -v disk --nvm "$NVM_CONFIG" --part "bitstr=$BITSTREAM_PART" --part "rootfs=$ROOTFS"

# Add rootfs to PHOENIX_DISK
printf "Copying "$ROOTFS" (offs="$((FS_OFFS/4096))" blocks)\n"
dd if="$ROOTFS" of="$PHOENIX_DISK" bs=4096 seek=$((FS_OFFS/4096)) conv=notrunc 2>/dev/null
# 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
15 changes: 15 additions & 0 deletions _targets/armv7a9/zynq7000/nvm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
flash0:
size: 0x1000000 # 16 MB
block_size: 512
padding_byte: 0xff
partitions:
- name: plo
offs: 0x0
- name: kernel
offs: 0x10000
- name: bitstr
offs: 0x400000
- name: rootfs
offs: 0x800000
size: 0x800000
type: jffs2
21 changes: 21 additions & 0 deletions _targets/armv7a9/zynq7000/preinit.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
size: 0x1000
is_relative: False

contents:
- map kddr 0x100000 0x12ffff rwx
- map ddr 0x130000 0x900000 rwx
- map ocram1 0x00000000 0x00030000 rwx
- phfs usb0 1.2 phoenixd
- phfs uart0 0.0 phoenixd
- phfs uart1 0.1 raw
- phfs flash0 2.0 raw
- console 0.1

- 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 }}'

Loading

0 comments on commit fe0b4c4

Please sign in to comment.