Revision d1ed66aa

View differences:

latex/STL_book_note.tex
1
\documentclass[12pt]{article}
2
\usepackage{booktabs}
3
\usepackage{listings}
4
\usepackage{color}
5
\definecolor{codegreen}{rgb}{0,0.6,0}
6
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
7
\definecolor{codepurple}{rgb}{0.58,0,0.82}
8
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
9
\lstdefinestyle{mystyle}{
10
    language=C++,
11
    backgroundcolor=\color{backcolour},
12
    commentstyle=\color{codegreen},
13
    keywordstyle=\color{magenta},
14
    numberstyle=\tiny\color{codegray},
15
    stringstyle=\color{codepurple},
16
    % basicstyle=\footnotesize,
17
    % basicstyle=\scriptsize,
18
    basicstyle=\ttfamily\footnotesize,
19
    breakatwhitespace=false,
20
    breaklines=true,
21
    captionpos=b,
22
    keepspaces=true,
23
    numbers=left,
24
    numbersep=5pt,
25
    showspaces=false,
26
    showstringspaces=false,
27
    showtabs=false,
28
    tabsize=2
29
}
30
\lstset{style=mystyle}
31

  
32

  
33
\usepackage[colorlinks]{hyperref}       % from http://tex.stackexchange.com/questions/3568/how-does-one-typeset-a-url
34
\hypersetup{citecolor=pink}
35
\hypersetup{linkcolor=red}
36
\hypersetup{urlcolor=blue}
37
\usepackage{cleveref}
38

  
39
\begin{document}
40

  
41
\title{
42
    Book Note
43
    STL Tutorial and Reference Guide (1996)
44
    David R. Musser, Atul Saini.
45
}
46

  
47
\author{Quynh PX Nguyen  quynh.xq@gmail.com}
48

  
49
\maketitle
50

  
51
\clearpage
52

  
53

  
54
\section{Chapter 1}
55
    \subsection{Template}
56
        \subsubsection{Template Functions}
57
            \begin{lstlisting}
58
template <class T>
59
const T& custom_max(const T& x, const T& y)
60
{
61
    return x < y ? y : x;
62
}
63
            \end{lstlisting}
64

  
65
        \subsubsection{Template Member Functions}
66

  
67

  
68
\section{Chapter 2 - Overview of STL Components}
69
    \subsection{From the official documentation}
