(no commit message)
[libreriscv.git] / HDL_workflow.mdwn
1 # HDL workflow
2
3 This section describes the workflow for developing the LibreSoC.
4
5 # Hardware
6
7 RAM is the biggest requirement. Minimum 16GB, the more the better (32 or 64GB starts to reach "acceptable" levels. Disk space is not hugely critical: 256GB SSD should be more than adequate. Simulations and FPGA compilations however are where raw processing power is a must. High end Graphics Cards are nonessential.
8
9 What is particularly useful is to have not only hi-res screens (curved is *strongly* recommended if the LCD is over 24in wide), but to have several of them: the more the better. Either a DisplayLink UD160A (or more modern variant) or simply using a second (lower spec hardware) machine is really effective.
10
11 Also it is really recommended to have a UHD monitor (4k - 3840x2160), or at least 2560x1200. However, caveat below: please when editing do not assume that everyone will have access to such high resolution screens.
12
13 # Operating System
14
15 First install and become familiar with Debian (ubuntu if you absolutely must) for standardisation cross-team and so that toolchain installation is greatly simplified. yosys in particular warns that trying to use Windows or MacOS will get you into a world of pain.
16
17 Only a basic GUI desktop is necessary: fvwm2, xfce4, lxde are perfectly sufficient (alongside wicd-gtk for network management). Other more complex desktops can be used however may consume greater resources.
18
19 # editors and editing
20
21 Whilst this is often a personal choice, the fact that many editors are GUI based and run fullscreen with the entire right hand side *and* middle *and* the majority of the left side of the hi-res screen entirely unused and bereft of text leaves experienced developers both amused and puzzled.
22
23 At the point where such fullscreen users commit code with line lengths well over 160 characters, that amusement quickly evaporates.
24
25 Where the problems occur with fullscreen editor usage is when a project is split into dozens if not hundreds of small files (as this one is). At that point it becomes pretty much essential to have as many as six to eight files open *and on-screen* at once, without overlaps i.e. not in hidden tabs, next to at least two if not three additional free and clear terminals into which commands are regularly and routinely typed (make, git commit, nosetests3 etc).
26
27 Once this becomes necessary, it it turn implies that having greater than 80 chars per line - and running editors fullscreen -is a severe hindance to an essential *and highly effective* workflow technique.
28
29 Additionally, care should be taken to respect that not everyone will have 200 column editor windows. They may only have a 1280 x 800 laptop which barely fits 2 80x60 xterms side by side. Consequently, having excessively long functions is also a hindrance to others, as such developers with limited screen resources would need to continuously page-up and page-down to read code even of a single function, in full.
30
31 This helps explain in part, below, why compliance with pep8 is enforced, including its 80 character limit. In short: not everyone has the same "modern" GUI workflow or has access to the same computing resources as you, so please do respect that.
32
33 # Software prerequisites
34
35 Whilst many resources online advocate "sudo" in front of all root-level commands below, this quickly becomes tiresome. run "sudo bash", get a root prompt, and save yourself some typing.
36
37 * sudo bash
38 * apt-get install vim exuberant-ctags
39 * apt-get install build-essential
40 * apt-get install git python3.7 python3.7-dev python-nosetest3
41 * apt-get install graphviz xdot
42 * return to user prompt (ctrl-d)
43
44 ## yosys
45
46 Follow the source code (git clone) instructions here: <http://www.clifford.at/yosys/download.html>
47
48 Do not try to use a fixed revision (currently 0.9), nmigen is evolving and frequently interacts with yosys
49
50 ## symbiyosys
51
52 Follow the instructions here: <https://symbiyosys.readthedocs.io/en/latest/quickstart.html#installing>
53
54 You do not have to install all of those (avy, boolector can be left out if desired) however the more that are installed the more effective the formal proof scripts will be (less resource utilisation in certain circumstances).
55
56 ## nmigen
57
58 nmigen may be installed as follows:
59
60 * mkdir ~/src
61 * cd !$
62 * git clone https://github.com/m-labs/nmigen.git
63 * cd nmigen
64 * sudo bash
65 * python3 setup.py develop
66 * ctrl-d
67
68 testing can then be carried out with "python3 setp.py test"
69
70 # Registering for git repository access
71
72 After going through the onboarding process and having agreed to take responsibility for certain tasks, ask on the mailing list for git repository access, sending in a public key (id_rsa.pub). If you do not have one generate it with ssh-keygen -t rsa.
73
74 NEVER SEND ANYONE THE PRIVATE KEY. By contrast the public key, on account of being public, is perfectly fine to make... err... public.
75
76 Create a file ~/.ssh/config with the following lines:
77
78 Host git.libre-riscv.org
79 Port 922
80
81 Wait for the Project Admin to confirm that the ssh key has been added to the required repositories. Once confirmed,
82 you can clone any of the repos at http://git.libre-riscv.org:
83
84 git clone gitolite3@git.libre-riscv.org:REPONAME.git
85
86 # Development Rules
87
88 team communication:
89
90 * communicate on the mailing list or the bugtracker an intent to take responsibility for a particular task.
91 * assign yourself as the bug's owner
92 * *keep in touch* about what you are doing, and why.
93 * if you cannot do sonething that you gave taken responsibility for, then unless it is a dire emergency please say so, on-list. we won't mind. we'll help sort it out.
94
95 for actual code development:
96
97 * **do not commit autogenerated output**. write a shell script and commit that, or add a Makefile to run the command that generates the output, but **do not** add the actual output of **any** command to the repository. ever. this is really important. even if it is a human-readable file rather than a binary object file.
98 * if the command needed to create any given autogenerated output is not currently in the list of dependencies, first consult on the list if it is okay to make that command become a hard dependency of the project (hint: java, node.js php and .NET commands will cause delays in responses due to list participants laughing hysterically too much), and after a decision is made, document the dependency and how its source code is obtained and built.
99 * plan in advance to write not just code but a full test suite for that code. **this is not optional**. large python projects that do not have unit tests **FAIL**.
100 * edit files making minimal *single purpose* modifications.
101 * prior to committing make sure that relevant unit tests pass, or that the change is a zero-impact addition.
102 * commit no more than 5 to 10 lines at a time, with a CLEAR message (no "added this" or "changed that"). if the commit involves a list of changes or the word "and" it is a "red flag" that the commit has not been properly broken down.
103 * if it is essential to commit large amounts of code, ensure that it is **not** in use **anywhere** by any other code.
104
105 the reason for the above is because python is a weakly typed language. make one tiny change at the base level of the class hierarchy and the effect may be disastrous.
106
107 * all code needs to conform to pep8. use either pep8checker or better run autopep8. however whenever committing whitespace changes, *make a separate commit* with a commit message "whitespace" or "autopep8 cleanup".
108 * pep8 REQUIRES no more than 80 chars per line. this is non-negotiable. if you think you need greater than 80 chars, it *fundamentally* indicates poor code design. split the code down further into smaller classes and functions.
109 * TBD there is a docstring checker. at the minimum make sure to have an SPD license heafer, module header docstring, class docstring and function docstrings on non-obvious functions
110 * make liberal but not excessive use of comments.
111 * unless they are very closely related, only have one module (one class) per file. a file only 25 lines long including imports and docstrings is perfectly fine.
112 * *keep files short and simple*. see below as to why
113 * create a decent directory hierarchy but do not go mad. ask for advice if unsure
114 * please do not use "from module import *". it is extremely bad practice, causes unnecessary resource utilisation, makes code readability extremely difficult, and results in unintended side-effects.
115 * try to keep both filenames and variable names short but not ridiculously obtuse. an interesting compromise on imports is "from ridiculousfilename import longsillyname as lsn", and to assign variables as well: "comb = m.d.comb" followed by multiple "comb += nmigenstmt" lines is a good trick that can reduce code indentation by 6 characters without reducing clarity.
116
117 regarding code structure: we decided to go with small modules that are both easy to analyse, as well as fit onto a single page and be readable when displayed as a visual graph on a full UHD monitor. this is done as follows:
118
119 * using the capability of nmigen (TODO crossref to example) output the module to a yosys ilang (.il) file
120 * in a separate terminal window, run yosys
121 * at the yosys prompt type "read_ilang modulename.il"
122 * type "show top" and a graphviz window should appear. note that typing show, then space, then pressing the tab key twice will give a full list of submodules (one of which will be "top")
123
124 you can now fullsize the graphviz window and scroll around. if it looks reasonably obvious, i.e the connections can be clearly related in your mind back to the actual code (by matching the graph names against signals and modules in the original nmigen code) and the words are not tiny when zoomed out, and connections are not total incomprehensible spaghetti, then congratulations, you have well-designed code. If not, then this indicates a need to split the code further into submodules.
125
126 The reasons for doing a proper modularisation job are several-fold:
127
128 * firstly, we will not be doing a full automated layout-and-hope using alliance/ciriolis2, we will be doing leaf-node thru tree node half-automated half-manual layout, finally getting to the floorplan, then revising and iteratively adjusting.
129 * secondly, examining modules at the gate level (or close to it) is just good practice. poor design creeps in by *not* knowing what the tools are actually doing.
130 * thirdly, unit testing, particularly formal proofs, is far easier on small sections of code.
131
132 # TODO Tutorials
133
134 Find appropriate tutorials for nmigen and yosys, as well as symbiyosys.
135