Statistics
| Branch: | Revision:

root / latex / note_w03.tex @ 4f432e4a

History | View | Annotate | Download (11.2 KB)

1 d1ed66aa Quynh PX Nguyen
%!TEX root = note.tex
2
3 d5a1a059 Quynh PX Nguyen
%%%%%%%%%%%%%%%%%%
4
% WEEK 3
5
%%%%%%%%%%%%%%%%%%
6
\section{Week 3}
7
    Read \href{http://www.ccs.neu.edu/home/noubir/Courses/CS6710/S12/material/OpenWrt_Dev_Tutorial.pdf}{OpenWrt Dev Tutorial}
8
9
    Read \href{http://landley.net/aboriginal/presentation.html#cross_advantages}{Developing for non-x86 targets using QEMU}
10
11
    \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
12
13
    \subsection{QEMU Manual}
14
        \subsubsection{Definitions}
15
            \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}
16
            \begin{itemize}
17
                \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.
18
19
                \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.
20
            \end{itemize}
21
22
            \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}
23
24
            \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}
25
26
            \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.
27
28
            \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
29
30
            \textbf{Realview} = this platform is intended to be used with Qemu (realview-eb-mpcore machine).
31
32
        \subsubsection{Questions on QEMU}
33
            \textbf{What is the difference between \texttt{qemu-arm} vs \texttt{qemu-system-arm}}
34
35
                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/}
36
37
38
    \subsection{Load realview target with QEMU}
39
        \begin{lstlisting}
40
FILENAME="OpenWrt-ImageBuilder-15.05-rc3-realview.Linux-x86_64"
41
42
wget "https://downloads.openwrt.org/chaos_calmer/15.05-rc3/realview/generic/$FILENAME.tar.bz2"
43
tar -xvjf $FILENAME.tar.bz2
44
rm $FILENAME.tar.bz2
45
cd $FILENAME
46
47
48
cd ./bin/realview
49
ELFFILE="openwrt-15.05-rc3-realview-vmlinux.elf"
50
51
# Boot with this command
52 d1ed66aa Quynh PX Nguyen
53 d5a1a059 Quynh PX Nguyen
# Got error: end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
54
55
# In the website, there is another *.elf file
56
# With this one, the kernel is boot successfully.
57
wget https://downloads.openwrt.org/chaos_calmer/15.05-rc3/realview/generic/openwrt-15.05-rc3-realview-vmlinux-initramfs.elf
58
59
60
        \end{lstlisting}
61
62
    \subsection{OpenWrt under QEMU}
63
    https://grenville.wordpress.com/2013/01/06/openwrt-under-qemu-on-freebsd/
64
65
    \subsection{Transfering files between host and QEMU instance}
66
    \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.
67
68
        \begin{lstlisting}
69
# Start OpenWrt instance
70
cd ~/Thesis/imagebuilder/OpenWrt-ImageBuilder-15.05-rc3-realview.Linux-x86_64/bin/realview
71
ELFFILE="openwrt-15.05-rc3-realview-vmlinux-initramfs.elf"
72 d1ed66aa Quynh PX Nguyen
ELFFILE="openwrt-realview-vmlinux-initramfs.elf"
73 d5a1a059 Quynh PX Nguyen
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic
74
75
# ELFFILE="openwrt-15.05-rc3-realview-vmlinux.elf" will created error
76
# Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
77
78
# Try to boot with ext4
79
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic -sd openwrt-realview-sdcard.img
80
81
# From ifconfig - vmnet1 - this one DOES NOT WORK
82
ssh -p 2222 quynh@192.168.52.1
83
# From ifconfig - vmnet8
84
ssh -p 2222 quynh@192.168.166.1
85
# This one allow to access the host file system
86
ssh quynh@192.168.166.1
87
# Copy file from host to QEMU
88
scp quynh@192.168.166.1:~/sed_4.2.1-1_realview.ipk ~/sed.ipk
89
        \end{lstlisting}
90
91
    \subsection{Install package on the running OpenWRT instance on QEMU}
92
        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}
93
94
        \begin{lstlisting}
95
# Download the precompiled SDK
96
FILENAME="OpenWrt-SDK-15.05-realview_gcc-4.8-linaro_uClibc-0.9.33.2_eabi.Linux-x86_64"
97
wget "https://downloads.openwrt.org/chaos_calmer/15.05/realview/generic/$FILENAME.tar.bz2"
98
tar -xvjf $FILENAME.tar.bz2
99
rm $FILENAME.tar.bz2
100
cd $FILENAME
101
102
# Download package 'sed' and compile it
103
svn export svn://svn.openwrt.org/openwrt/packages/utils/sed package/sed
104
grep DEPENDS package/sed/Makefile
105
make package/sed/compile
106
107
# Transfer the compiled package 'sed' to running instance OpenWrt
108
# From the root@OpenWrt console
109
scp quynh@192.168.166.1:~/sed_4.2.1-1_realview.ipk ~/sed.ipk
110
111
# Install the ipk
112
opkg install ~/sed.ipk
113
        \end{lstlisting}
