Statistics
| Branch: | Revision:

root / latex / note_w03.tex @ d5a1a059

History | View | Annotate | Download (11.2 KB)

1 d5a1a059 Quynh PX Nguyen
%%%%%%%%%%%%%%%%%%
2
% WEEK 3
3
%%%%%%%%%%%%%%%%%%
4
\section{Week 3}
5
    Read \href{http://www.ccs.neu.edu/home/noubir/Courses/CS6710/S12/material/OpenWrt_Dev_Tutorial.pdf}{OpenWrt Dev Tutorial}
6
7
    Read \href{http://landley.net/aboriginal/presentation.html#cross_advantages}{Developing for non-x86 targets using QEMU}
8
9
    \href{http://wiki.prplfoundation.org/wiki/Building_OpenWrt}{Bilding OpenWrt}: screenshots, and detaield instruction on how to build OpenWrt image, and how to run that image with Qemu
10
11
    \subsection{QEMU Manual}
12
        \subsubsection{Definitions}
13
            \textbf{QEMU} = QEMU is a generic and open source machine emulator and virtualizer. QEMU has the advantage of being able to run either as a pure emulator or as a native virtual machine. \footnote{http://wiki.qemu.org/Main\_Page}
14
            \begin{itemize}
15
                \item When used as a machine emulator, QEMU can run OSes and programs made for one machine (e.g. an ARM board) on a different machine (e.g. your own PC). By using dynamic translation, it achieves very good performance.
16
17
                \item When used as a virtualizer, QEMU achieves near native performances by executing the guest code directly on the host CPU. QEMU supports virtualization when executing under the Xen hypervisor or using the KVM kernel module in Linux. When using KVM, QEMU can virtualize x86, server and embedded PowerPC, and S390 guests.
18
            \end{itemize}
19
20
            \textbf{Emulator} = a hardware or software that enables one computer system (called the host) to behave like another computer system (called the guest). An emulator typically enables the host system to run software or use peripheral devices designed for the guest system. \footnote{https://en.wikipedia.org/wiki/Emulator}
21
22
            \textbf{Virtualizer (or virtualization machine)} allows an unmodified operating system with all of its installed software to run in a special environment, on top of your existing operating system. This environment, called a "virtual machine", is created by the virtualization software by intercepting access to certain hardware components and certain features. The physical computer is then usually called the "host", while the virtual machine is often called a "guest". Most of the guest code runs unmodified, directly on the host computer, and the guest operating system "thinks" it's running on real machine. \footnote{https://www.virtualbox.org/wiki/Virtualization}
23
24
            \textbf{Peripheral devices} are defined as a computer device, such as a keyboard or printer, that is not part of the essential computer (i.e., the memory and microprocessor). These auxiliary devices are intended to be connected to the computer and used.
25
26
            \textbf{Cross Compiler} is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. For example, a compiler that runs on a Windows 7 PC but generates code that runs on Android smartphone is a cross compiler
27
28
            \textbf{Realview} = this platform is intended to be used with Qemu (realview-eb-mpcore machine).
29
30
        \subsubsection{Questions on QEMU}
31
            \textbf{What is the difference between \texttt{qemu-arm} vs \texttt{qemu-system-arm}}
32
33
                The first is used to execute ARM binary files, and the second to boot the ARM OS. \footnote{http://opensourceforu.efytimes.com/2011/06/qemu-for-embedded-systems-development-part-1/}
34
35
36
    \subsection{Load realview target with QEMU}
37
        \begin{lstlisting}
38
FILENAME="OpenWrt-ImageBuilder-15.05-rc3-realview.Linux-x86_64"
39
40
wget "https://downloads.openwrt.org/chaos_calmer/15.05-rc3/realview/generic/$FILENAME.tar.bz2"
41
tar -xvjf $FILENAME.tar.bz2
42
rm $FILENAME.tar.bz2
43
cd $FILENAME
44
45
46
cd ./bin/realview
47
ELFFILE="openwrt-15.05-rc3-realview-vmlinux.elf"
48
49
# Boot with this command
50
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic
51
# Got error: end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
52
53
# In the website, there is another *.elf file
54
# With this one, the kernel is boot successfully.
55
wget https://downloads.openwrt.org/chaos_calmer/15.05-rc3/realview/generic/openwrt-15.05-rc3-realview-vmlinux-initramfs.elf
56
57
58
        \end{lstlisting}
59
60
    \subsection{OpenWrt under QEMU}
61
    https://grenville.wordpress.com/2013/01/06/openwrt-under-qemu-on-freebsd/
62
63
    \subsection{Transfering files between host and QEMU instance}
64
    \href{http://www.cnx-software.com/2011/10/02/how-to-transfer-files-between-host-and-qemu-via-ssh-and-nfs/}{OpenWRT under Qemu on FreeBSD}: screenshots and commands with an overview on how to build Realview image of OpenWrt and run it under Qemu.
65
66
        \begin{lstlisting}
67
# Start OpenWrt instance
68
cd ~/Thesis/imagebuilder/OpenWrt-ImageBuilder-15.05-rc3-realview.Linux-x86_64/bin/realview
69
ELFFILE="openwrt-15.05-rc3-realview-vmlinux-initramfs.elf"
70
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic
71
72
# ELFFILE="openwrt-15.05-rc3-realview-vmlinux.elf" will created error
73
# Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
74
75
# Try to boot with ext4
76
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic -sd openwrt-realview-sdcard.img
77
78
# From ifconfig - vmnet1 - this one DOES NOT WORK
79
ssh -p 2222 quynh@192.168.52.1
80
# From ifconfig - vmnet8
81
ssh -p 2222 quynh@192.168.166.1
82
# This one allow to access the host file system
83
ssh quynh@192.168.166.1
84
# Copy file from host to QEMU
85
scp quynh@192.168.166.1:~/sed_4.2.1-1_realview.ipk ~/sed.ipk
86
        \end{lstlisting}
87
88
    \subsection{Install package on the running OpenWRT instance on QEMU}
89
        Read page 11 on \href{http://www.ccs.neu.edu/home/noubir/Courses/CS6710/S12/material/OpenWrt_Dev_Tutorial.pdf}{OpenWrt Dev Tutorial from NEU}
90
91
        \begin{lstlisting}
92
# Download the precompiled SDK
93
FILENAME="OpenWrt-SDK-15.05-realview_gcc-4.8-linaro_uClibc-0.9.33.2_eabi.Linux-x86_64"
94
wget "https://downloads.openwrt.org/chaos_calmer/15.05/realview/generic/$FILENAME.tar.bz2"
95
tar -xvjf $FILENAME.tar.bz2
96
rm $FILENAME.tar.bz2
97
cd $FILENAME
98
99
# Download package 'sed' and compile it
100
svn export svn://svn.openwrt.org/openwrt/packages/utils/sed package/sed
101
grep DEPENDS package/sed/Makefile
102
make package/sed/compile
103
104
# Transfer the compiled package 'sed' to running instance OpenWrt
105
# From the root@OpenWrt console
106
scp quynh@192.168.166.1:~/sed_4.2.1-1_realview.ipk ~/sed.ipk
107
108
# Install the ipk
109
opkg install ~/sed.ipk
110
        \end{lstlisting}
111
112
        \textbf{Problem: Only have 0kb available on filesystem /overlay, pkg sed needs 48}
113
114
            https://forum.openwrt.org/viewtopic.php?id=58545
115
116
            I tried to boot with \emph{image}, but the problem is still there
117
            \begin{lstlisting}
118
EFLFILE="openwrt-15.05-ar71xx-generic-vmlinux.elf"
119
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic -sd openwrt-realview-sdcard.img
120
            \end{lstlisting}
121
122
            Some reasons:
123
            \begin{itemize}
124
                \item However (as far as I understand), the image is mounted as an overlay image which (for what I could gather on the web) means it's readonly, and therefore, I can't install new packages.\footnote{https://forum.openwrt.org/viewtopic.php?id=58545}
125
126
                \item You are running a read only image, you need to add an overlay filesystem over that you that you can have full read and write functions. \footnote{https://forum.openwrt.org/viewtopic.php?id=56891}
127
128
                \item If I want to store something on my target I do this on some other mounted media (usually flash). Others might write the image into the devices flash and allow changes to be saved into flash. \footnote{http://buildroot.uclibc.narkive.com/pp4A78C6/creating-a-filesystem-for-real-time-linux-using-qemu}
129
            \end{itemize}
130
131
        \textbf{Qemu + overlay}
132
133
        \textbf{SD card image and Qemu}
134
            \href{https://en.wikibooks.org/wiki/QEMU/Images#Creating_an_image}{Creating an image - Wikibooks}
135
136
            \begin{lstlisting}
137
qemu-img create -f qcow2 sdcard.img 500M
138
139
140
qemu-system-arm -M realview-eb-mpcore -kernel openwrt-15.05-rc3-realview-vmlinux-initramfs.elf \
141
-nographic -m 1024M \
142
-sd sdcard.img \
143
--append "console=ttyAMA0 verbose debug root=/dev/mmcblk0p1"
144
145
            \end{lstlisting}
146
147
        \textbf{Test: Build an image with additional package}
148
            By this way, we do not need to install additional package with a running instance of OpenWrt
149
150
            Where is the Profiles.mk
151
152
            \begin{lstlisting}
153
# OpenWrt on Qemu with the default image for Realview Target
154
root@OpenWrt:/# fdisk
155
/bin/ash: fdisk: not found
156
157
# OpenWrt on Qemu with the image + fdisk package
158
# Inside the ImageBuilder folder
159
160
make image PACKAGES="fdisk"
161
162
            \end{lstlisting}
163
164
        \textbf{Generate openwrt-15.05-rc3-realview-vmlinux-initramfs.elf}
165
            The current Image Builder only generate openwrt-15.05-rc3-realview-vmlinux.elf, and not openwrt-15.05-rc3-realview-vmlinux-initramfs.elf
166
167
            Some similar forum threads:
168
            \begin{itemize}
169
                \item \footnote{https://forum.openwrt.org/viewtopic.php?id=53931}
170
            \end{itemize}
171
172
        \textbf{Recompile the OpenWrt toolchain to obtain openwrt-15.05-rc3-realview-vmlinux-initramfs.elf}
173
            By selecting the package that I want to include from $make menuconfig$, then that additional package will be available in the \texttt{initranfs.elf} file.
174
175
        \textbf{Add additional package to the compiled toolchain}
176
            Ways to do:
177
            \begin{itemize}
178
                \item Select the package/library from make menuconfig
179
                \item Use the $scripts/diffconfig.sh$ to generate \texttt{config.diff} file. Append the \texttt{config.diff} to the original \texttt{<build dir>/.config}. Then $make defconfig$ will generate the full \texttt{.config} file.
180
                \item Check out guideline on \href{http://wiki.openwrt.org/doc/howto/build}{Updating Feeds section}
181
            \end{itemize}
182
183
            Why does not the "Update Feeds" have \texttt{base} as in repo of \href{https://downloads.openwrt.org/chaos_calmer/15.05-rc3/realview/generic/packages/}{realview/generic/packages}
184
185
            Where is \texttt{feeds.conf}
186
187
            \begin{lstlisting}
188
quynh in ~/Thesis/cc-openwrt
189
$ ./scripts/feeds usage
190
$ ./scripts/feeds list -n
191
packages
192
luci
193
routing
194
telephony
195
management
196
quynh in ~/Thesis/cc-openwrt
197
$ ./scripts/feeds list -s
198
packages src-git  7f3ef93  https://github.com/openwrt/packages.git;for-15.05
199
luci     src-git  af9f093  https://github.com/openwrt/luci.git;for-15.05
200
routing  src-git  5876cd3  https://github.com/openwrt-routing/packages.git;for-15.05
201
telephony src-git  d4ca5e5  https://github.com/openwrt/telephony.git;for-15.05
202
management src-git  ab76d57  https://github.com/openwrt-management/packages.git;for-15.05
203
204
            \end{lstlisting}
205
206
        \textbf{Save the configuration information}
207
            \href{http://wiki.openwrt.org/doc/howto/build}{Read more in the official document - How to Build}
208
209
            \begin{lstlisting}
210
# In folder openwrt-cc
211
# After selecting all the changes in make menuconfig
212
213
# Export the diffconfig to file
214
./scripts/diffconfig.sh > diffconfig
215
            \end{lstlisting}
216
217
        \textbf{How to 'make' without re-compiling}
218
219
220
221
222
223
224
225