diff options
| author | Leah Rowe <leah@libreboot.org> | 2023-10-20 04:10:50 +0100 | 
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2023-10-20 05:03:16 +0100 | 
| commit | 6af65ad430ae58bac5afd0d6e12a97e5e12e9b59 (patch) | |
| tree | 6fd88f362d2ea26ae78d614aa0a3043fa3ddc422 /script/vendor/inject | |
| parent | 4e54a051ef4ae66bae402479cd4ecdc9709e44ca (diff) | |
error handling code cleanup and fixes
in some cases, use of x_ or xx_ can be error-prone,
due to the way $@ is handled; commands requiring
quotes, or with funny file names as arguments such
as spaces in the file name, or other special
characters, can make the x/xx functions break.
in those cases, where x/xx must not be used, the
commands use || err instead
in other cases, use of x/xx is superfluous, and has
been removed in some commands.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'script/vendor/inject')
| -rwxr-xr-x | script/vendor/inject | 34 | 
1 files changed, 22 insertions, 12 deletions
| diff --git a/script/vendor/inject b/script/vendor/inject index 1eebca30..923224d0 100755 --- a/script/vendor/inject +++ b/script/vendor/inject @@ -78,7 +78,7 @@ detect_board()  		_stripped_prefix=${filename#*_}  		board="${_stripped_prefix%.tar.xz}" ;;  	*) -		err "detect_board: could not detect board type" +		err "detect_board $filename: could not detect board type"  	esac	  	[ -d "${boarddir}/" ] || \  		err "detect_board: dir, ${boarddir}, doesn't exist" @@ -98,7 +98,10 @@ build_dependencies()  inject_vendorfiles()  { -	[ "${release}" != "y" ] && x_ patch_rom "${rom}" && return 0 +	if [ "${release}" != "y" ]; then +		patch_rom "${rom}" +		return 0 +	fi  	printf "patching release images\n"  	patch_release_roms  } @@ -108,11 +111,12 @@ patch_release_roms()  	_tmpdir="tmp/romdir"  	x_ rm -Rf "${_tmpdir}"  	x_ mkdir -p "${_tmpdir}" -	x_ tar -xf "${archive}" -C "${_tmpdir}" +	tar -xf "${archive}" -C "${_tmpdir}" || \ +	    err "patch_release_roms: !tar -xf \"${archive}\" -C \"${_tmpdir}\""  	for x in "${_tmpdir}"/bin/*/*.rom ; do  		printf "patching rom: %s\n" "$x" -		x_ patch_rom "${x}" +		patch_rom "${x}"  	done  	for x in "${_tmpdir}"/bin/*/*_nomicrocode.rom ; do  		[ -f "${x}" ] || continue @@ -123,7 +127,7 @@ patch_release_roms()  	done  	( -	x_ cd "${_tmpdir}/bin/"* +	x_ cd "${_tmpdir}/bin/"* # TODO: very dodgy, re-write accordingly  	# NOTE: For compatibility with older rom releases, defer to sha1  	[ "${nukemode}" = "nuke" ] || \ @@ -211,22 +215,28 @@ inject()  	if [ "${_t}" = "GbE" ]; then  		x_ mkdir -p tmp -		x_ cp "${_dest}" "tmp/gbe.bin" +		cp "${_dest}" "tmp/gbe.bin" || \ +		    err "inject: !cp \"${_dest}\" \"tmp/gbe.bin\""  		_dest="tmp/gbe.bin" -		x_ "${nvmutil}" "${_dest}" setmac "${new_mac}" +		"${nvmutil}" "${_dest}" setmac "${new_mac}" || \ +		    err "inject ${_dest}: can't change mac address"  	fi  	if [ "${cbfsname}" = "IFD" ]; then  		if [ "${nukemode}" != "nuke" ]; then -			x_ "${ifdtool}" -i ${_t}:${_dest} "${rom}" -O "$rom" +			"${ifdtool}" -i ${_t}:${_dest} "${rom}" -O "$rom" || \ +			    err "inject: can't insert $_t ($dest) into $rom"  		else -			x_ "${ifdtool}" --nuke ${_t} "${rom}" -O "${rom}" +			"${ifdtool}" --nuke ${_t} "${rom}" -O "${rom}" || \ +			    err "inject ${rom}: can't nuke ${_t} in IFD"  		fi  	else  		if [ "${nukemode}" != "nuke" ]; then -			x_ "${cbfstool}" "${rom}" add -f "${_dest}" \ -			    -n "${cbfsname}" -t ${_t} ${_offset} +			"${cbfstool}" "${rom}" add -f "${_dest}" \ +			    -n "${cbfsname}" -t ${_t} ${_offset} || \ +			    err "inject $rom: can't insert $_t file $_dest"  		else -			x_ "${cbfstool}" "${rom}" remove -n "${cbfsname}" +			"${cbfstool}" "${rom}" remove -n "${cbfsname}" || \ +			    err "inject $rom: can't remove ${cbfsname}"  		fi  	fi | 
