compileROM.sh 985 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. printf "\nConverting code.list to code.bin\n"
  3. #create code.bin from code.list (comments can stay after lines)
  4. perl -ne 'print pack("B32", $_)' < code.list > code.bin
  5. #printf "to verify, use: \nxxd -b -c4 code.bin\n"
  6. #printf "to create intel hex file for quartus, use: \nsrec_cat code.bin -binary -output -intel > code.hex\n"
  7. #add padding unless specified to not add padding
  8. if [[ $1 != "noPadding" ]]; then
  9. printf "Padding code.bin with ones until multiple of 4096\n"
  10. #get file size
  11. SIZE=$(wc -c < code.bin)
  12. printf "Size of code.bin is $SIZE bytes\n"
  13. #get needed bytes to make multiple of 4096
  14. NEEDED=$((4096-($SIZE%4096)))
  15. printf "Need $NEEDED more bytes for next multiple of 4096\n"
  16. printf "Appending $NEEDED bytes to code.bin\n"
  17. dd if=<(yes $'\xFF' | tr -d "\n") bs=1 count=$NEEDED >> code.bin
  18. fi
  19. FILESIZE=`du -hs code.bin | cut -f1`
  20. echo "Size of binary: $FILESIZE"
  21. printf "Done compiling binary files\n"