joeylib2/make/support/psp/packEboot.sh

42 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# Pack a linked PSP program into the EBOOT.PBP the PSP runs, the way the
# PSPSDK's own build.mak does: fix up its module imports in place, write a
# PARAM.SFO with its title, and pack that, its icon (ICON0, a 144x80 PNG)
# and a stripped copy of the ELF (no other pictures, no sound) into the
# EBOOT.PBP. The unstripped ELF stays where it is, for psp-addr2line. Run as
# make/psp.mk's packing step.
#
# Usage: packEboot.sh PROGRAM.elf TITLE ICON0.png EBOOT.PBP
#
# Requires $PSPDEV (exported by make from the installer's
# toolchains/config.mk; toolchains/env.sh for a shell).
set -euo pipefail
if [[ $# -ne 4 ]]; then
echo "usage: $0 PROGRAM.elf TITLE ICON0.png EBOOT.PBP" >&2
exit 2
fi
elf=$1
title=$2
icon=$3
eboot=$4
# PARAM.SFO's MEMSIZE: the PSPSDK's default for firmware after 3.90 (the
# whole user memory a model has).
memSize=2
if [[ -z "${PSPDEV:-}" ]]; then
echo "PSPDEV not set; run ./install.sh install toolchain:psp" >&2
exit 1
fi
stem=${elf%.elf}
"$PSPDEV/bin/psp-fixup-imports" "$elf"
"$PSPDEV/bin/psp-strip" "$elf" -o "$stem.stripped.elf"
"$PSPDEV/bin/mksfoex" -d MEMSIZE="$memSize" "$title" "$stem.sfo"
"$PSPDEV/bin/pack-pbp" "$eboot" "$stem.sfo" "$icon" NULL NULL NULL NULL "$stem.stripped.elf" NULL > /dev/null