Atlas SoCのビルドがうまく行かないメモ


# まずはAtlas-SoCでLチカ

## DE0-Nano-SoC
http://www.marutsu.co.jp/pc/i/595199/

## Macと接続
- USB UART
- 5Vアダプタ
- Ethernet

## Atlas SoC
http://rocketboards.org/foswiki/view/Documentation/AtlasSoCDevelopmentPlatform

## Atlas SOCイメージ取得
http://rocketboards.org/foswiki/view/Documentation/AtlasSoCSdCardImage

## MacでSD card書き出し
http://ledsun.hatenablog.com/entry/2014/10/26/174712
8分かかった。

```
sudo dd if=atlas_sdcard_v1.1.img of=/dev/rdisk3 bs=1m
```

## シリアルポートで起動確認
http://rocketboards.org/foswiki/view/Documentation/AtlasSoCBootingLinux

```
screen /dev/tty.usbserial-AK00D0RG 115200
```

```
.---O---.                                           
|       |                  .-.           o o        
|   |   |-----.-----.-----.| |   .----..-----.-----.
|       |     | __  |  ---'| '--.|  .-'|     |     |
|   |   |  |  |     |---  ||  --'|  |  |  '  | | | |
'---'---'--'--'--.  |-----''----''--'  '-----'-'-'-'
                -'  |
                '---'

The Angstrom Distribution atlas_sockit ttyS0

Angstrom v2014.12 - Kernel 4.0.0-altera

atlas_sockit login: 
```

## rootでログイン、IP確認

login: root

```
root@atlas_sockit:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:07:ed:43:5b:10  
          inet addr:192.168.1.119  Bcast:192.168.1.255  Mask:255.255.255.0

```