114
115
        \textbf{Problem: Only have 0kb available on filesystem /overlay, pkg sed needs 48}
116
117
            https://forum.openwrt.org/viewtopic.php?id=58545
118
119
            I tried to boot with \emph{image}, but the problem is still there
120
            \begin{lstlisting}
121
EFLFILE="openwrt-15.05-ar71xx-generic-vmlinux.elf"
122
qemu-system-arm -M realview-eb-mpcore -kernel $ELFFILE -net nic -net user -nographic -sd openwrt-realview-sdcard.img
123
            \end{lstlisting}
124
125
            Some reasons:
126
            \begin{itemize}
127
                \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}
128
129
                \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}
130
131
                \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}
132
            \end{itemize}
133
134
        \textbf{Qemu + overlay}
135
136
        \textbf{SD card image and Qemu}
137
            \href{https://en.wikibooks.org/wiki/QEMU/Images#Creating_an_image}{Creating an image - Wikibooks}
138
139
            \begin{lstlisting}
140
qemu-img create -f qcow2 sdcard.img 500M
141
142
143
qemu-system-arm -M realview-eb-mpcore -kernel openwrt-15.05-rc3-realview-vmlinux-initramfs.elf \
144
-nographic -m 1024M \
145
-sd sdcard.img \
146
--append "console=ttyAMA0 verbose debug root=/dev/mmcblk0p1"
147
148
            \end{lstlisting}
149
150
        \textbf{Test: Build an image with additional package}
151
            By this way, we do not need to install additional package with a running instance of OpenWrt
152
153
            Where is the Profiles.mk
154
155
            \begin{lstlisting}
156
# OpenWrt on Qemu with the default image for Realview Target
157
root@OpenWrt:/# fdisk
158
/bin/ash: fdisk: not found
159
160
# OpenWrt on Qemu with the image + fdisk package
161
# Inside the ImageBuilder folder
162
163
make image PACKAGES="fdisk"
164
165
            \end{lstlisting}
166
167
        \textbf{Generate openwrt-15.05-rc3-realview-vmlinux-initramfs.elf}
168
            The current Image Builder only generate openwrt-15.05-rc3-realview-vmlinux.elf, and not openwrt-15.05-rc3-realview-vmlinux-initramfs.elf
169
170
            Some similar forum threads:
171
            \begin{itemize}
172
                \item \footnote{https://forum.openwrt.org/viewtopic.php?id=53931}
173
            \end{itemize}
174
175
        \textbf{Recompile the OpenWrt toolchain to obtain openwrt-15.05-rc3-realview-vmlinux-initramfs.elf}
176
            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.
177
178
        \textbf{Add additional package to the compiled toolchain}
179
            Ways to do:
180
            \begin{itemize}
181
                \item Select the package/library from make menuconfig
182
                \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.
183
                \item Check out guideline on \href{http://wiki.openwrt.org/doc/howto/build}{Updating Feeds section}
184
            \end{itemize}
185
186
            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}
187
188
            Where is \texttt{feeds.conf}
189
190
            \begin{lstlisting}
191
quynh in ~/Thesis/cc-openwrt
192
$ ./scripts/feeds usage
193
$ ./scripts/feeds list -n
194
packages
195
luci
196
routing
197
telephony
198
management
199
quynh in ~/Thesis/cc-openwrt
200
$ ./scripts/feeds list -s
201
packages src-git  7f3ef93  https://github.com/openwrt/packages.git;for-15.05
202
luci     src-git  af9f093  https://github.com/openwrt/luci.git;for-15.05
203
routing  src-git  5876cd3  https://github.com/openwrt-routing/packages.git;for-15.05
204
telephony src-git  d4ca5e5  https://github.com/openwrt/telephony.git;for-15.05
205
management src-git  ab76d57  https://github.com/openwrt-management/packages.git;for-15.05
206
207
            \end{lstlisting}
208
209
        \textbf{Save the configuration information}
210
            \href{http://wiki.openwrt.org/doc/howto/build}{Read more in the official document - How to Build}
211
212
            \begin{lstlisting}
213
# In folder openwrt-cc
214
# After selecting all the changes in make menuconfig
215
216
# Export the diffconfig to file
217
./scripts/diffconfig.sh > diffconfig
218
            \end{lstlisting}
219
220
        \textbf{How to 'make' without re-compiling}
221
222
223
224
225 d1ed66aa Quynh PX Nguyen
Prepare the C++ development for Linux Mint