70
        \href{http://www.sgi.com/tech/stl/doc_introduction.html}{Introduction from the Official Documentation}
71

  
72
         The STL documentation classifies components in two ways.
73

  
74
        \textbf{Categories} are a classification by functionality. The categories are:
75
        \begin{itemize}
76
            \item Container
77
            \item Iterator
78
            \item Algorithm
79
            \item Function Object
80
            \item Utility
81
            \item Adaptor
82
            \item Allocator
83
        \end{itemize}
84

  
85
        \textbf{Component types} are a structural classification: one based on what kind of C++ entity (if any) a component is. The component types are:
86
        \begin{itemize}
87
            \item Type (i.e. a \lstinline{struct} or \lstinline{class}).
88

  
89
            Ex: \lstinline{vector<T, Alloc>}. Read more \href{http://www.sgi.com/tech/stl/Vector.html}{here}
90

  
91
            Ex: \lstinline{input_iterator<T, Distance>}.
92

  
93
            \item Function. Ex: \lstinline{find} function
94
            \item Concept. Ex: \lstinline{Container}. Read more \href{http://www.sgi.com/tech/stl/Container.html}{here}
95
        \end{itemize}
96

  
97
        \lstinline{Concept} is kind of the definition. And then \lstinline{Type} is the ???materialized version of each concept. \lstinline{Function} is the implementation that receives some input, and returns some output.
98

  
99
        It is misleading to think that the component type of one specific \emph{function objects}, such as \lstinline{plus<T>} belongs to \emph{Function}. Actually, \lstinline{plus<T>} is a \emph{Type}
100

  
101
        \begin{table}[h]
102
        \centering
103
            \begin{tabular}{|l|l|l|}
104
            \toprule
105
                Name & Category & Component Types \\
106
            \midrule
107
                Sequence & Container & Concept \\
108
                vector & Container & Type \\
109
                Input Iterator & Iterators & Concept \\
110
                input\_iterator & Iterators & Type \\
111
                distance & Algorithms, Iterators & Function \\
112
                find, find\_if & Algorithms & Function \\
113
                Binary Function & Functors & Concept \\
114
                Adaptable Generator & Functors & Concept \\
115
                Predicate & Functors & Concept \\
116
                plus<T> (predefined function objects) & Functors & Type \\
117
            \bottomrule
118
            \end{tabular}
119
        \end{table}
120

  
121
        \subsubsection{Function Objects}
122
            Just as iterators are a generalization of pointers, function objects are a generalization of functions: a function object is anything that you can call using the ordinary function call syntax.
123

  
124
            There are several different concepts relating to function objects, including \texttt{Unary Function} (a function object that takes a single argument, i.e. one that is called as f(x)) and \texttt{Binary Function} (a function object that takes two arguments, i.e. one that is called as f(x, y)). Function objects are an important part of generic programming because they \textbf{allow abstraction} not only over the types of objects, but also \textbf{over the operations} that are being performed.
125

  
126
        \subsubsection{More about \emph{Concepts}}
127
            \lstinline{Find} isn't the only STL algorithm that has such a set of requirements; the arguments to \lstinline{for_each} and \lstinline{count}, and other algorithms, must satisfy the same requirements. These requirements are sufficiently important that we give them a name: we call such a set of type requirements a concept, and we call this particular concept \texttt{Input Iterator}. We say that a type conforms to a concept, or that it is a model of a concept, if it satisfies all of those requirements. We say that \lstinline{int*} is a model of Input Iterator because \lstinline{int*} provides all of the operations that are specified by the \texttt{Input Iterator} requirements.
128

  
129
            the author of \lstinline{find} only has to consider the interface specified by the concept \texttt{Input Iterator}, rather than the implementation of every possible type that conforms to that concept. Similarly, if you want to use \lstinline{find}, you need only to ensure that the arguments you pass to it are models of \texttt{Input Iterator}.
130

  
131
            Container classes, like iterators, are organized into a hierarchy of concepts. All containers are models of the concept \texttt{Container}; more refined concepts, such as \texttt{Sequence} and \texttt{Associative Container}, describe specific types of containers.
132

  
133
    \subsection{From the book}
134
        \subsubsection{Containers}
135
            Sequence Containers
136

  
137
            Sorted Associative Containers
138

  
139
        \subsubsection{Generic Algorithms}
140

  
141
        \subsubsection{Iterators}
142

  
143
        \subsubsection{Function Objects}
144

  
145
            This one is also known as \emph{functors}
146

  
147
            passing a \emph{function object}
148

  
149
            \textbf{function object} can carry with them additional information that an ordinary function cannot.
150

  
151
        \subsubsection{Adaptors}
152
            \lstinline{1 << 26} = $2^{26}$
153

  
154
            I don't really get why defining the \lstinline{reverse_iterator} has to be that difficult
155

  
156
            And what is the difference between \lstinline{vector<float>::reverse_iterator} and \lstinline{reverse_iterator<vector<float>::iterator, ... >}
157

  
158
            \begin{lstlisting}
159
reverse_iterator<vector<float>::iterator, float,
160
                float&, ptrdiff_t> first(vector1.end()), last(vector1.begin());
161

  
162
// Meaning
163
vector<float>::iterator // this is the container type's iterator TYPE
164
float // corresponding value type
165
float& // reference type for the value type
166
ptrdiff_t // distance type for the iterator type = differences between iterator values
167
first // variable of type reverse_iterator<vector<float>::iterator, float,
168
                float&, ptrdiff_t>
169
            \end{lstlisting}
170

  
171

  
172
\section{Chapter 3 - How STL Differs from Other Libraries}
173
    each container provides some category of iterators.
174
    each algorithm works with some category of iterators.
175

  
176
    So the data structure is separated from the algorithm.
177

  
178

  
179
\section{Chapter 4 - Iterators}
180

  
181
\section{Chapter 5 - Generic Algorithms}
182
    Nonmutating Sequence Algorithms: \lstinline{find, adjacent_find, count, for_each, mismatch, equal, search}
183

  
184
    Mutating Sequence Algorithms:
185
    \begin{itemize}
186
        \item \lstinline{copy, copy_backward}
187
        \item \lstinline{fill, fill_n}
188
        \item \lstinline{generate}
189
    \end{itemize}
190

  
191
    [pg. 86] I don't understand why the \lstinline{operator()} in class \lstinline{calc_square} can be invoked
192

  
193
\end{document}
latex/important.tex
1
\relax 
2
\providecommand\hyper@newdestlabel[2]{}
3
\@setckpt{important\relax \protect \unhbox \voidb@x \kern .06em\vbox {\hrule width.3em}commands}{
4
\setcounter{page}{13}
5
\setcounter{equation}{0}
6
\setcounter{enumi}{0}
7
\setcounter{enumii}{0}
8
\setcounter{enumiii}{0}
9
\setcounter{enumiv}{0}
10
\setcounter{footnote}{0}
11
\setcounter{mpfootnote}{0}
12
\setcounter{part}{0}
13
\setcounter{section}{1}
14
\setcounter{subsection}{2}
15
\setcounter{subsubsection}{1}
16
\setcounter{paragraph}{0}
17
\setcounter{subparagraph}{0}
18
\setcounter{figure}{0}
19
\setcounter{table}{0}
20
\setcounter{parentequation}{0}
21
\setcounter{lstnumber}{4}
22
\setcounter{Item}{0}
23
\setcounter{Hfootnote}{0}
24
\setcounter{bookmark@seq@number}{6}
25
\setcounter{lstlisting}{0}
26
\setcounter{section@level}{3}
27
}
latex/important_commands.tex
1
%!TEX root = note.tex
2

  
3
\section{Important Commands}
4

  
5
    \begin{lstlisting}
6
cp .config.original .config
7
make dirclean
8
make menuconfig
9
./compile_toolchain.sh
10
    \end{lstlisting}
latex/lab_11_10.tex
1
\documentclass[12pt]{article}
2
\begin{document}
3

  
4
\end{document}
latex/note.tex
1

  
2 1
% http://www.ams.jhu.edu/~ers/learn-latex/
3 2

  
4 3
\documentclass[12pt]{article}
......
13 12
\usepackage{amsmath}               % great math stuff
14 13
\usepackage{amsfonts}              % for blackboard bold, etc
15 14
\usepackage{amsthm}                % better theorem environments
16
\usepackage{listings}			   % to add code
15
\usepackage{listings}              % to add code
17 16
\lstset{language=Java}
17
\renewcommand{\lstlistingname}{Code} % change "Listing 1.1" to "Code 1.1"
18

  
18 19
\usepackage[utf8]{inputenc}
19 20
\usepackage{color}
20 21

  
......
57 58
\newcommand{\col}[1]{\left[\begin{matrix} #1 \end{matrix} \right]}
58 59
\newcommand{\comb}[2]{\binom{#1^2 + #2^2}{#1+#2}}
59 60

  
61
\usepackage[T1]{fontenc}
62
\AtBeginDocument{%
63
  \begingroup\lccode`~=`_%
64
  \lowercase{\endgroup\let~}_%
65
  \catcode`_=12
66
}
60 67

  
61 68
\begin{document}
62 69

  
63
\nocite{*}
64

  
65 70
\title{Thesis - Note Taking}
71
\nocite{*}
66 72

  
67 73
\author{166071 - Pham Xuan Quynh Nguyen \\
68 74
DISI - University of Trento}
......
70 76
\maketitle
71 77

  
72 78
\clearpage
73
\section{Week 0}
74
    \subsection{Friday, 11/09/2015}
75
        \subsubsection{paper-adhoc.pdf}
76
            \textbf{Mesh network} A mesh network is a network topology in which each node relays data for the network. All mesh nodes cooperate in the distribution of data in the network. \footnote{https://en.wikipedia.org/wiki/Mesh\_networking}
77

  
78
            \textbf{Multi-Point Relays (MPR)}: nodes in Wireless ad hoc network that do the job of relaying messages between nodes. They also have the main role in routing and selecting the proper route from any source to any desired destination node. \footnote{https://en.wikipedia.org/wiki/Multipoint\_relay}
79

  
80
            \textbf{Optimized Link State Routing (OLSR)} an IP routing protocol optimized for \textit{mobile ad hoc networks}, which can also be used on other \textit{wireless ad hoc networks}. OLSR is a proactive \textit{link-state routing protocol}, which uses\textit{ hello and topology control (TC) messages} to discover and then disseminate link state information throughout the mobile ad hoc network. Individual nodes use this topology information to compute next hop destinations for all nodes in the network using shortest hop forwarding paths.
81

  
82
            \textbf{OLSRd} Optimized Link State Routing daemon - reads information about meshed networks from the txtinfo
83

  
84
            A \textbf{wireless ad hoc network} (WANET) is a decentralized type of wireless network.[1][2] The network is \textit{ad hoc} because it does not rely on a pre existing infrastructure, such as (i) routers in wired networks or (ii) access points in managed (infrastructure) wireless networks. Instead, each node participates in routing by forwarding data for other nodes, so the determination of which nodes forward data is made dynamically on the basis of network connectivity. In addition to the classic routing, ad hoc networks can use flooding for forwarding data.
85

  
86
            A \textbf{mobile ad hoc network} (MANET) is a continuously self-configuring, infrastructure-less network of mobile devices connected without wires. Ad hoc is Latin and means "for this purpose".
87

  
88
            cross-AP routing? abc
89

  
90
            \textbf{beam-width}
91

  
92
%%%%%%%%%%%%%%%%%%
93
% WEEK 1
94
%%%%%%%%%%%%%%%%%%
95
\section{Week 1}
96
    \subsection{Brandes 2001}
97
        \subsubsection{Counting the number of shortest paths}
98
            Explanation on k-th power of the adjacency matrix equals the number of paths from vertex \texttt{u} to vertex \texttt{v} \footnote{https://www.quora.com/What-is-an-intuitive-explanation-for-why-raising-an-adjacency-matrix-to-the-power-of-n-gives-a-new-matrix-with-the-number-of-n-paths}
99

  
100
            \textbf{Floyd/Warshall algorithm}
101

  
102
        \subsubsection{Code for shortest-path betweenness centrality}
103
            https://github.com/networkx/networkx/blob/master/networkx/algorithms/centrality/betweenness.py
104

  
105
            Line 116
106
            \begin{itemize}
107
            \item S
108
            \item P
109
            \item sigma
110
            \end{itemize}
111

  
112
            $c_B(v) =\sum_{s,t \in V} \frac{\sigma(s, t|v)}{\sigma(s, t)}$
113

  
114
%%%%%%%%%%%%%%%%%%
115
% WEEK 2
116
%%%%%%%%%%%%%%%%%%
117
\section{Week 2}
118
    \subsection{Library \texttt{networkx}}
119
        \textbf{Graph object}
120
            \begin{lstlisting}
121
            {'A': {'B': {}, 'F': {}}, 'C': {'B': {}}, 'B': {'A': {}, 'C': {}, 'E': {}}, 'E': {'B': {}, 'D': {}, 'F': {}}, 'D': {'E': {}, 'G': {}}, 'G': {'D': {}}, 'F': {'A': {}, 'E': {}}}
122
            \end{lstlisting}
123

  
124
        \textbf{Function} \texttt{\_single\_source\_shortest\_path\_basic} (in betweenness.py)
125

  
126
            Variable meanings:
127
            \begin{itemize}
128
                \item sigma[v] is the number of shortest paths passing through vertice v
129
                \item D[v] is the distance from vertice s to vertice v
130
                \item P[v] contains predecessors for node v. The predecessors satisfies the condition that if we traverse through it, the path is the shortest one.
131
            \end{itemize}
132

  
133
        \textbf{Function} \texttt{\_accumulate\_basic}
134
            S is an array
135
            S.pop() iteratively returns elements in array S, from the last to the top
136

  
137
    \subsection{Brandes 2001}
138
        I still do not understand Section 4, but I understand the pseudo-code. [21/09/2015]
139

  
140
    \subsection{OpenWRT}
141

  
142
        Download the SDK \footnote{http://wiki.openwrt.org/doc/howto/obtain.firmware.sdk}
143

  
144
        README.SDK:
145
        \begin{lstlisting}
146
            This is the OpenWrt SDK. It contains a stripped-down version of
147
            the buildroot. You can use it to test/develop packages without
148
            having to compile your own toolchain or any of the libraries
149
            included with OpenWrt.
150

  
151
            To use it, just put your buildroot-compatible package directory
152
            in the subdir 'package/' and run 'make' from this directory.
153
        \end{lstlisting}
154

  
155
        \subsubsection{Definition}
156
            \textbf{SDK}
157

  
158
            \textbf{OpenWrt Build System} = build system for the OpenWrt Linux distribution
159

  
160
            \textbf{OpenWrt Linux distribution}
161

  
162
            \textbf{Instruction set architecture} = the translator that turns the code a machine is running into instructions a processor can understand and execute. It's an important part of a processor.
163

  
164
            \textbf{ARM} = a simpler instruction set architecture comparing to the \texttt{x86}. It has the power efficiency. It uses \texttt{Reduced Instruction Set Computing - RISC}
165

  
166
            \textbf{i386} = that chips win over ARM chips on the performance. It uses \texttt{Complex Instruction Set Computing - CISC}.
167

  
168
            \textbf{Debian on ARM}
169

  
170

  
171
        \subsubsection{Compile OpenWRT CC toolchain to get OpenWrt SDK}
172
            Compile the \texttt{OpenWrt Chaos Calmer}. More information can be found in \href{http://wiki.openwrt.org/doc/howto/buildroot.exigence}{OpenWrt build system - Installation}.
173

  
174
            \href{http://wiki.openwrt.org/doc/howto/build}{This tutorial} shows how to build \texttt{OpenWrt SDK from source}
175

  
176
            \begin{lstlisting}
177
# Clone OpenWRT, branch Chaos Clamer
178
git clone http://git.openwrt.org/15.05/openwrt.git
179
# Make OpenWrt build system check for missing packages on your build-system using one of the following commands
180
make defconfig
181
make prereq
182
# To set the target system (e.g. Broadcom BCM47xx)
183
# Select (by pressing Y) on item "[ ] Build the OpenWrt SDK"
184
make menuconfig
185
            \end{lstlisting}
186

  
187
            \begin{figure}[h]
188
                \label{fig:menuconfig}
189
                \caption{menuconfig}
190
                \includegraphics[scale=0.3]{make-menuconfig}
191
            \end{figure}
192

  
193
            \begin{lstlisting}
194
# It will take a while to finish
195
make
196

  
197
# 2nd run - ERROR
198
make[3] -C package/system/opkg host-compile
199
make -r world: build failed. Please re-run make with -j1 V=s to see what's going on
200
make: *** [world] Error 1
201

  
202
# 3rd run - NO ERROR
203
            \end{lstlisting}
204

  
205
            Inside the directory \textbf{target-arm\_cortex-a9\_uClibc-0.9.33.2\_eabi} in \texttt{build\_dir}, we have \texttt{OpenWrt-SDK-bcm53xx\_gcc-4.8-linaro\_uClibc-0.9.33.2\_eabi.Linux-x86\_64}. This one is the \texttt{compiled toolchain}, or the \texttt{OpenWrt SDK, version Chaos Calmer}
206

  
207
    \subsubsection{Compile packages with OpenWrt SDK}
208
            Steps I performed
209

  
210
            \begin{itemize}
211
                \item Test building package with OpenWrt SDK BB on Linux Mint 17 (based on Ubuntu Trusty - 14)
212
                    \begin{lstlisting}
213
svn export svn://svn.openwrt.org/openwrt/packages/utils/sed package/sed
214
grep DEPENDS package/sed/Makefile
215
make package/sed/compile # GOT ERROR HERE
216

  
217
configure: error: in `/home/quynh/Thesis/openwrt-bb/build_dir/target-mipsel_mips32_uClibc-0.9.33.2/sed-4.2.1':
218
configure: error: C compiler cannot create executables
219
See `config.log' for more details.
220
make[2]: *** [/home/quynh/Thesis/openwrt-bb/build_dir/target-mipsel_mips32_uClibc-0.9.33.2/sed-4.2.1/.configured_] Error 77
221
make[2]: Leaving directory `/home/quynh/Thesis/openwrt-bb/package/sed'
222
make[1]: *** [package/sed/compile] Error 2
223
make[1]: Leaving directory `/home/quynh/Thesis/openwrt-bb'
224
make: *** [package/sed/compile] Error 2
225

  
226
# SOLUTION
227
sudo apt-get install ccache
228
                    \end{lstlisting}
229

  
230
                \item Test building package with Ubuntu 14 in VMWare. I got the same error as when running with Linux Mint 17
231

  
232
                \item Install the library \texttt{ccache} manually would solve the problem
233

  
234
                \item After successfully compile the package, you will find *.ipk in the folder [./bin/bcm53xx/packages/base/]. Where \texttt{bcm53xx} is the code of the target device. It can also be \texttt{ar71xx} or something else.
235
            \end{itemize}
236

  
237
        \subsubsection{Install QEMU}
238
            Check out \href{http://wiki.qemu.rg/Download}{Wiki} for instruction. It will took a while to install, since QEMU required several packages that are not present on my system.
239

  
240
            After installation, I have a bunch of binary file \texttt{quem-*} in \texttt{/usr/local/bin}
241

  
242
        \subsubsection{Generate OpenWrt Image with QEMU}
243
            This \href{http://wiki.openwrt.org/doc/howto/obtain.firmware}{Obtaining Firmware} page summarizes different ways to obtain \texttt{OpenWrt Firmware Image (OFI)} file. After having the OFI, then we can feed it into QEMU.
244

  
245
            This \href{http://wiki.openwrt.org/doc/howto/obtain.firmware.generate}{Image Generator tutorial} has instruction on how to generate Image Builder firmware.
246

  
247
            Since when compiling OpenWrt toolchain, I didn't modify anything in \texttt{menuconfig}, so the target system of the SDK are bcm53xx.
248

  
249
            The profile for bcm53xx can be found \href{https://dev.openwrt.org/browser/trunk/target/linux/bcm53xx/profiles/100-Generic.mk?rev=42143}{here}. I (randomly) pick \texttt{BCM53010}
250

  
251
            \begin{lstlisting}
252
cd openwrt
253
wget https://downloads.openwrt.org/chaos_calmer/15.05/bcm53xx/generic/OpenWrt-ImageBuilder-15.05-bcm53xx.Linux-x86_64.tar.bz2
254
tar -xvjf OpenWrt-ImageBuilder-15.05-bcm53xx.Linux-x86_64.tar
255
cd OpenWrt-ImageBuilder-15.05-bcm53xx.Linux-x86_64
256
mv OpenWrt-ImageBuilder-15.05-bcm53xx.Linux-x86_64 ImageBuilder-15.05-bcm53xx.Linux-x86_64
257

  
258
# If you want to modify 'profiles', then:
259
vim ./ImageBuilder-15.05-bcm53xx.Linux-x86_64/target/linux/bcm53xx/profiles/100-Generic.mk
260
make image PROFILE=Generic
261

  
262
# The image is in ./bin directory
263
# ERROR: Can't find any *.bin file
264
            \end{lstlisting}
265

  
266
            I then tried to generate OpenWrt Firmware Image for \texttt{ar71xx} just like the original tutorial. This time I got all the *.bin file.
267

  
268
        \subsubsection{Run OpenWrt Firmware Image with QEMU}
269
            \begin{lstlisting}
270
qemu-system-x86_64 -kernel openwrt-15.05-ar71xx-generic-vmlinux.elf
271
            \end{lstlisting}
272

  
273
    \subsection{Questions}
274
        What is \emph{buildroot-compatible package directory}?
275

  
276
        How big should I set for the size of the QEMU image? In \href{http://www.aurel32.net/info/debian_arm_qemu.php}{here} they set aside 10G for creating the image.
277

  
278
    \subsection{Technical Problems}
279
        \subsubsection{'build' folder for all output file from LaTeX with \emph{LaTeXTools}}
280
            So far I couldn't do it. I tried:
281
            \begin{itemize}
282
                \item Edit directly the simpleBuilder.py script, adding the option \texttt{"-output\_directory=./build"}. It shows error that *.log file cannot be written
283
                \item Change the \texttt{builder\_settings} \emph{Preferences -> Package Settings -> LaTeXTools -> Settings - User}
284
            \end{itemize}
285

  
286
            The solution now is to add extra line in \texttt{.gitignore} to not including the generated \emph{pdf} for each \emph{TeX} file.
287

  
288
        \subsubsection{Cannot compile package \texttt{sed}}
289
            Some line of errors from config.log
290
            \begin{lstlisting}
291
/home/quynh/Thesis/openwrt-bb/staging_dir/host/bin/
292
ccache_cc: 2: exec: ccache: not found
293
            \end{lstlisting}
294

  
295
            But I found the file ccache\_cc in that folder as shown below:
296
            \begin{lstlisting}
297
quynh in ~/Thesis/openwrt-bb/staging_dir/host/bin
298
$ ls | grep ccache
299
ccache_cc
300
ccache_cxx
301
            \end{lstlisting}
302

  
303
            Solution: sudo apt-get install ccache
304

  
305

  
306
    \subsection{Misc}
307
        [11:10 - 11:30] I'm doing shitty things now. Removing gcc-base, and as a result most packages are being removed: chrome, mozilla, gedit,  tortoise, skype, python, libqt4, networkmanager. Now I don't have the internet connection anymore.
308

  
79
    \include{note_w00}
80
    \include{note_w01}
81
    \include{note_w02}
309 82
    \include{note_w03}
83
    \include{note_w04}
84
    \include{note_w05}
85
    \include{note_w06}
86
    \include{note_w07}
87
    \include{note_w08}
88
    \include{tips}
89
    \include{important_commands}
310 90

  
311 91
\end{document}
latex/note_w00.tex
1
%!TEX root = note.tex
2

  
3
\section*{Week 0}
4
    \subsection{Friday, 11/09/2015}
5
        \subsubsection{paper-adhoc.pdf}
6
            \textbf{Mesh network} A mesh network is a network topology in which each node relays data for the network. All mesh nodes cooperate in the distribution of data in the network. \footnote{https://en.wikipedia.org/wiki/Mesh\_networking}
7

  
8
            \textbf{Multi-Point Relays (MPR)}: nodes in Wireless ad hoc network that do the job of relaying messages between nodes. They also have the main role in routing and selecting the proper route from any source to any desired destination node. \footnote{https://en.wikipedia.org/wiki/Multipoint\_relay}
9

  
10
            \textbf{Optimized Link State Routing (OLSR)} an IP routing protocol optimized for \textit{mobile ad hoc networks}, which can also be used on other \textit{wireless ad hoc networks}. OLSR is a proactive \textit{link-state routing protocol}, which uses\textit{ hello and topology control (TC) messages} to discover and then disseminate link state information throughout the mobile ad hoc network. Individual nodes use this topology information to compute next hop destinations for all nodes in the network using shortest hop forwarding paths.
11

  
12
            \textbf{OLSRd} Optimized Link State Routing daemon - reads information about meshed networks from the txtinfo
13

  
14
            A \textbf{wireless ad hoc network} (WANET) is a decentralized type of wireless network.[1][2] The network is \textit{ad hoc} because it does not rely on a pre existing infrastructure, such as (i) routers in wired networks or (ii) access points in managed (infrastructure) wireless networks. Instead, each node participates in routing by forwarding data for other nodes, so the determination of which nodes forward data is made dynamically on the basis of network connectivity. In addition to the classic routing, ad hoc networks can use flooding for forwarding data.
15

  
16
            A \textbf{mobile ad hoc network} (MANET) is a continuously self-configuring, infrastructure-less network of mobile devices connected without wires. Ad hoc is Latin and means "for this purpose".
17

  
18
            cross-AP routing? abc
19

  
20
            \textbf{beam-width}
latex/note_w01.tex
1
%!TEX root = note.tex
2

  
3
%%%%%%%%%%%%%%%%%%
4
% WEEK 1
5
%%%%%%%%%%%%%%%%%%
6
\section{Week 1}
7
    \subsection{Brandes 2001}
8
        \subsubsection{Counting the number of shortest paths}
9
            Explanation on k-th power of the adjacency matrix equals the number of paths from vertex \texttt{u} to vertex \texttt{v} \footnote{https://www.quora.com/What-is-an-intuitive-explanation-for-why-raising-an-adjacency-matrix-to-the-power-of-n-gives-a-new-matrix-with-the-number-of-n-paths}
10

  
11
            \textbf{Floyd/Warshall algorithm}
12

  
13
        \subsubsection{Code for shortest-path betweenness centrality}
14
            https://github.com/networkx/networkx/blob/master/networkx/algorithms/centrality/betweenness.py
15

  
16
            Line 116
17
            \begin{itemize}
18
            \item S
19
            \item P
20
            \item sigma
21
            \end{itemize}
22

  
23
            $c_B(v) =\sum_{s,t \in V} \frac{\sigma(s, t|v)}{\sigma(s, t)}$
24

  
latex/note_w02.tex
1
%!TEX root = note.tex
2

  
3
%%%%%%%%%%%%%%%%%%
4
% WEEK 2
5
%%%%%%%%%%%%%%%%%%
6
\section{Week 2}
7
    \subsection{Library \texttt{networkx}}
8
        \textbf{Graph object}
9
            \begin{lstlisting}
10
            {'A': {'B': {}, 'F': {}}, 'C': {'B': {}}, 'B': {'A': {}, 'C': {}, 'E': {}}, 'E': {'B': {}, 'D': {}, 'F': {}}, 'D': {'E': {}, 'G': {}}, 'G': {'D': {}}, 'F': {'A': {}, 'E': {}}}
11
            \end{lstlisting}
12

  
13
        \textbf{Function} \texttt{\_single\_source\_shortest\_path\_basic} (in betweenness.py)
14

  
15
            Variable meanings:
16
            \begin{itemize}
17
                \item sigma[v] is the number of shortest paths passing through vertice v
18
                \item D[v] is the distance from vertice s to vertice v
19
                \item P[v] contains predecessors for node v. The predecessors satisfies the condition that if we traverse through it, the path is the shortest one.
20
            \end{itemize}
21

  
22
        \textbf{Function} \texttt{\_accumulate\_basic}
23
            S is an array
24
            S.pop() iteratively returns elements in array S, from the last to the top
25

  
26
    \subsection{Brandes 2001}
27
        I still do not understand Section 4, but I understand the pseudo-code. [21/09/2015]
28

  
29
    \subsection{OpenWRT}
30

  
31
        Download the SDK \footnote{http://wiki.openwrt.org/doc/howto/obtain.firmware.sdk}
32

  
33
        README.SDK:
34
        \begin{lstlisting}
35
            This is the OpenWrt SDK. It contains a stripped-down version of
36
            the buildroot. You can use it to test/develop packages without
37
            having to compile your own toolchain or any of the libraries
38
            included with OpenWrt.
39

  
40
            To use it, just put your buildroot-compatible package directory
41
            in the subdir 'package/' and run 'make' from this directory.
42
        \end{lstlisting}
43

  
44
        \subsubsection{Definition}
45
            \textbf{SDK}
46

  
47
            \textbf{OpenWrt Build System} = build system for the OpenWrt Linux distribution
48

  
49
            \textbf{OpenWrt Linux distribution}
50

  
51
            \textbf{Instruction set architecture} = the translator that turns the code a machine is running into instructions a processor can understand and execute. It's an important part of a processor.
52

  
53
            \textbf{ARM} = a simpler instruction set architecture comparing to the \texttt{x86}. It has the power efficiency. It uses \texttt{Reduced Instruction Set Computing - RISC}
54

  
55
            \textbf{i386} = that chips win over ARM chips on the performance. It uses \texttt{Complex Instruction Set Computing - CISC}.
56

  
57
            \textbf{Debian on ARM}
58

  
59

  
60
        \subsubsection{Compile OpenWRT CC toolchain to get OpenWrt SDK}
61
            Compile the \texttt{OpenWrt Chaos Calmer}. More information can be found in \href{http://wiki.openwrt.org/doc/howto/buildroot.exigence}{OpenWrt build system - Installation}.
62

  
63
            \href{http://wiki.openwrt.org/doc/howto/build}{This tutorial} shows how to build \texttt{OpenWrt SDK from source}
64

  
65
            \begin{lstlisting}
66
# Clone OpenWRT, branch Chaos Clamer
67
git clone http://git.openwrt.org/15.05/openwrt.git
68
# Make OpenWrt build system check for missing packages on your build-system using one of the following commands
69
make defconfig
70
make prereq
71
# To set the target system (e.g. Broadcom BCM47xx)
72
# Select (by pressing Y) on item "[ ] Build the OpenWrt SDK"
73
make menuconfig
74
            \end{lstlisting}
75

  
76
            \begin{figure}[h]
77
                \label{fig:menuconfig}
78
                \caption{menuconfig}
79
                \includegraphics[scale=0.3]{make-menuconfig}
80
            \end{figure}
81

  
82
            \begin{lstlisting}
83
# It will take a while to finish
84
make
85

  
86
# 2nd run - ERROR
87
make[3] -C package/system/opkg host-compile
88
make -r world: build failed. Please re-run make with -j1 V=s to see what's going on
89
make: *** [world] Error 1
90

  
91
# 3rd run - NO ERROR
92
            \end{lstlisting}
93

  
94
            Inside the directory \textbf{target-arm\_cortex-a9\_uClibc-0.9.33.2\_eabi} in \texttt{build\_dir}, we have \texttt{OpenWrt-SDK-bcm53xx\_gcc-4.8-linaro\_uClibc-0.9.33.2\_eabi.Linux-x86\_64}. This one is the \texttt{compiled toolchain}, or the \texttt{OpenWrt SDK, version Chaos Calmer}
95

  
96
    \subsubsection{Compile packages with OpenWrt SDK}
97
            Steps I performed
98

  
99
            \begin{itemize}
100
                \item Test building package with OpenWrt SDK BB on Linux Mint 17 (based on Ubuntu Trusty - 14)
101
                    \begin{lstlisting}
102
svn export svn://svn.openwrt.org/openwrt/packages/utils/sed package/sed
103
grep DEPENDS package/sed/Makefile
104
make package/sed/compile # GOT ERROR HERE
105

  
106
configure: error: in `/home/quynh/Thesis/openwrt-bb/build_dir/target-mipsel_mips32_uClibc-0.9.33.2/sed-4.2.1':
107
configure: error: C compiler cannot create executables
108
See `config.log' for more details.
109
make[2]: *** [/home/quynh/Thesis/openwrt-bb/build_dir/target-mipsel_mips32_uClibc-0.9.33.2/sed-4.2.1/.configured_] Error 77
110
make[2]: Leaving directory `/home/quynh/Thesis/openwrt-bb/package/sed'
111
make[1]: *** [package/sed/compile] Error 2
112
make[1]: Leaving directory `/home/quynh/Thesis/openwrt-bb'
113
make: *** [package/sed/compile] Error 2
114

  
115
# SOLUTION
116
sudo apt-get install ccache
117
                    \end{lstlisting}
118

  
119
                \item Test building package with Ubuntu 14 in VMWare. I got the same error as when running with Linux Mint 17
120

  
121
                \item Install the library \texttt{ccache} manually would solve the problem
122

  
123
                \item After successfully compile the package, you will find *.ipk in the folder [./bin/bcm53xx/packages/base/]. Where \texttt{bcm53xx} is the code of the target device. It can also be \texttt{ar71xx} or something else.
124
            \end{itemize}
125

  
126
        \subsubsection{Install QEMU}
127
            Check out \href{http://wiki.qemu.rg/Download}{Wiki} for instruction. It will took a while to install, since QEMU required several packages that are not present on my system.
128

  
129
            After installation, I have a bunch of binary file \texttt{quem-*} in \texttt{/usr/local/bin}
130

  
131
        \subsubsection{Generate OpenWrt Image with QEMU}
132
            This \href{http://wiki.openwrt.org/doc/howto/obtain.firmware}{Obtaining Firmware} page summarizes different ways to obtain \texttt{OpenWrt Firmware Image (OFI)} file. After having the OFI, then we can feed it into QEMU.
133

  
134
            This \href{http://wiki.openwrt.org/doc/howto/obtain.firmware.generate}{Image Generator tutorial} has instruction on how to generate Image Builder firmware.
135

  
136
            Since when compiling OpenWrt toolchain, I didn't modify anything in \texttt{menuconfig}, so the target system of the SDK are bcm53xx.
137

  
138
            The profile for bcm53xx can be found \href{https://dev.openwrt.org/browser/trunk/target/linux/bcm53xx/profiles/100-Generic.mk?rev=42143}{here}. I (randomly) pick \texttt{BCM53010}
139

  
140
            \begin{lstlisting}
141
cd openwrt
142
wget https://downloads.openwrt.org/chaos_calmer/15.05/bcm53xx/generic/OpenWrt-ImageBuilder-15.05-bcm53xx.Linux-x86_64.tar.bz2
143
tar -xvjf OpenWrt-ImageBuilder-15.05-bcm53xx.Linux-x86_64.tar
144
cd OpenWrt-ImageBuilder-15.05-bcm53xx.Linux-x86_64
145
mv OpenWrt-ImageBuilder-15.05-bcm53xx.Linux-x86_64 ImageBuilder-15.05-bcm53xx.Linux-x86_64
146

  
147
# If you want to modify 'profiles', then:
148
vim ./ImageBuilder-15.05-bcm53xx.Linux-x86_64/target/linux/bcm53xx/profiles/100-Generic.mk
149
make image PROFILE=Generic
150

  
151
# The image is in ./bin directory
152
# ERROR: Can't find any *.bin file
153
            \end{lstlisting}
154

  
155
            I then tried to generate OpenWrt Firmware Image for \texttt{ar71xx} just like the original tutorial. This time I got all the *.bin file.
156

  
157
        \subsubsection{Run OpenWrt Firmware Image with QEMU}
158
            \begin{lstlisting}
159
qemu-system-x86_64 -kernel openwrt-15.05-ar71xx-generic-vmlinux.elf
160
            \end{lstlisting}
161

  
162
    \subsection{Questions}
163
        What is \emph{buildroot-compatible package directory}?
164

  
165
        How big should I set for the size of the QEMU image? In \href{http://www.aurel32.net/info/debian_arm_qemu.php}{here} they set aside 10G for creating the image.
166

  
167
    \subsection{Technical Problems}
168
        \subsubsection{'build' folder for all output file from LaTeX with \emph{LaTeXTools}}
169
            So far I couldn't do it. I tried:
170
            \begin{itemize}
171
                \item Edit directly the simpleBuilder.py script, adding the option \texttt{"-output\_directory=./build"}. It shows error that *.log file cannot be written
172
                \item Change the \texttt{builder\_settings} \emph{Preferences -> Package Settings -> LaTeXTools -> Settings - User}
173
            \end{itemize}
174

  
175
            The solution now is to add extra line in \texttt{.gitignore} to not including the generated \emph{pdf} for each \emph{TeX} file.
176

  
177
        \subsubsection{Cannot compile package \texttt{sed}}
178
            Some line of errors from config.log
179
            \begin{lstlisting}
180
/home/quynh/Thesis/openwrt-bb/staging_dir/host/bin/
181
ccache_cc: 2: exec: ccache: not found
182
            \end{lstlisting}
183

  
184
            But I found the file ccache\_cc in that folder as shown below:
185
            \begin{lstlisting}
186
quynh in ~/Thesis/openwrt-bb/staging_dir/host/bin
187
$ ls | grep ccache
188
ccache_cc
189
ccache_cxx
190
            \end{lstlisting}
191

  
192
            Solution: sudo apt-get install ccache
193

  
194

  
195
    \subsection{Misc}
196
        [11:10 - 11:30] I'm doing shitty things now. Removing gcc-base, and as a result most packages are being removed: chrome, mozilla, gedit,  tortoise, skype, python, libqt4, networkmanager. Now I don't have the internet connection anymore.
latex/note_w03.tex
1
%!TEX root = note.tex
2

  
1 3
%%%%%%%%%%%%%%%%%%
2 4
% WEEK 3
3 5
%%%%%%%%%%%%%%%%%%
......
47 49
ELFFILE="openwrt-15.05-rc3-realview-vmlinux.elf"
48 50

  
49 51
# Boot with this command
50
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic
52

  
51 53
# Got error: end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
52 54

  
53 55
# In the website, there is another *.elf file
......
67 69
# Start OpenWrt instance
68 70
cd ~/Thesis/imagebuilder/OpenWrt-ImageBuilder-15.05-rc3-realview.Linux-x86_64/bin/realview
69 71
ELFFILE="openwrt-15.05-rc3-realview-vmlinux-initramfs.elf"
72
ELFFILE="openwrt-realview-vmlinux-initramfs.elf"
70 73
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic
71 74

  
72 75
# ELFFILE="openwrt-15.05-rc3-realview-vmlinux.elf" will created error
......
219 222

  
220 223

  
221 224

  
222

  
223

  
224

  
225

  
226

  
225
Prepare the C++ development for Linux Mint
latex/note_w04.tex
1
%!TEX root = note.tex
2

  
3
%%%%%%%%%%%%%%%%%%
4
% WEEK 4
5
%%%%%%%%%%%%%%%%%%
6
\section{Week 4}
7
    \subsection{Install package - nano - with dependency into OpenWrt Image}
8
        \href{http://wiki.openwrt.org/doc/devel/feeds}{Feeds}
9

  
10
        If we use \texttt{./scripts/feeds install -a -p packages}, then when issuing \texttt{make}, all the libraries, packages in the feed \texttt{packages} will be compiled. Don't use \texttt{-a}, since it might lead to error during \texttt{make}, and you do not need all those packages.
11

  
12
        \begin{lstlisting}
13
$ ./scripts/feeds install -p packages nano
14
Installing package 'nano'
15

  
16
# Press 'Y' to select to install package "nano" in make menuconfig: Utilities -> Editor
17

  
18
# Create config.diff so that we can create an image later with the exact same configuration
19
$ ./scripts/diffconfig.sh > config_10:47.diff
20

  
21
# Compile the toolchain to get SDK, ImageBuilder, and firmware image
22
$ make
23

  
24
# Running the image with QEMU
25
cd ./bin/realview
26
qemu-system-arm -M realview-eb-mpcore -kernel openwrt-realview-vmlinux-initramfs.elf -net nic -net user -nographic
27

  
28
# Show all the installed packages with this image
29
root@OpenWrt:/# opkg list-installed
30

  
31
        \end{lstlisting}
32

  
33
        This is the original installed packages
34

  
35
        \begin{lstlisting}
36
root@OpenWrt:/# opkg list-installed
37
base-files - 157-r47101
38
busybox - 1.23.2-1
39
dropbear - 2015.67-1
40
fstools - 2015-09-15-cc63723d886fde2cd364a545b7cb05b70721b83f
41
jshn - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
42
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
43
libblobmsg-json - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
44
libc - 0.9.33.2-1
45
libgcc - 4.8-linaro-1
46
libjson-c - 0.12-1
47
libjson-script - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
48
libnl-tiny - 0.1-4
49
libubox - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
50
libubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
51
libuci - 2015-08-27.1-1
52
mtd - 21
53
netifd - 2015-09-27-509ffb22475ebdd5291d510a098f996473951344
54
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-8
55
procd - 2015-09-16-b6618ffab8ed4981c57f53929276559698541462
56
terminfo - 5.9-2
57
ubox - 2015-07-14-907d046c8929fb74e5a3502a9498198695e62ad8
58
ubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
59
ubusd - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
60
uci - 2015-08-27.1-1
61
usign - 2015-05-08-cf8dcdb8a4e874c77f3e9a8e9b643e8c17b19131
62
        \end{lstlisting}
63

  
64
        This is all the packages we get when selecting nano
65

  
66
        \begin{lstlisting}
67
root@OpenWrt:/# opkg list-installed
68
base-files - 157-r47101
69
busybox - 1.23.2-1
70
dropbear - 2015.67-1
71
fstools - 2015-09-15-cc63723d886fde2cd364a545b7cb05b70721b83f
72
jshn - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
73
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
74
libblobmsg-json - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
75
libc - 0.9.33.2-1
76
libgcc - 4.8-linaro-1
77
libjson-c - 0.12-1
78
libjson-script - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
79
libncurses - 5.9-2 # This one is new
80
libnl-tiny - 0.1-4
81
libubox - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
82
libubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
83
libuci - 2015-08-27.1-1
84
mtd - 21
85
nano - 2.4.1-1 # This one is new
86
netifd - 2015-09-27-509ffb22475ebdd5291d510a098f996473951344
87
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-8
88
procd - 2015-09-16-b6618ffab8ed4981c57f53929276559698541462
89
terminfo - 5.9-2
90
ubox - 2015-07-14-907d046c8929fb74e5a3502a9498198695e62ad8
91
ubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
92
ubusd - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
93
uci - 2015-08-27.1-1
94
usign - 2015-05-08-cf8dcdb8a4e874c77f3e9a8e9b643e8c17b19131
95
        \end{lstlisting}
96

  
97
    \subsection{Boost library}
98

  
99
        Download \textbf{boost} library: \href{http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download}{here}
100

  
101
        \begin{lstlisting}
102
$ wget http://netix.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
103
$ tar -xf boost_1_59_0.tar.gz
104
$ rm tar -xf boost_1_59_0.tar.gz
105
$ cd boost_1_59_0/
106
        \end{lstlisting}
107

  
108
        Read \href{http://www.boost.org/doc/libs/1_59_0/more/getting_started/unix-variants.html}{Getting Started with Boost}
109

  
110
        The Boost Graph Library is a header-only library and does not need to be built to be used. The only exceptions are the GraphViz input parser and the GraphML parser. ==> Since I don't think OpenWrt will parse anyfile for GraphViz, so probably we do not need to build anything?!
111

  
112

  
113
    \subsection{Creating package from C++ code \& Installing it}
114
        \href{https://manoftoday.wordpress.com/2007/10/11/writing-and-compiling-a-simple-program-for-openwrt/}{Writing and Compiling A Simple Program For OpenWrt}
115

  
116
        \textbf{Package libboost is missing dependencies for the following libraries:libstdc++.so.6}
117

  
118
        https://forum.openwrt.org/viewtopic.php?id=5446
119

  
120
            You should link your executable against uclibc++
121

  
122
            Also remember to install the package: libstdcpp.
123

  
124
        \textbf{After having libboost.ipk, how to add to OpenWrt image with make menuconfig}
125
            \begin{lstlisting}
126
quynh in ~/Thesis/quynhnguyen-ms
127
$ TOOLCHAIN_DIR="/home/quynh/Thesis/cc-openwrt"
128
$ cp -r libboost $TOOLCHAIN_DIR/package/custom
129

  
130
quynh in ~/Thesis/cc-openwrt
131
$ make package/custom/libboost/compile
132

  
133
$ make menuconfig
134

  
135
# Then select the package libboost in Utilities
136

  
137
# Then, build a new image.
138
$ make
139
            \end{lstlisting}
140

  
141
        \textbf{Script to run after make menuconfig}
142

  
143
            This script will compile the OpenWrt toolchain, create SDK, and OpenWrt image with the necessary packages.
144

  
145
            \begin{lstlisting}
146
_description=$1
147
_separator="_"
148
_now="$(date +'%Y_%m_%d_%H_%M')"
149
_filename="$_now$_separator$_description"
150
./scripts/diffconfig.sh > config.diff
151
make
152
cd ./bin/realview
153
mkdir $_now
154
mv ../../config.diff ./
155
find . -maxdepth 1 -type f -name '*' -exec mv -n {} ./$_now \;
156
echo "All binary files are in ./bin/realview/$_now"
157
cd $_now
158
ELFFILE="openwrt-realview-vmlinux-initramfs.elf"
159
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic
160
            \end{lstlisting}
161

  
162

  
163
    \subsection{Add python-light to openwrt}
164
        The Python package can be found \href{https://github.com/openwrt/packages/blob/master/lang/python/Makefile}{here in github}
165

  
166

  
167
        How to add Python package to OpenWrt image?
168
        \begin{lstlisting}
169
./scripts/feeds install -p package python
170
# Select 'python-light' in Languages
171
make menuconfig
172

  
173
# To see if introducing python-light package will produce any error in compiling the OpenWrt toolchain
174
make package/python/compile
175

  
176
        \end{lstlisting}
177

  
178
    \subsection{Add python library networkx to OpenWrt}
179
        Create a simple program. Follow the similar guideline for \href{https://manoftoday.wordpress.com/2007/10/11/writing-and-compiling-a-simple-program-for-openwrt/}{Writing and Compiling A Simple Program For OpenWrt (C++)}. This guide also works with python.
180

  
181
        Save the file as \texttt{libnetworkx/src/libnetworkx.py}. This program will print all the functions in the library networkx.
182

  
183
        \begin{lstlisting}
184
#! python
185
import networkx
186

  
187
if __name__ == '__main__':
188
    print "Success"
189
    print dir(networkx)
190
        \end{lstlisting}
191

  
192
        The \texttt{libnetworkx/src/Makefile}
193

  
194
        \begin{lstlisting}
195
libnetworkx: libnetworkx.py
196
    ln -s libnetworkx.py libnetworkx
197
    chmod +x libnetworkx
198

  
199
clean:
200
    rm libnetworkx
201
        \end{lstlisting}
202

  
203
        Create a Makefile for OpenWrt in \texttt{libnetworkx/Makefile}
204

  
205
        After having all the files in place, then move them to the OpenWrt Toolchain. Compile the package, and select to install the package in make menuconfig. Compile the toolchain. Run the image with QEMU. Run the binary file \texttt{libnetworkx} to see whether the print command works.
206

  
207
        \textbf{Error: No module named networkx}
208

  
209
            How can we copy the whole module networkx and put it with the source
210
            \begin{lstlisting}
211
root@OpenWrt:/# libnetworkx
212
Traceback (most recent call last):
213
  File "/bin/libnetworkx", line 2, in <module>
214
    import networkx
215
ImportError: No module named networkx
216
            \end{lstlisting}
217

  
latex/note_w05.tex
1
%!TEX root = note.tex
2

  
3
%%%%%%%%%%%%%%%%%%
4
% WEEK 5
5
%%%%%%%%%%%%%%%%%%
6
\section{Week 5}
7
    \subsection{Install additional libraries for python}
8
        \begin{lstlisting}
9
$ make package/python-light/compile V=s
10
make[1]: Entering directory `/home/quynh/Thesis/cc-openwrt'
11
make[1]: *** No rule to make target `package/python-light/compile'.  Stop.
12
make[1]: Leaving directory `/home/quynh/Thesis/cc-openwrt'
13
make: *** [package/python-light/compile] Error 2
14

  
15
$ make package/python-light/install -p packages
16
no /build_dir/target/Python2.7 folder
17

  
18
$ make package/python -p packages
19
The same result as the command above
20
        \end{lstlisting}
21

  
22
        \textbf{ERROR:root:code for hash sha256 was not found.}
23
            Try to add \texttt{libopenssl} ==> It's not working
24

  
25
            Add both \texttt{+libopenssl +openssl-util} ==> Still get the same error
26

  
27
            Add \texttt{+python-openssl}. Since I saw that in \texttt{python-package-openssl.mk} there is a line:
28

  
29
            \begin{lstlisting}
30
/usr/lib/python$(PYTHON_VERSION)/lib-dynload/_hashlib.so
31
            \end{lstlisting}
32

  
33
            \texttt{python-openssl} solves the problem
34

  
35
        \textbf{How to check whether openssl is installed}
36

  
37
        \textbf{What to do when adding new dependencies in Makefile}
38

  
39
            Copy the new Makefile
40
            Run make defconfig
41
            The new dependencies will be added in the new configuration. You can check whether the new dependency was added by:
42

  
43
            \begin{lstlisting}
44
./scripts/diffconfig.sh > config.diff
45
cat config.diff
46
            \end{lstlisting}
47

  
48
            NOTE: when removing dependencies, running make defconfig doesn't automatically remove those libraries out of the configuration. So check again whether you need those library, and remove them by hand if needed.
49

  
50
        \textbf{What is the differences between openssl-util and libopenssl}
51

  
52
            From the \href{http://wiki.openwrt.org/doc/howto/http.mini-httpd}{tutorial for httpd}
53

  
54
        \textbf{How to remove library showing up in make menuconfig?}
55

  
56
            You only need to remove the package directory from the /package directory. Then when make menuconfig is executed, it will scan through the /package directory to find if there is any new/removed packages
57

  
58

  
59
        \textbf{ERROR: SyntaxError: encoding problem: utf8}
60

  
61
            Add dependency \texttt{python-codecs}
62
            Below is the error in more detail
63

  
64
            \begin{lstlisting}
65
Traceback (most recent call last):
66
  File "<stdin>", line 1, in <module>
67
  File "/usr/lib/python2.7/networkx/__init__.py", line 84, in <module>
68
    import networkx.generators
69
  File "/usr/lib/python2.7/networkx/generators/__init__.py", line 5, in <module>
70
    from networkx.generators.classic import *
71
  File "/usr/lib/python2.7/networkx/generators/classic.py", line 21, in <module>
72
    from networkx.algorithms.bipartite.generators import complete_bipartite_graph
73
  File "/usr/lib/python2.7/networkx/algorithms/__init__.py", line 4, in <module>
74
    from networkx.algorithms.centrality import *
75
  File "/usr/lib/python2.7/networkx/algorithms/centrality/__init__.py", line 1, in <module>
76
    from .betweenness import *
77
  File "/usr/lib/python2.7/networkx/algorithms/centrality/betweenness.py", line 1
78
SyntaxError: encoding problem: utf8
79
            \end{lstlisting}
80

  
81
        \textbf{ERROR: ImportError: No module named lib2to3.pgen2.parse}
82
            Do we even need the function read\_gml()
83

  
84
            \begin{lstlisting}
85
Traceback (most recent call last):
86
  File "<stdin>", line 1, in <module>
87
  File "/usr/lib/python2.7/networkx/__init__.py", line 87, in <module>
88
    import networkx.readwrite
89
  File "/usr/lib/python2.7/networkx/readwrite/__init__.py", line 14, in <module>
90
    from networkx.readwrite.gml import *
91
  File "/usr/lib/python2.7/networkx/readwrite/gml.py", line 44, in <module>
92
    from lib2to3.pgen2.parse import ParseError
93
ImportError: No module named lib2to3.pgen2.parse
94
            \end{lstlisting}
95

  
96
    \subsection{Install only few files in networkx needed for the project}
97

  
98
        \begin{lstlisting}
99
>>> from networkx.algorithms.centrality import *
100
Traceback (most recent call last):
101
  File "<stdin>", line 1, in <module>
102
  File "/usr/lib/python2.7/networkx/__init__.py", line 87, in <module>
103
    import networkx.readwrite
104
  File "/usr/lib/python2.7/networkx/readwrite/__init__.py", line 14, in <module>
105
    from networkx.readwrite.gml import *
106
  File "/usr/lib/python2.7/networkx/readwrite/gml.py", line 44, in <module>
107
    from lib2to3.pgen2.parse import ParseError
108
ImportError: No module named lib2to3.pgen2.parse
109

  
110
>>> from networkx.algorithms.centrality import betweenness
111
Traceback (most recent call last):
112
  File "<stdin>", line 1, in <module>
113
  File "/usr/lib/python2.7/networkx/__init__.py", line 43, in <module>
114
    from networkx import release
115
ImportError: cannot import name release
116

  
117
        \end{lstlisting}
118

  
119
        The python2.7 package is dependent to the libssl package (openssl runtime librairies).
120

  
121
        Questions
122

  
123
        ? When is the Python2.7 folder got generated
124

  
125
        Much simpler solution. I can simply choose to include the logging module in [make menuconfig]
126

  
127
        \textbf{Oct 21, 2015} Leonardo said that we can just drop the attempt with networkx, it's not worth the effort.
128

  
129
    \subsection{Prepartion for Hello World program}
130
        \subsubsection{How templates work in C++}
131

  
132
            From the \href{https://www.sgi.com/tech/stl/stl_introduction.html}{Introduction to the Standard Template Library}
133

  
134
        \subsubsection{What is dynamic linking that Leonardo talked about?}
135

  
136
        \subsubsection{pointer for dummy}
137
            \lstinline{&} = address operator
138

  
139
            \lstinline{*} = reference operator. \lstinline{*(1000) = Value at address 1000}
140

  
141
            A pointer must know how big the house it is pointing to. So if paul is an int, only an int pointer can point to it. If paul is a float, then only a float pointer can point to it, and so on.
142

  
143

  
144
            \begin{lstlisting}
145

  
146
            \end{lstlisting}
147

  
148
            \lstinline{int *melissa} = creating a pointer melissa
149

  
150
            \lstinline{int* melissa} = another way to create a pointer melissa. In the "Thinking in C++", pointer is created using this form.
151

  
152
            \lstinline{int * melissa} = another way to create a pointer melissa.
153

  
154
            \lstinline{int **ramon} = pointer to a pointer
155

  
156
            A \textbf{string} in C is simply a pointer to a char that has the convention of being the start of a sequence of characters that ends in '\textbackslash0'.
157

  
158
            \href{http://www.c4learn.com/c-programming/c-pointer-to-array-of-string/}{c4learn} website is a useful tutorial.
159

  
160
            \begin{lstlisting}
161
char *path[] // an array of pointers
162
char *path // a single pointer
163
char *path = "ABCD" //
164
            \end{lstlisting}
165

  
166
            \textbf{Question related to pointer}
167

  
168
            \begin{lstlisting}
169
# int arr[] = {7, 11, 13};
170
arr =       0x7ffc71ca1f90
171
&(*arr)) =  0x7ffc71ca1f90
172
&arr =      0x7ffc71ca1f90
173
&arr = 140722217557904
174
??? why why why, plusing with 4, resulting in plusing with 16 ???
175
sizeof(int) = 4
176
arr + sizeof(int) = 140722217557920
177
arr + 2*sizeof(int) = 140722217557936
178
//
179
&arr + sizeof(int) = 140722217557952
180
arr + 4 = 140722217557920
181
arr + 8 = 140722217557936
182
&arr[1] = 0x7ffc71ca1f94
183
*(&arr[1]) = 11
184
arr[1] = 11
185

  
186
# char char_arr[] = {'x', 'u', 'a', 'n', '
187
char_arr = xuan
188
*char_arr = x
189
&char_arr = 0x7ffc71ca1fa0
190
&(*char_arr) = xuan
191
??? Why char_arr is printed out completely, why arr only print number 10???
192
            \end{lstlisting}
193

  
194

  
195
        \subsubsection{Passing a pointer vs Pass-by-reference (PBR)}
196
            \begin{lstlisting}
197
// Passing a poitner to a function
198
void f(int* p) {
199
    cout << p; // 0065FE00
200
    cout << *p; // 16
201
    *p = 5;
202
    cout << *p; // 5
203
}
204

  
205
int main() {
206
    int x = 16;
207
    f(&x)
208
}
209
            \end{lstlisting}
210

  
211
            Calling a function that take a reference is cleaner
212

  
213
            Assigning to \texttt{r} is the same as assigning to the variable that \texttt{r} \emph{references}
214

  
215
            \begin{lstlisting}
216
// Pass-by-reference
217
void f(int& r) {
218
    cout << r; // 16
219
    cout << &r; // 0065FE00
220
    r = 5;
221
    cout << p; // 5
222
}
223

  
224
int main() {
225
    int x = 16;
226
    f(x)
227
}
228
            \end{lstlisting}
229

  
230

  
231
    \subsection{Write a Hello World program for Boost Graph Library}
232

  
233
        Reading \href{http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/quick_tour.html}{Graph Doc Quick Tour}
234

  
235
        \subsubsection{Notation}
236
            \textbf{STL} = Standard Template Library
latex/note_w06.tex
1
%!TEX root = note.tex
2

  
3
%%%%%%%%%%%%%%%%%%
4
% WEEK 6
5
%%%%%%%%%%%%%%%%%%
6
\section{Week 6}
7
    \subsection{Install Boost into OpenWRT Image}
8

  
9
        There were some error related to no *.so found in the \texttt{build\_dir}. I do not know why.
10

  
11
        But after I choose specific Boost library to install, including the \texttt{graph}, then the error got resolved. Is it due to the fact that  the \texttt{graph} also include the *.cpp file, and those implementation file then get compiled into the \texttt{shared objects *.so}.
12

  
13
        \begin{lstlisting}
14
./scripts/feeds install boost
15
make menuconfig
16
# choose boost in libraries
17

  
18
# Verify whether we can compile & install Boost successfully
19
make package/boost/compile
20
make package/boost/install
21

  
22
# compile to get the OpenWrt Image
23
        \end{lstlisting}
24

  
25
    \subsection{Makefile}
26
        Below is some general note about Makefile.
27

  
28
        http://stackoverflow.com/questions/9688200/difference-between-shared-objects-so-static-libraries-a-and-dlls-so
29

  
30
        http://stackoverflow.com/questions/8229620/why-does-the-c-boost-package-only-contain-hpp-files
31

  
32
        what is boost-build.jam
33

  
34

  
35
        https://www.gnu.org/software/make/manual/html\_node/Call-Function.html
36

  
37
        http://www.tutorialspoint.com/makefile/makefile\_quick\_guide.htm
38

  
39

  
40
        The \$(INSTALL\_DIR) variable contains a command to prepare the install \# directory if it does not already exist. Likewise \$(INSTALL\_BIN) contains the \# command to copy the binary file from its current location (in our case the build \# directory) to the install directory.
41

  
42

  
43
        http://gargoyle-router.com/old-openwrt-coding.html\#part2
44

  
45
        Detailed instruction with explanation on what Makefile, and OpenWrt Makefile do during compilation. With example that use STL library, and porting STL to the OpenWrt Image. This example is the step-by-step approach, it shows you also the non-functioning example, and then it shows you how to make it work. Any modification is explained in deep.
46

  
47

  
48
        Variable and function references in recipes have identical syntax and semantics to references elsewhere in the makefile. They also have the same quoting rules: if you want a dollar sign to appear in your recipe, you must double it (‘\$\$’). For shells like the default shell, that use dollar signs to introduce variables, it’s important to keep clear in your mind whether the variable you want to reference is a make variable (use a single dollar sign) or a shell variable (use two dollar signs)
49

  
50
        \begin{lstlisting}
51
LIST = one two three
52
all:
53
        for i in $(LIST); do \
54
            echo $$i; \
55
        done
56

  
57
# results in the following command being passed to the shell:
58

  
59
for i in one two three; do \
60
    echo $i; \
61
done
62

  
63

  
64
# which generates the expected result:
65

  
66
one
67
two
68
        \end{lstlisting}
69

  
70
    \subsection{Boost Graph Library (BGL)}
71
        \href{http://stackoverflow.com/a/31734150}{Using Boost Graph Library}: this comment is really helpful. It's not giving an example, but it provides
72

  
73
    \subsection{Summary - Week 6}
74
        Read book about STL, Template. Making notes on paper
75

  
latex/note_w07.tex
1
%!TEX root = note.tex
2

  
3
%%%%%%%%%%%%%%%%%%
4
% WEEK 7
5
%%%%%%%%%%%%%%%%%%
6
\section{Week 7}
7
    \subsection{Figuring out boost/lambda}
8
        \subsubsection{Test to make sure that boost/lambda header file is not included in the firmware image}
9

  
10
            \begin{tabular}{l|l|l|l}
11
                Order & Select boost in menuconfig & DEPENDS:= +boost & Result \\
12
                1 & Yes & Yes & Yes \\
13
                2 & Yes & No & Yes | No \\
14
                3 & No & Yes & Yes \\
15
                4 & No & No & No \\
16
            \end{tabular}
17

  
18
            \textbf{STAGING\_DIR}
19

  
20
            Note that in the case No. 2, if we have \lstinline{/home/quynh/Thesis/cc-openwrt/staging_dir/target-arm_mpcore+vfp_uClibc-0.9.33.2_eabi/usr/include/boost/lambda/lambda.hpp}, then the header file from Boost library is still included in compilation process
21

  
22
            The staging directory is where both target and host development files are stored. Libraries and headers that are required for package compilation are stored there (as well as the toolchain). The build system includes \$STAGING\_DIR during the build process, and links against libraries stored in there. \footnote{https://forum.openwrt.org/viewtopic.php?id=47448}
23

  
24
            We can clean the \lstinline{staging\_dir} and \lstinline{build\_dir} with \lstinline{make dirclean}.
25

  
26
            After \lstinline{dirclean}, then we cannot run \lstinline{make package/hello-boost-lambda/compile V=s}
27

  
28
            \begin{lstlisting}
29
$ make package/hello-boost-lambda/compile V=s
30
make[1]: Entering directory `/home/quynh/Thesis/cc-openwrt'
31
make[2]: Entering directory `/home/quynh/Thesis/cc-openwrt/package/libs/toolchain'
32
mkdir -p /home/quynh/Thesis/cc-openwrt/build_dir/target-arm_mpcore+vfp_uClibc-0.9.33.2_eabi/toolchain
33
touch /home/quynh/Thesis/cc-openwrt/build_dir/target-arm_mpcore+vfp_uClibc-0.9.33.2_eabi/toolchain/.prepared_d3923b47dd5ae45263460d1c2269b9ea
34
rm -f /home/quynh/Thesis/cc-openwrt/staging_dir/target-arm_mpcore+vfp_uClibc-0.9.33.2_eabi/stamp/.toolchain_installed
35
....
36
cp: cannot stat '/home/quynh/Thesis/cc-openwrt/staging_dir/toolchain-arm_mpcore+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/lib/libuClibc-*.so': No such file or directory
37
cp: cannot stat '/home/quynh/Thesis/cc-openwrt/staging_dir/toolchain-arm_mpcore+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/lib/libcrypt-*.so': No such file or directory
38
cp: cannot stat '/home/quynh/Thesis/cc-openwrt/staging_dir/toolchain-arm_mpcore+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/lib/libm-*.so': No such file or directory
39
cp: cannot stat '/home/quynh/Thesis/cc-openwrt/staging_dir/toolchain-arm_mpcore+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/lib/libpthread-*.so': No such file or directory
40
make[2]: *** [/home/quynh/Thesis/cc-openwrt/build_dir/target-arm_mpcore+vfp_uClibc-0.9.33.2_eabi/toolchain/.built] Error 1
41
make[2]: Leaving directory `/home/quynh/Thesis/cc-openwrt/package/libs/toolchain'
42
make[1]: *** [package/libs/toolchain/compile] Error 2
43
make[1]: Leaving directory `/home/quynh/Thesis/cc-openwrt'
44
make: *** [package/hello-boost-lambda/compile] Error 2
45
            \end{lstlisting}
46

  
47

  
48
    \subsection{MAKE command}
49
        \lstinline{package/compile} or \lstinline{package compile}. I guess it has to do with this one:
50

  
51
        \lstinline{-C dir, --directory=dir}
52

  
53
        Change  to directory dir before reading the makefiles or doing anything else. If multiple -C options are specified, each  is  interpreted  relative  to the previous one: -C / -C etc is equivalent to -C /etc.  This is typically  used  with  recursive  invocations  of make.
54

  
55
        So the correct version is \lstinline{make package/boost/compile}
56

  
57
        \begin{lstlisting}
58
make package/boost/c lean V=s
59

  
60
$ make -C package/custom/hello-boost-lambda compile
61
make: Entering directory `/home/quynh/Thesis/cc-openwrt/package/custom/hello-boost-lambda'
62
Makefile:19: /rules.mk: No such file or directory
63
Makefile:31: /package.mk: No such file or directory
64
make: *** No rule to make target `/package.mk'.  Stop.
65
make: Leaving directory `/home/quynh/Thesis/cc-openwrt/package/custom/hello-boost-lambda'
66

  
67

  
68
$ make package/custom/hello-boost-lambda/compile V=s
69
...
70
hello-boost-lambda.cpp:3:35: fatal error: boost/lambda/lambda.hpp: No such file or directory
71
 #include <boost/lambda/lambda.hpp>
72
                                   ^
73
compilation terminated.
74
make[3]: *** [hello-boost-lambda.o] Error 1
75
make[3]: Leaving directory `/home/quynh/Thesis/cc-openwrt/build_dir/target-arm_mpcore+vfp_uClibc-0.9.33.2_eabi/hello-boost-lambda'
76
make[2]: *** [/home/quynh/Thesis/cc-openwrt/build_dir/target-arm_mpcore+vfp_uClibc-0.9.33.2_eabi/hello-boost-lambda/.built] Error 2
77
make[2]: Leaving directory `/home/quynh/Thesis/cc-openwrt/package/custom/hello-boost-lambda'
78
make[1]: *** [package/custom/hello-boost-lambda/compile] Error 2
79
make[1]: Leaving directory `/home/quynh/Thesis/cc-openwrt'
80
make: *** [package/custom/hello-boost-lambda/compile] Error 2
81

  
82

  
83
$ make package/custom/hello-boost-lambda compile V=s
84
make: `package/custom/hello-boost-lambda' is up to date.
85
make[1]: Entering directory `/home/quynh/Thesis/cc-openwrt'
86
make[1]: *** No rule to make target `compile'.  Stop.
87
make[1]: Leaving directory `/home/quynh/Thesis/cc-openwrt'
88
make: *** [compile] Error 2
89
        \end{lstlisting}
90

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff