Skip to content

Commit 010c33c

Browse files
committed
RCM (Fusée Gelée) support, numerous UI updates and a lot of things for version 2.
1 parent 3d3fb56 commit 010c33c

36 files changed

+1572
-92
lines changed

BUILD.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
### How to build this app
2+
3+
Java application:
4+
* Install Maven
5+
* Execute
6+
`# mvn -B -DskipTests clean package`
7+
8+
**Building JNI libraries section**
9+
10+
First of all install JDK, GCC, make, kernel headers and whatever else (or use Gentoo <3 ).
11+
12+
Generate header (Optional! Already generated.):
13+
```
14+
$ cp NS-USBloader/src/main/java/nsusbloader/Utilities/RcmSmash.java .
15+
$ javac -h . RcmSmash.java
16+
```
17+
**Build for Linux (amd64 Linux host):**
18+
```
19+
$ cd 'NS-USBloader/JNI sources/linux'
20+
$ make install clean
21+
```
22+
**Build for Windows (on x86_64 host):**
23+
24+
[ This part should be updated ]
25+
26+
Install MinGW, msys (?) MinGW-w64 and JDK. Set JAVA_HOME, set PATH to match MinGW, MSYS, JDK/bin (and other?) environment variables.
27+
28+
x86: Install MinGw to C:\MinGW\
29+
30+
Update sources: set (uncomment) line 'BUILD_FOR_X86'
31+
32+
Set environment variables for MinGw:
33+
* C:\MinGW\bin
34+
* C:\MinGW\msys\1.0\bin
35+
```
36+
$ cd 'NS-USBloader/JNI sources/windows'
37+
$ make x86
38+
```
39+
40+
amd64: Install MinGw-w64
41+
42+
Update sources: remove line 'BUILD_FOR_X86'
43+
```
44+
$ make amd64
45+
```

JNI sources/linux/Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Compiler
2+
CC=gcc
3+
# Flags
4+
CFLAGS=-O2
5+
MKDIR_P = mkdir -p
6+
APP_NAME = smashlib.so
7+
8+
all: x86 amd64
9+
10+
x86:
11+
$(MKDIR_P) ./x86
12+
$(CC) ${CFLAGS} -m32 -c -fPIC -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux" smashlib.c -o smashlib_x86.o
13+
$(CC) ${CFLAGS} -m32 -shared -fPIC -o ./x86/${APP_NAME} smashlib_x86.o -lc
14+
15+
amd64:
16+
$(MKDIR_P) ./amd64
17+
$(CC) ${CFLAGS} -m64 -c -fPIC -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux" smashlib.c -o smashlib_amd64.o
18+
$(CC) ${CFLAGS} -m64 -shared -fPIC -o ./amd64/${APP_NAME} smashlib_amd64.o -lc
19+
20+
clean:
21+
rm -rf \
22+
smashlib_amd64.o \
23+
smashlib_x86.o \
24+
./x86 \
25+
./amd64
26+
27+
install: x86 amd64
28+
install ./x86/${APP_NAME} ../../src/main/resources/native/linux/x86/
29+
install ./amd64/${APP_NAME} ../../src/main/resources/native/linux/amd64/
30+
31+
uninstall:
32+
rm ../../src/main/resources/native/linux/x86/${APP_NAME}
33+
rm ../../src/main/resources/native/linux/amd64/${APP_NAME}

