Project

General

Profile

QMI-RIL » History » Version 16

Wolfgang Wiedmeyer, 07/16/2017 08:57 AM
qmi_wwan replaces RMNET driver

1 1 Wolfgang Wiedmeyer
h1. QMI-RIL
2
3
This page covers development efforts to create a "Radio Interface Layer":https://en.wikipedia.org/wiki/Radio_Interface_Layer (RIL) for modems that use the Qualcomm MSM Interface (QMI) protocol. The work is currently carried out for the Galaxy S 3 4G (I9305) which has a Qualcomm MDM9615 modem. The Galaxy Note 2 4G (t0lte) uses the same modem and this device could be supported as well in Replicant when the QMI-RIL is ready. We will hopefully identify further candidates that have an isolated modem using the QMI protocol and for which Replicant support could be added. Among the non-Android devices, the iPhone 5  is one that "uses the MDM9615 modem":https://www.theiphonewiki.com/wiki/MDM9615 as well.
4 2 Wolfgang Wiedmeyer
5 6 Wolfgang Wiedmeyer
"relevant thread on libqmi mailing list":https://lists.freedesktop.org/archives/libqmi-devel/2017-February/002089.html
6
7 2 Wolfgang Wiedmeyer
h2. Modem boot
8
9
When the MDM9615 modem is activated, it first boots into a download mode. There, firmware, bootloaders and EFS files are uploaded to the modem via a serial interface. The used protocol is called SAHARA and it is a proprietary protocol developed by Qualcomm. The protocol covers various functionalities. We will likely only need to implement a very small subset that is responsible for transferring firmware and other files to the modem and possibly synchronising changes to EFS files with the filesystem.
10
11 3 Wolfgang Wiedmeyer
Qualcomm provides the proprietary tool kickstart for uploading the files to the modem. It is run by the daemon qcks. The options qcks supplies to kickstart show which files need to be transferred:
12 2 Wolfgang Wiedmeyer
<pre>
13
/system/bin/ks -v  -w /data/cp_log/ -p /dev/ttyUSB0 -f 0 -r 21 -s 2:/firmware/image/amss.mbn -s 6:/firmware/image/apps.mbn -s 8:/firmware/image/dsp1.mbn -s 11:/firmware/image/osbl.mbn -s 12:/firmware/image/dsp2.mbn -s 21:/firmware/image/sbl1.mbn -s 22:/firmware/image/sbl2.mbn -s 23:/firmware/image/rpm.mbn -s 28:/firmware/image/dsp3.mbn -s 16:/tombstones/qcks/efs1.bin -s 17:/tombstones/qcks/efs2.bin -s 20:/tombstones/qcks/efs3.bin -s 29:/tombstones/qcks/acdb.bin
14 1 Wolfgang Wiedmeyer
</pre>
15 3 Wolfgang Wiedmeyer
16
Logcat and dmesg output of the upload: attachment:ks_logcat, attachment:ks_dmesg
17 4 Wolfgang Wiedmeyer
18
"libopenpst":https://github.com/openpst/libopenpst can be used as a reference to implement the file upload and as documentation about the protocol. The "kernel":https://git.replicant.us/replicant/kernel_samsung_smdk4412 itself can be checked for the different boot modes.
19
20
h2. QMI protocol
21
22 16 Wolfgang Wiedmeyer
"libqmi":https://www.freedesktop.org/wiki/Software/libqmi/ is a library that implements the QMI protocol and it will be used for implementing the RIL. libqmi needs the cdc-wdm and qmi_wwan kernel drivers for communicating with the modem. These are backported to the smdk4412 kernel on the "qmi branch":https://code.fossencdi.org/kernel_samsung_smdk4412.git/log/?h=qmi. The branch is not yet merged into the replicant-6.0 branch because one commit sets SELinux to permissive. This is more convenient for development. The qmi_wwan driver replaces the RMNET usb driver that the blobs use for a network interface to the modem.
23 7 Wolfgang Wiedmeyer
24 15 Wolfgang Wiedmeyer
libqmi provides the command-line tool @qmicli@ to communicate with the modem. It was already successfully tested on the S 3 4G.
25
26 7 Wolfgang Wiedmeyer
h2. Cross-compiling libqmi for Android on ARM
27
28 12 Wolfgang Wiedmeyer
These instructions can be used to build libqmi and include it in an image for the Galaxy S 3 4G. See the [[GalaxyS3I9305Build|build instructions for the Galaxy S 3 4G]] for building the image. Android.mk files need to be written to integrate libqmi and its dependencies into a regular device build. Some of the source code is auto-generated and some dependencies like glib have a lot of source files, so writing the Android Makefiles will be some work.
29 7 Wolfgang Wiedmeyer
30 13 Wolfgang Wiedmeyer
Based on "these instructions":https://zwyuan.github.io/2016/07/17/cross-compile-glib-for-android/
31
32 8 Wolfgang Wiedmeyer
h3. Dependencies
33
34
<pre>
35 11 Wolfgang Wiedmeyer
apt-get install groff libltdl-dev pkg-config gtk-doc-tools
36 8 Wolfgang Wiedmeyer
</pre>
37
38 7 Wolfgang Wiedmeyer
h3. Getting the source code
39
40 1 Wolfgang Wiedmeyer
<pre>
41 13 Wolfgang Wiedmeyer
git clone https://code.fossencdi.org/external_libqmi.git external/libqmi
42 1 Wolfgang Wiedmeyer
git clone https://git.savannah.gnu.org/git/libiconv.git external/libiconv -b v1.15
43 7 Wolfgang Wiedmeyer
git clone https://github.com/libffi/libffi external/libffi -b v3.2.1
44 13 Wolfgang Wiedmeyer
git clone https://code.fossencdi.org/external_gettext.git external/gettext
45 1 Wolfgang Wiedmeyer
git clone https://github.com/GNOME/glib external/glib -b 2.52.3
46 13 Wolfgang Wiedmeyer
</pre>
47
48
h3. Configure and build
49
50
The attached script attachment:qmi_build_envsetup.sh makes it more convenient to configure the environment. You need to set the Replicant source tree root folder as the @REPLICANT_BASE@ variable at the top of the script. Then you can source it:
51
<pre>
52
. path/to/qmi_build_envsetup.sh
53
</pre> 
54
55 14 Wolfgang Wiedmeyer
It's recommended to not run this and the following commands in the same shell you use for building a Replicant image as the environment variables break the Replicant build. Run the commands after you built an image for the I9305.
56 13 Wolfgang Wiedmeyer
57
h4. libiconv
58
59
<pre>
60
./autogen.sh
61 1 Wolfgang Wiedmeyer
./configure --build=${BUILD_SYSTEM} --host=arm-eabi --prefix=${PREFIX} --disable-rpath
62 14 Wolfgang Wiedmeyer
make install -j8
63
</pre>
64
65
If @autoconf-2.69@ and @autoheader-2.69@ are not found, remove the @-2.69@ suffix from the @AUTOCONF@ and @AUTOHEADER@ variables in @Makefile.devel@, @libcharset/Makefile.devel@ and @preload/Makefile.devel@.
66
67
h4. libffi
68
69
<pre>
70
./autogen.sh
71
sed -e '/^includesdir/ s/$(libdir).*$/$(includedir)/' -i include/Makefile.in
72
sed -e '/^includedir/ s/=.*$/=@includedir@/' -e 's/^Cflags: -I${includedir}/Cflags:/' -i libffi.pc.in
73
./configure --build=${BUILD_SYSTEM} --host=arm-eabi --prefix=${PREFIX} --enable-static
74
make install -j8
75
</pre> 
76
77
h4. gettext
78
79
<pre>
80
./autogen.sh
81
./configure --build=${BUILD_SYSTEM} --host=arm-eabi --prefix=${PREFIX} --disable-rpath --disable-libasprintf --disable-java --disable-native-java --disable-openmp --disable-curses
82
make install -j8
83
</pre>
84
85
h4. glib
86
87
First, the file @android.cache@ with the following content needs to be created:
88
<pre>
89
glib_cv_long_long_format=ll
90
glib_cv_stack_grows=no
91
glib_cv_sane_realloc=yes
92
glib_cv_have_strlcpy=no
93
glib_cv_va_val_copy=yes
94
glib_cv_rtldglobal_broken=no
95
glib_cv_uscore=no
96
glib_cv_monotonic_clock=no
97
ac_cv_func_nonposix_getpwuid_r=no
98
ac_cv_func_posix_getpwuid_r=no
99
ac_cv_func_posix_getgrgid_r=no
100
glib_cv_use_pid_surrogate=yes
101
ac_cv_func_printf_unix98=no
102
ac_cv_func_vsnprintf_c99=yes
103
ac_cv_func_realloc_0_nonnull=yes
104
ac_cv_func_realloc_works=yes
105
</pre>
106
107
Make it read-only:
108
<pre>
109
chmod 444 android.cache
110
</pre>
111
112
Then configure and build:
113
<pre>
114
./autogen.sh --build=${BUILD_SYSTEM} --host=${TOOLCHAIN_PREFIX} --prefix=${PREFIX} --disable-dependency-tracking --cache-file=android.cache --enable-included-printf --enable-static --with-pcre=no --enable-libmount=no
115
make install -j8
116
</pre>
117
118
h4. libqmi
119
120
<pre>
121
./autogen.sh --build=${BUILD_SYSTEM} --host=${TOOLCHAIN_PREFIX} --prefix=${PREFIX} --without-udev
122 13 Wolfgang Wiedmeyer
make install -j8
123 7 Wolfgang Wiedmeyer
</pre>