Can you cut a few lines out of your script, showing where you set the variable and where you execute the sed command? (Rather than trying to read thru your entire zipped script.)
bootsize=$(ls -l *boot.bin | awk '{printf "%10d %s\n",$5,$9}') #this line return the size of a file named XXXXXboot.bin and put it in the bootsize variable(only one file in the current folder)
let bootsize=bootsize/512 #this line return the number of 512 bytes block of bootsize
let bootsize=bootsize+1
folderpath=$(pwd) # return the current folder in use in the folderpath variable
bootpath=$(ls -a *boot.bin) # return the name of the XXXXboot.bin
bootpathf=$folderpath/$bootpath # return the full path of the XXXXXboot.bin
cp ../../TEMPLATE_OS_STITCH_penwellB0.xml $rootfspath.xml # copy a config template file to be modified into the current folder and name it with another file (+ .xml)
sed -i "s/BOOTPATH/$bootpathf/g" $rootfspath.xml # modify the file to replace the pattern BOOTPATH by the XXXXboot.bin full path