JNI sources/linux/nsusbloader_Utilities_RcmSmash.h

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JNI sources/linux/smashlib.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* NS-USBloader - native libraries for 'special purposes'
2+
* Copyright (C) 2020 Dmitry Isaenko
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include <stdlib.h>
19+
#include <string.h>
20+
#include <fcntl.h>
21+
#include <unistd.h>
22+
#include <sys/ioctl.h>
23+
#include <linux/usbdevice_fs.h>
24+
#include <linux/usb/ch9.h>
25+
#include <errno.h>
26+
27+
#include "nsusbloader_Utilities_RcmSmash.h"
28+
29+
struct usbdevfs_urb urb;
30+
31+
JNIEXPORT jint JNICALL Java_nsusbloader_Utilities_RcmSmash_smashLinux
32+
(JNIEnv * jni_env, jclass this_class, jint bus_id, jint device_addr){
33+
int ret_value;
34+
35+
char *usb_path = (char*)malloc(24 * sizeof(char));
36+
37+
sprintf(usb_path, "/dev/bus/usb/%03d/%03d", bus_id, device_addr);
38+
int fd = open(usb_path, O_RDWR);
39+
if (fd == -1)
40+
return -1;
41+
42+
struct usb_ctrlrequest* ctrl_req;
43+
44+
__u8* buf[0x7000+sizeof(ctrl_req)];
45+
46+
ctrl_req = (struct usb_ctrlrequest *) buf;
47+
ctrl_req->bRequestType = 0x82;
48+
ctrl_req->bRequest = USB_REQ_GET_STATUS;
49+
ctrl_req->wValue = 0;
50+
ctrl_req->wIndex = 0;
51+
ctrl_req->wLength = 0x7000;
52+
53+
memset(&urb, 0, sizeof(urb));
54+
urb.type = USBDEVFS_URB_TYPE_CONTROL;
55+
urb.endpoint = USB_DIR_IN | 0;
56+
urb.buffer = buf;
57+
urb.buffer_length = sizeof(buf);
58+
//Submit request
59+
ret_value = ioctl(fd, USBDEVFS_SUBMITURB, &urb);
60+
// If we failed on this step, it's a VERY bad sign. Nothing to do, let's report failure.
61+
if (ret_value != 0)
62+
return ret_value;
63+
// Wait 1/4 sec
64+
usleep(250000);
65+
struct usbdevfs_urb urb1;
66+
// Let's pick reply (everybody does it, right? In non-blocking manner.)
67+
ret_value = ioctl(fd, USBDEVFS_REAPURBNDELAY, &urb1);
68+
if (ret_value < 0){
69+
if (errno == EAGAIN){ // In case of resource temporarily unavailable
70+
// Wired.. so much time left. Let's cancel it!
71+
ret_value = ioctl(fd, USBDEVFS_DISCARDURB, &urb);
72+
// And wait a bit more..
73+
usleep(40000);
74+
// And try to pick reply. Yes, it's still possible. See /usr/src/linux/drivers/usb/core/devio.c
75+
ret_value = ioctl(fd, USBDEVFS_REAPURBNDELAY, &urb1);
76+
}
77+
}
78+
// Leftovers.
79+
free(usb_path);
80+
// Let's try to close device, but even if we fail with this, nvm.
81+
close(fd); // So we won't even write returned value somewhere.
82+
return 0;
83+
}
84+
85+
JNIEXPORT jint JNICALL Java_nsusbloader_Utilities_RcmSmash_smashWindows
86+
(JNIEnv * jni_env, jclass this_class){
87+
return -1;
88+
}

JNI sources/windows/Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Compiler
2+
CC32='C:/MinGW/bin/gcc'
3+
CC64='C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/gcc'
4+
# Flags
5+
CFLAGS=-O2
6+
MKDIR_P=mkdir
7+
APP_NAME=smashlib.dll
8+
9+
all: x86 amd64
10+
11+
#$(CC) ${CFLAGS} -m32 -c -fPIC -I "C:/MinGW/include/ddk" -I "${JAVA_HOME}/include" -I "${JAVA_HOME}/include/win32" smashlib.c -o ./x86/smashlib.o # MinGw-32 version
12+
x86:
13+
$(MKDIR_P) ./x86
14+
export PATH="C/MinGW/bin/:${PATH}"
15+
$(CC32) ${CFLAGS} -m32 -c -fPIC -I "C:/MinGW/include/ddk" -I "${JAVA_HOME}/include" -I "${JAVA_HOME}/include/win32" smashlib.c -o ./smashlib_x86.o
16+
$(CC32) ${CFLAGS} -shared -o ./x86/${APP_NAME} ./smashlib_x86.o -lsetupapi -lhid -Wl,--add-stdcall-alias
17+
18+
#$(CC) ${CFLAGS} -m64 -c -fPIC -I "C:/MinGW/include/ddk" -I "${JAVA_HOME}/include" -I "${JAVA_HOME}/include/win32" smashlib.c -o ./amd64/smashlib.o # MinGw-32 version
19+
amd64:
20+
$(MKDIR_P) ./amd64
21+
export PATH="C/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/:${PATH}"
22+
$(CC64) ${CFLAGS} -m64 -c -fPIC -I "${JAVA_HOME}/include" -I "${JAVA_HOME}/include/win32" smashlib.c -o ./smashlib_amd64.o
23+
$(CC64) ${CFLAGS} -shared -o ./amd64/${APP_NAME} ./smashlib_amd64.o -lsetupapi -lhid -Wl,--add-stdcall-alias
24+
25+
clean:
26+
rm -rf ./smashlib_x86.o ./smashlib_amd64.o ./x86 ./amd64
27+
28+
install: x86 amd64
29+
install ./x86/${APP_NAME} ../../src/main/resources/native/windows/x86/
30+
install ./amd64/${APP_NAME} ../../src/main/resources/native/windows/amd64/
31+
32+
uninstall:
33+
rm ../../src/main/resources/native/windows/x86/${APP_NAME}
34+
rm ../../src/main/resources/native/windows/amd64/${APP_NAME}

JNI sources/windows/nsusbloader_Utilities_RcmSmash.h

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)