## ブラウザからアクセス
![Screen Shot 2016-01-23 at 3.33.42 PM.png](https://qiita-image-store.s3.amazonaws.com/0/38290/e73aec90-6c02-cb31-8ad0-fe26aab8ef95.png)


## Lチカ
![Screen Shot 2016-01-23 at 3.35.29 PM.png](https://qiita-image-store.s3.amazonaws.com/0/38290/351750c3-504b-9e81-0694-fa0e36629385.png)

Lチカした。

# クラウドに開発環境構築

つづいて、Google Compute Engine上に開発環境を構築。

## GCEインスタンス作成
- asia-east1-c
- Debian 7 backport
- 4 core
- 26GB memory
- 512GB SSD

## gnomeとVNCをインストール
https://medium.com/google-cloud/linux-gui-on-the-google-cloud-platform-800719ab27c5#.gfbsfncr3

## Altera SoC EDS
https://www.altera.com/products/design-software/embedded-software-developers/soc-eds/overview.html

- ダウンロード遅い
- GUIから`SoCEDSSetup-15.1.0.185-linux.run`をダブルクリックして起動

<img width="888" alt="Screen Shot 2016-01-24 at 6.21.57 AM.png" src="https://qiita-image-store.s3.amazonaws.com/0/38290/f0d83804-8236-731c-3bda-b3c8b00bb2d3.png">

<img width="489" alt="Screen Shot 2016-01-24 at 6.32.19 AM.png" src="https://qiita-image-store.s3.amazonaws.com/0/38290/40e0360c-f760-e344-3ed7-497c9714c119.png">
- rootでないと言われる。"b"を選択

```
$ sudo ~/altera/15.1/embedded/ds-5/run_post_install_for_ARM_DS-5_v5.22.0.sh
```

## Altera Quartus Prime Lite

- ダウンロード遅い
- `Quartus-lite-15.1.1.189-linux.tar`を展開

```
$ tar xf Quartus-lite-15.1.1.189-linux.tar 
```

- `setup.sh`をダブルクリックして起動

<img width="694" alt="Screen Shot 2016-01-24 at 6.38.18 AM.png" src="https://qiita-image-store.s3.amazonaws.com/0/38290/3fcee870-d928-4a0e-98b5-b530f687bf34.png">

<img width="669" alt="Screen Shot 2016-01-24 at 7.11.12 AM.png" src="https://qiita-image-store.s3.amazonaws.com/0/38290/69c81d87-3f45-f73a-b431-1d5206aa6976.png">

<img width="987" alt="Screen Shot 2016-01-24 at 7.15.20 AM.png" src="https://qiita-image-store.s3.amazonaws.com/0/38290/4090c932-a700-f0fb-086b-8a776b687633.png">

## GHRD構築

ここの手順で：
http://rocketboards.org/foswiki/view/Documentation/AtlasSoCCompileHardwareDesign

先人たちの記録。
http://qiita.com/new3bon/items/1d7349f9bb0c2d6228a1
http://qiita.com/miyox/items/cf23040d8fa10ac62ff3

まずは必要そうなライブラリを入れとく。必要なのかいまいちわからない。
http://rocketboards.org/foswiki/view/Documentation/AlteraSoCDevelopmentBoardYoctoGettingStarted

```
$ sudo apt-get install sed wget cvs subversion git-core coreutils unzip texi2html texinfo libsdl1.2-dev docbook-utils gawk python-pysqlite2 diffstat help2man make gcc build-essential g++ desktop-file-utils chrpath libgl1-mesa-dev libglu1-mesa-dev mercurial autoconf automake groff libtool xterm
```

ドキュメントの通り、このままmake allする。

```
mkdir atlas
cd atlas
wget https://github.com/dwesterg/atlas-soc-ghrd/tarball/master -O atlas-soc-ghrd.tgz
mkdir atlas-soc-ghrd
tar -xzvf atlas-soc-ghrd.tgz --strip-components 1 -C atlas-soc-ghrd
cd atlas-soc-ghrd
make all
```

と、quartus系のコマンドがないと怒られてビルドが止まる。

パスを通すため、以下をまとめて.bash_profileに書いておく。Quartusのパスは適当にそれっぽい場所を通しておいた（きもちわるいー）。

```
# for SoC EDS
export SOCEDS_DEST_ROOT=~/altera/15.1/embedded
source ~/altera/15.1/embedded/env.sh

# for Quartus
PATH=$PATH:~/altera_lite/15.1/quartus/bin:~/altera_lite/15.1/quartus/sopc_builder/bin
export PATH
```

しかし、embedded/env.shを呼ぶと、makeがNo such fileと言われるようになる。。orz

```
kazsato@kaz-altera0:~/atlas/atlas-soc-ghrd$ make all
bash: /home/kazsato/altera/15.1/embedded/ds-5/bin/make: No such file or directory
```

いや、altera/15.1/embedded/ds-5/bin/makeはちゃんとあるけどなあ。。なんなんだ。じゃあ、/usr/bin/makeを指定することにするよ。

miyoさんの書いてたfft問題を避けるために、念のためこれをやっておく。

```
$ mv scripts/qsys_add_fft128_components.tcl scripts/qsys_add_fft128_components.tcl.old
```

さて、もう一回ビルドに挑戦。

```
$ /usr/bin/make scrub_clean
$ /usr/bin/make all
```

こんなエラーで止まった。

```
Error: Quartus Prime Analysis & Synthesis was unsuccessful. 12 errors, 39 warnings
    Error: Peak virtual memory: 1489 megabytes
    Error: Processing ended: Sun Jan 24 23:54:28 2016
    Error: Elapsed time: 00:04:46
    Error: Total CPU time (on all processors): 00:05:10
make: *** [stamp/ATLAS_SOC_GHRD.quartus_pin_assignments.stamp] Error 3
```

logsを`Error`でgrepすると、、

```
azsato@kaz-altera0:~/atlas/atlas-soc-ghrd$ cat logs/* | grep Error
2016.01.24.23:46:44 Error: add_instance altchip_id_0 altchip_id 15.0: No module type named altchip_id.
2016.01.24.23:46:44 Error: set_instance_parameter_value altchip_id_0 ID_VALUE 18446744073709551615: No module named altchip_id_0.
2016.01.24.23:46:44 Error: add_connection altchip_id_0.output chip_id_read_mm_0.in0: No interface named altchip_id_0.output.
2016.01.24.23:46:44 Error: add_connection clk_0.clk altchip_id_0.clkin: No interface named altchip_id_0.clkin.
2016.01.24.23:46:44 Error: add_connection clk_0.clk_reset altchip_id_0.reset: No interface named altchip_id_0.reset.
2016.01.24.23:49:32 Error: border: Error during execution of script generate_hps_sdram.tcl: seq: add_fileset_file: No such file /tmp/alt6824_827278802229984201.dir/0003_seq_gen/hps_AC_ROM.hex
2016.01.24.23:49:32 Error: border: Error during execution of script generate_hps_sdram.tcl: Generation stopped, 3 or more modules remaining
2016.01.24.23:49:32 Error: border: Execution of script generate_hps_sdram.tcl failed
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:01 Info:
2016.01.24.23:49:32 Error: border: ********************************************************************************************************************
2016.01.24.23:49:32 Error: border: 
2016.01.24.23:49:32 Error: border: Use qsys-generate for a simpler command-line interface for generating IP.
2016.01.24.23:49:32 Error: border: 
2016.01.24.23:49:32 Error: border: Run ip-generate with switch --remove-qsys-generate-warning to prevent this notice from appearing in subsequent runs.
2016.01.24.23:49:32 Error: border: 
2016.01.24.23:49:32 Error: border: ********************************************************************************************************************
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:08 Warning: Ignored parameter assignment device=5CSEMA4U23C6
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:08 Warning: Ignored parameter assignment extended_family_support=true
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:18 Warning: hps_sdram: 'Quick' simulation modes are NOT timing accurate. Some simulation memory models may issue warnings or errors
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:18 Warning: hps_sdram.seq: This module has no ports or interfaces
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:18 Warning: hps_sdram.p0: p0.scc must be exported, or connected to a matching conduit.
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:18 Warning: hps_sdram.as: as.afi_init_cal_req must be exported, or connected to a matching conduit.
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:18 Warning: hps_sdram.as: as.tracking must be exported, or connected to a matching conduit.
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:18 Warning: hps_sdram.c0: c0.status must be exported, or connected to a matching conduit.
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:18 Warning: hps_sdram.p0: p0.avl must be connected to an Avalon-MM master
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:18 Info: hps_sdram: Generating altera_mem_if_hps_emif "hps_sdram" for QUARTUS_SYNTH
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:20 Info: pll: "hps_sdram" instantiated altera_mem_if_hps_pll "pll"
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:20 Info: p0: Generating clock pair generator
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:21 Info: p0: Generating hps_sdram_p0_altdqdqs
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0:
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0: *****************************
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0:
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0: Remember to run the hps_sdram_p0_pin_assignments.tcl
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0: script after running Synthesis and before Fitting.
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0:
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0: *****************************
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0:
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: p0: "hps_sdram" instantiated altera_mem_if_ddr3_hard_phy_core "p0"
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Error: seq: add_fileset_file: No such file /tmp/alt6824_827278802229984201.dir/0003_seq_gen/hps_AC_ROM.hex
2016.01.24.23:49:32 Error: border: while executing
2016.01.24.23:49:32 Error: border: "add_fileset_file $file_name [::alt_mem_if::util::hwtcl_utils::get_file_type $file_name 0] PATH $file_pathname"
2016.01.24.23:49:32 Error: border: ("foreach" body line 4)
2016.01.24.23:49:32 Error: border: invoked from within
2016.01.24.23:49:32 Error: border: "foreach file_pathname $return_files_sw {
2016.01.24.23:49:32 Error: border:              _dprint 1 "Preparing to add $file_pathname"
2016.01.24.23:49:32 Error: border:              set file_name [file tail $file_pathname]
2016.01.24.23:49:32 Error: border:              add_fileset_file $..."
2016.01.24.23:49:32 Error: border: (procedure "generate_sw" line 18)
2016.01.24.23:49:32 Error: border: invoked from within
2016.01.24.23:49:32 Error: border: "generate_sw $name $fileset"
2016.01.24.23:49:32 Error: border: ("if" then script line 4)
2016.01.24.23:49:32 Error: border: invoked from within
2016.01.24.23:49:32 Error: border: "if {[string compare -nocase $fileset QUARTUS_SYNTH] == 0} {
2016.01.24.23:49:32 Error: border:              set top_level_file "altera_mem_if_hhp_qseq_synth_top.v"
2016.01.24.23:49:32 Error: border:              add_fileset_file $top_level_fi..."
2016.01.24.23:49:32 Error: border: (procedure "generate_files" line 4)
2016.01.24.23:49:32 Error: border: invoked from within
2016.01.24.23:49:32 Error: border: "generate_files $name QUARTUS_SYNTH"
2016.01.24.23:49:32 Error: border: (procedure "generate_synth" line 3)
2016.01.24.23:49:32 Error: border: invoked from within
2016.01.24.23:49:32 Error: border: "generate_synth altera_mem_if_hhp_qseq_synth_top"
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: seq: "hps_sdram" instantiated altera_mem_if_hhp_ddr3_qseq "seq"
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Error: Generation stopped, 3 or more modules remaining
2016.01.24.23:49:32 Error: border: 2016.01.24.23:49:32 Info: hps_sdram: Done "hps_sdram" with 7 modules, 33 files
2016.01.24.23:49:33 Error: Generation stopped, 2 or more modules remaining
2016.01.24.23:49:34 Error: qsys-generate failed with exit code 1: 60 Errors, 10 Warnings
```

むー。何これ。。

`not found`でgrepすると、

```
kazsato@kaz-altera0:~/atlas/atlas-soc-ghrd$ cat logs/* | grep 'not found'
Warning (125092): Tcl Script File ../ip/fft128/fft_test.qip not found
Warning (125092): Tcl Script File ../ip/fft128/fft_test.qip not found
Warning (125092): Tcl Script File ../ip/fft128/fft_test.qip not found
Warning (125092): Tcl Script File ../ip/fft128/fft_test.qip not found
Warning (125092): Tcl Script File ../ip/fft128/fft_test.qip not found
Warning (125092): Tcl Script File soc_system/synthesis/soc_system.qip not found
Warning (125092): Tcl Script File ../ip/fft128/fft_test.qip not found
Warning (125092): Tcl Script File soc_system/synthesis/soc_system.qip not found
```

StratixV問題かな？ miyoxさんのアドバイスどおりに入れてみよう。まずはデバイスパッケージを入手。

Alteraのダウンロードセンターから`stratixv-15.1.0.185.qdz`をダウンロード。QuartusのTools > Install Devicesでインストールを試みるも、「このバージョンのQuartusには対応してない」と出てくるので、

```
$ cd ~/altera_lite/15.1/
$ unzip stratixv-15.1.0.185.qdz
```

として解凍。

これで再度make allすると、、結果は同じでしたorz

↑いまここ。


## ref
http://qiita.com/yukitaketake/items/96f9fd8607cc1f3c8e7c
http://marsee101.blog19.fc2.com/blog-entry-3281.html
http://qiita.com/tags/Atlas-SoC