Skip to content

Commit

Permalink
build: use image_builder in sparc based projects
Browse files Browse the repository at this point in the history
JIRA: CI-494
  • Loading branch information
nalajcie committed Sep 30, 2024
1 parent 473e4f7 commit 05cbdf8
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 153 deletions.
38 changes: 14 additions & 24 deletions _projects/sparcv8leon3-gr716-mimas/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,16 @@

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

BOOT_DEVICE="uart0"
# no NVM storage, all programs are being loaded via UART
export BOOT_DEVICE="uart0"

export PLO_DEVICES="gpio-gr716 uart-grlib"

PREINIT_SCRIPT=(
"map ocram 0x31000000 0x3101FFFF rwx"
"map extram 0x40000000 0x401FFFFF rwx"
"phfs uart0 0.0 phoenixd"
"console 0.1"
)


USER_SCRIPT=(
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs extram extram"
"app ${BOOT_DEVICE} -x grlib-multi extram extram"
"app ${BOOT_DEVICE} -x psh extram extram"
"wait 500"
"go!"
)


b_convert_project() {
prepare_plo_img() {
#TODO: consider using nvm.yaml for merging header with plo
local f="${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img"
local sz=$(stat -c%s "$f")
#TODO: why "- 4" ?
sz=$(((sz - 4)/4))
printf "\xde\xad\xbe\xef" > "$PREFIX_BOOT/plo.img"
printf "%08X" $sz | xxd -r -p >> "$PREFIX_BOOT/plo.img"
Expand All @@ -42,10 +27,15 @@ b_convert_project() {


b_image_project () {
cp "${PREFIX_PROG_STRIPPED}phoenix-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.elf" "$PREFIX_BOOT/"
cp "${PREFIX_PROG_STRIPPED}dummyfs" "$PREFIX_BOOT/"
cp "${PREFIX_PROG_STRIPPED}grlib-multi" "$PREFIX_BOOT/"
cp "${PREFIX_PROG_STRIPPED}psh" "$PREFIX_BOOT/"
prepare_plo_img;

# no NVM storage, all programs are being loaded via UART - prepare user.plo and all binaries in "PREFIX_BOOT"
image_builder.py script --nvm "$NVM_CONFIG" --script "$PLO_SCRIPT_USER" --out "${PREFIX_BOOT}/user.plo"

cp -a "${PREFIX_PROG_STRIPPED}phoenix-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.elf" "$PREFIX_BOOT/"
cp -a "${PREFIX_PROG_STRIPPED}dummyfs" "$PREFIX_BOOT/"
cp -a "${PREFIX_PROG_STRIPPED}grlib-multi" "$PREFIX_BOOT/"
cp -a "${PREFIX_PROG_STRIPPED}psh" "$PREFIX_BOOT/"

b_log "The images have been built for the ${TARGET} platform"
}
18 changes: 18 additions & 0 deletions _projects/sparcv8leon3-gr716-mimas/preinit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
size: 0x1000
is_relative: False

contents:
- map ocram 0x31000000 0x3101FFFF rwx
- map extram 0x40000000 0x401FFFFF rwx
- phfs uart0 0.0 phoenixd
- console 0.1

- if: '{{ not(env.RAM_SCRIPT) | default(false) }}'
action: call
set_base: True
device: '{{ env.BOOT_DEVICE }}'
filename: user.plo
offset: 0 # BOOT_DEVICE is UART, offset doesn't matter?
target_magic: '{{ env.MAGIC_USER_SCRIPT }}'


13 changes: 13 additions & 0 deletions _projects/sparcv8leon3-gr716-mimas/user.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# kernel + initrd
magic: '{{ env.MAGIC_USER_SCRIPT }}'
size: 0x1000
is_relative: True

contents:
- kernel {{ env.BOOT_DEVICE }}
- app {{ env.BOOT_DEVICE }} -x dummyfs extram extram
- app {{ env.BOOT_DEVICE }} -x grlib-multi extram extram
- app {{ env.BOOT_DEVICE }} -x psh extram extram
- wait 2000
- go!

13 changes: 10 additions & 3 deletions _projects/sparcv8leon3-gr716-mini/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@

export PLO_DEVICES="gpio-gr716 uart-grlib flash-gr716"

b_convert_project() {
./phoenix-rtos-build/scripts/gr716-convert.py "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.elf" -o "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img"
./phoenix-rtos-build/scripts/gr716-bch.py "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" "$PREFIX_BOOT/plo.bch"
prepare_plo_img() {
#FIXME: img file already produced by the plo make, change the output filename
FLASH_SIZE=$(image_builder.py query --nvm "$NVM_CONFIG" '{{ nvm.flash0._meta.size }}')
gr716-convert.py "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.elf" -o "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img"
gr716-bch.py -s "$FLASH_SIZE" "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" "$PREFIX_BOOT/plo.bch"
}


b_image_project () {
prepare_plo_img;

image_builder.py -v partition --nvm "$NVM_CONFIG" --name kernel --script "$PLO_SCRIPT_USER"
image_builder.py -v disk --nvm "$NVM_CONFIG" --name flash0 --part "plo=${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" --out "phoenix.disk"

b_log "The images have been built for the ${TARGET} platform"
}
43 changes: 12 additions & 31 deletions _targets/sparcv8leon3/generic/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,13 @@ export PORTS_CURL=n
#
# Platform dependent parameters
#
SIZE_PAGE=$((0x1000))
PAGE_MASK=$((~(SIZE_PAGE - 1)))
KERNEL_OFFS=$((0x10000))
export SIZE_PAGE=$((0x1000))

BOOT_DEVICE="ram0" # Default boot device
NAME_USER_SCRIPT="user.plo" # User script name
OFFS_USER_SCRIPT=$((0xf000))
MAGIC_USER_SCRIPT=$((0xdabaabad)) # User script magic value


PREINIT_SCRIPT=(
"map sram 0x40000000 0x47ffffff rwx"
"console 0.0"
"phfs ram0 4.0 raw"
)

USER_SCRIPT=(
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs sram sram"
"app ${BOOT_DEVICE} -x grlib-uart sram sram"
"app ${BOOT_DEVICE} -x psh sram sram"
"wait 500"
"go!"
)
#
# Project specific build
#
export BOOT_DEVICE="ram0"
export MAGIC_USER_SCRIPT=dabaabad


b_build_project() {
Expand All @@ -66,19 +49,17 @@ b_build_target() {
b_log "Building $TARGET project"
b_log "Building phoenix-rtos-loader"

b_mkscript_preinit

make -C plo all
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

cp "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.elf" "${PREFIX_BOOT}/plo.elf"
cp -a "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.elf" "${PREFIX_BOOT}/plo.elf"
}


b_image_target() {
b_mkscript_user "${USER_SCRIPT[@]}"
cp "$PLO_SCRIPT_DIR/$NAME_USER_SCRIPT" "${PREFIX_BOOT}"

b_prod_image
image_builder.py -v partition --nvm "$NVM_CONFIG" --name kernel --script "$PLO_SCRIPT_USER"
image_builder.py -v disk --nvm "$NVM_CONFIG" --name flash0 --part "plo=${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" --out "phoenix.disk"
}


Expand Down
10 changes: 10 additions & 0 deletions _targets/sparcv8leon3/generic/nvm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
flash0:
size: 0x800000 # 8 MB
block_size: 0x100 # program page size
padding_byte: 0xff
partitions:
- name: plo
offs: 0x0
- name: kernel
offs: 0xf000
# if size not set - last non-virtual partition will be extnded to the end of flash
16 changes: 16 additions & 0 deletions _targets/sparcv8leon3/generic/preinit.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
size: 0x1000
is_relative: False

contents:
- map sram 0x40000000 0x47ffffff rwx
- console 0.0
- phfs ram0 4.0 raw

- 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/sparcv8leon3/generic/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:
- kernel {{ env.BOOT_DEVICE }}
- app {{ env.BOOT_DEVICE }} -x dummyfs sram sram
- app {{ env.BOOT_DEVICE }} -x grlib-uart sram sram
- app {{ env.BOOT_DEVICE }} -x psh sram sram
- wait 500
- go!
78 changes: 19 additions & 59 deletions _targets/sparcv8leon3/gr712rc/build.project
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,12 @@ export PORTS_CURL=n
#
# Platform dependent parameters
#
SIZE_PAGE=$((0x1000))
PAGE_MASK=$((~(SIZE_PAGE - 1)))
KERNEL_OFFS=$((0x10000))

BOOT_DEVICE="flash0" # Default boot device
NAME_USER_SCRIPT="user.plo" # User script name
OFFS_USER_SCRIPT=$((0xf000))
MAGIC_USER_SCRIPT=$((0xdabaabad)) # User script magic value
ERASE_SIZE=$((0x20000)) # Rootfs disk erase block size (in bytes)
FS_OFFS=$((0xc0000))


PREINIT_SCRIPT=(
"map sram 0x40000000 0x80000000 rwx"
"console 0.0"
"phfs uart1 0.1 phoenixd"
"phfs flash0 2.0 raw"
)
export SIZE_PAGE=$((0x1000))

USER_SCRIPT=(
"kernel ${BOOT_DEVICE}"
"app ${BOOT_DEVICE} -x dummyfs;-N;devfs;-D sram sram"
"app ${BOOT_DEVICE} -x grlib-multi sram sram"
"app ${BOOT_DEVICE} -x gr712rc-flash;-r;root:jffs2 sram sram"
"app ${BOOT_DEVICE} -x psh;-i;/etc/rc.psh sram sram"
"wait 500"
"go!"
)
export BOOT_DEVICE="flash0" # Default boot device
export MAGIC_USER_SCRIPT="dabaabad" # User script magic value
#TODO: move to nvm.yaml
ERASE_SIZE=$((0x20000)) # Rootfs disk erase block size (in bytes)


b_build_project() {
Expand All @@ -70,25 +48,18 @@ 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
make -C plo all

cp "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" "$PREFIX_BOOT/plo.img"
cp "${PREFIX_PROG_STRIPPED}plo-ram-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" "$PREFIX_BOOT/plo-ram.img"
cp -a "${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" "$PREFIX_BOOT/plo.img"
cp -a "${PREFIX_PROG_STRIPPED}plo-ram-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img" "$PREFIX_BOOT/plo-ram.img"
}


b_image_target() {
b_mkscript_user "${USER_SCRIPT[@]}"
cp "$PLO_SCRIPT_DIR/$NAME_USER_SCRIPT" "${PREFIX_BOOT}"

b_prod_image
image_builder.py -v partition --nvm "$NVM_CONFIG" --name kernel --script "$PLO_SCRIPT_USER"

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="$PREFIX_BOOT/rootfs.jffs2"

Expand All @@ -100,29 +71,18 @@ b_image_target() {
mv "$ROOTFS.tmp" "$ROOTFS"
fi

sz=$(du -b "$ROOTFS" | awk '{ print $1 }')
echo "rootfs size: $((sz/1024))KB"

local start=$(((FS_OFFS+sz+ERASE_SIZE-1)/ERASE_SIZE)) # Start clean block after rootfs
local end=$((FLASH_SZ/ERASE_SIZE)) # Number of blocks in flash
local nblocks=$((end-start-1)) # Clean blocks

# cmd for creating cleanmarkers in plo on clean system
echo "Create cleanmarkers in plo:"
echo "jffs2 -d 2.0 -c ${start}:${nblocks}:${ERASE_SIZE}:16"
local FS_OFFS=$(image_builder.py query --nvm "$NVM_CONFIG" '{{ nvm.flash0.rootfs.offs }}')
local 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 / $((FS_SZ / 1024)) kB"
[ "$sz" -gt "$FS_SZ" ] && b_die "rootfs size exceeds the target partition!"

# set rootfs offset in image
OFFSET=$FS_OFFS
b_add2img "$ROOTFS" "$PHOENIX_DISK"

if [[ -f "$PREFIX_BOOT"/ptable.img ]]; then
rm "$PREFIX_BOOT"/ptable.img
fi
# cmd for creating cleanmarkers in plo
echo "Format jffs2 partition in plo:"
echo "jffs2 -d 2.0 -c $((FS_OFFS / ERASE_SIZE)):$((FS_SZ / ERASE_SIZE)):${ERASE_SIZE}:16"

"$PREFIX_BOOT"/psdisk "$PREFIX_BOOT"/ptable.img -m "$FLASH_SZ",0x20000 \
-p boot0,0,$((FS_OFFS)),0x51 \
-p root,$((FS_OFFS)),$((FLASH_SZ-FS_OFFS-ERASE_SIZE)),0x72 \
-p ptable,$((FLASH_SZ-ERASE_SIZE)),$((ERASE_SIZE)),0x51
image_builder.py ptable --nvm "$NVM_CONFIG"
image_builder.py -v disk --nvm "$NVM_CONFIG" --part "rootfs=$ROOTFS" --part "plo=${PREFIX_PROG_STRIPPED}plo-${TARGET_FAMILY}-${TARGET_SUBFAMILY}.img"
}


Expand Down
15 changes: 15 additions & 0 deletions _targets/sparcv8leon3/gr712rc/nvm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
flash0:
size: 0x1000000 # 16 MB
block_size: 0x1000
# eraseblock_size: 0x20000 # TODO: add generic support?
padding_byte: 0xff
partitions:
- name: plo
offs: 0x0
- name: kernel
offs: 0x20000
- name: rootfs
offs: 0x100000
- name: ptable
offs: 0xfe0000
size: 0x20000
18 changes: 18 additions & 0 deletions _targets/sparcv8leon3/gr712rc/preinit.plo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
size: 0x1000
is_relative: False

contents:
#FIXME: map should end at 0x7fffffff
- map sram 0x40000000 0x80000000 rwx
- console 0.0
- phfs uart1 0.1 phoenixd
- phfs flash0 2.0 raw

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

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

contents:
- kernel {{ env.BOOT_DEVICE }}
- app {{ env.BOOT_DEVICE }} -x dummyfs;-N;devfs;-D sram sram
- app {{ env.BOOT_DEVICE }} -x grlib-multi sram sram
- app {{ env.BOOT_DEVICE }} -x gr712rc-flash;-r;root:jffs2 sram sram
- app {{ env.BOOT_DEVICE }} -x psh;-i;/etc/rc.psh sram sram
- wait 500
- go!
Loading

0 comments on commit 05cbdf8

Please sign in to comment.