명령줄이라고?
네, GUI 프로그래머보다 훨씬 편리합니다. FPGA 에 비트스트림(bitstream) 파일을 로딩하는 일은 반복적으로 하게 됩니다. 항상 같은 컴퓨터에 연결된 같은 보드의 같은 FPGA 에 같은 파일을 넣는 것이죠. 그런데 GUI 도구는 이 간단한 일을 왠지 부담스러운 의식으로 만들어 버립니다. 게다가 정확히 어떤 디바이스가 연결되어 있는지 판별하지 못할 때는 퀴즈를 내기도 합니다. 그래서 사용자인 내가 정확한 디바이스를 알고 있어야만 하죠.
명령줄에서는 말 그대로 bash 히스토리에서 명령을 골라 Enter 키만 누르면 끝입니다. 놀랍게도 명령줄 도구는 GUI 도구가 묻는 어처구니없는 질문들을 하지 않습니다.
먼저, 이것저것 시험해 보기
환경을 설정합니다:
$ /path/to/quartus/15.1/nios2eds/nios2_command_shell.sh
감지된 모든 디바이스를 나열하려면(케이블은 자동 감지됩니다):
$ quartus_pgm --auto
Info: *******************************************************************
Info: Running Quartus Prime Programmer
Info: Version 15.1.0 Build 185 10/21/2015 SJ Lite Edition
Info: Copyright (C) 1991-2015 Altera Corporation. All rights reserved.
[ ... ]
Info: agreement for further details.
Info: Processing started: Sun May 27 15:06:22 2018
Info: Command: quartus_pgm --auto
Info (213045): Using programming cable "USB-BlasterII [2-5.1]"
1) USB-BlasterII [2-5.1]
02B040DD 5CGTFD9(A5|C5|D5|E5)/..
020A40DD 5M2210Z/EPM2210
[ ... ]
위와 같이 디바이스 목록을 확인하는 작업은 비트스트림(bitstream)을 로딩하는 데 필수적이지는 않습니다. 아마도 JTAG 체인에서 FPGA 의 위치를 파악하는 정도에는 유용할 수 있습니다. 정말로 보드를 탐색하려고 한 번쯤 해 보는 일입니다.
jtagd
TCP/IP 포트 1309 번을 리슨(listen)하는 데몬이라는 점을 알아 두는 것이 중요합니다. jtagd 는 USB 버스를 통해 JTAG 어댑터와 통신하는 역할을 담당하므로, GUI 프로그래머와 명령줄 도구 모두 이 데몬에 의존합니다. 실행 중인 데몬이 없다면 두 도구 모두 데몬을 직접 시작합니다.
그런데 여러 버전의 Quartus 를 사용한다면 이것이 혼란의 원인이 될 수 있습니다. 특히 이전 버전으로 FPGA 로딩을 먼저 시도한 다음, 새 버전을 사용하려 할 때가 그렇습니다. 새 버전의 Quartus 가 계속해서 이전 버전의 jtagd 를 사용하기 때문입니다. 그리고 이 이전 버전 jtagd 는 새 버전 Quartus 가 지원하는 FPGA 를 지원하지 못할 수 있습니다. 그러므로 결론적으로, 이상한 문제가 발생한다면 아래 명령으로 해결될 수 있으며, 어차피 해가 될 일도 없습니다:
$ killall jtagd
FPGA 로딩하기
quartus_pgm 은 출력 대부분을 녹색 텍스트로 표시합니다. 일반적으로 빨간색 텍스트가 없다면 모든 것이 정상적으로 진행된 것입니다.
$ quartus_pgm -m jtag -o "p;path/to/file.sof"
또는 JTAG 체인에서 디바이스의 위치를 명시적으로 지정할 수도 있습니다(특히 첫 번째 디바이스가 아닐 때 유용합니다). 여기서 @1 은 JTAG 체인의 첫 번째 디바이스라는 뜻입니다. 두 번째 디바이스라면 @2 를 사용하면 됩니다.
$ quartus_pgm -m jtag -o "p;path/to/file.sof@1"
Info: *******************************************************************
Info: Running Quartus Prime Programmer
Info: Version 15.1.0 Build 185 10/21/2015 SJ Lite Edition
Info: Copyright (C) 1991-2015 Altera Corporation. All rights reserved.
Info: Your use of Altera Corporation's design tools, logic functions
Info: and other software and tools, and its AMPP partner logic
Info: functions, and any output files from any of the foregoing
Info: (including device programming or simulation files), and any
Info: associated documentation or information are expressly subject
Info: to the terms and conditions of the Altera Program License
Info: Subscription Agreement, the Altera Quartus Prime License Agreement,
Info: the Altera MegaCore Function License Agreement, or other
Info: applicable license agreement, including, without limitation,
Info: that your use is for the sole purpose of programming logic
Info: devices manufactured by Altera and sold by Altera or its
Info: authorized distributors. Please refer to the applicable
Info: agreement for further details.
Info: Processing started: Sun May 27 15:35:02 2018
Info: Command: quartus_pgm -m jtag -o p;path/to/file.sof@1
Info (213045): Using programming cable "USB-BlasterII [2-5.1]"
Info (213011): Using programming file p;path/to/file.sof@1 with checksum 0x061958E1 for device 5CGTFD9E5F35@1
Info (209060): Started Programmer operation at Sun May 27 15:35:05 2018
Info (209016): Configuring device index 1
Info (209017): Device 1 contains JTAG ID code 0x02B040DD
Info (209007): Configuration succeeded -- 1 device(s) configured
Info (209011): Successfully performed operation(s)
Info (209061): Ended Programmer operation at Sun May 27 15:35:09 2018
Info: Quartus Prime Programmer was successful. 0 errors, 0 warnings
Info: Peak virtual memory: 432 megabytes
Info: Processing ended: Sun May 27 15:35:09 2018
Info: Elapsed time: 00:00:07
Info: Total CPU time (on all processors): 00:00:03
디바이스 불일치, JTAG 체인 스캔 실패 등 어떤 문제가 발생하더라도 빨간색으로 표시되는 오류가 있으므로 놓치기 어렵습니다. 명령줄 인터페이스의 좋은 점은 매번 시도할 때 처음부터 모든 과정을 다시 시작한다는 것입니다. 그러니 그냥 보드 전원을 켜고 다시 시도하면 됩니다.
Cyclone 10 GX FPGA 개발 키트
이 보드는 저에게 몇 가지 추가적인 골칫거리를 안겨 주었으므로, 이에 대해 간단히 언급하겠습니다. 이 보드를 컴퓨터에 연결하면 09fb:6810 으로 나타납니다. 그런데 다음 명령으로(끝의 '@2'에 유의하세요) FPGA 로딩을 시도하면:
$ quartus_pgm -m jtag -o "p;thecode.sof@2"
Error (213019): Can't scan JTAG chain. Error code 86.
디바이스 ID 가 09fb:6010 으로 바뀝니다. 따라서 펌웨어(firmware)가 분명히 다시 프로그래밍되고 있음을 알 수 있습니다(시스템 로그에는 새 ID 로 연결이 끊겼다가 다시 연결되는 이벤트가 기록됩니다). Quartus 의 GUI 프로그래밍 도구는 이 보드를 GX0000406 으로 감지하지만, 'Auto Detect'를 클릭하면 'Unable to scan device chain. Hardware is not connected'라는 메시지가 표시됩니다.
자, 그럼 스캔을 한번 시도해 볼까요?
$ quartus_pgm --auto
[ ... ]
Info (213045): Using programming cable "10CGX0000406 [1-5.1.2]"
1) 10CGX0000406 [1-5.1.2]
Unable to read device chain - Hardware not attached
제 경우의 문제는, 실행 중이던 jtagd 가 Cyclone 10 디바이스를 인식하지 못하는 이전 버전의 Quartus 에 의해 시작되었다는 점이었습니다. 그러니 위의 조언대로 jtagd 를 종료하세요. 그런 다음 Quartus Pro 17.1 에서 위 명령으로 프로그래밍이 정상적으로 동작했습니다:
$ quartus_pgm --auto
[...]
Info (213045): Using programming cable "USB-BlasterII [1-5.1.2]"
1) USB-BlasterII [1-5.1.2]
031820DD 10M08SA(.|ES)/10M08SC
02E120DD 10CX220Y