flasher implement(90%)

This commit is contained in:
dxl
2020-03-13 10:54:25 +08:00
parent aa45f9b803
commit cc5da1283a
11 changed files with 84 additions and 71 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ Download and flash [Compiled FW 12 August](https://www.dropbox.com/s/416lsrqpr2l
## App core implementation
If you want to join our project, you must comply with the following development specifications to some extent, including macro architecture and micro implementation. Let us have fun time coding.
If you want to join our project, you must comply with the following development specifications to some extent, including macro architecture and micro implementation. Let us have target time coding.
- Communication implementation: using JNI mapping C & Java communication, encapsulating posix-compliant UART library, using Google API in the upper layer (Java) and posix-compliant UART in the lower layer (C/C+++).
@@ -13,6 +13,7 @@ import androidx.annotation.Nullable;
import com.bumptech.glide.Glide;
import com.proxgrind.pm3flasher.Proxmark3Flasher;
import com.proxgrind.pm3flasher.Target;
import cn.dxl.com.Com;
import cn.dxl.common.util.LogUtils;
@@ -35,7 +36,6 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
//在程序执行读卡,写卡操作时的程序后台交互性提醒对话框
private AlertDialog mDialogWorkingState = null;
private TextView txtShowLog;
private Button btnFlash;
private MODE mode = MODE.BOOT;
@@ -61,18 +61,12 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
mDialogWorkingState.setCancelable(false);
btnFlash = findViewById(R.id.btnFlash);
txtShowLog = findViewById(R.id.txtShowLog);
}
private void initActions() {
btnFlash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!flasher.isPM3Opened()) {
if (!flasher.openProxmark3()) {
return;
}
}
mode = MODE.BOOT;
if (control.connect(null)) {
flashDefaultFW();
@@ -83,32 +77,23 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
});
}
private void appendLog(String log) {
runOnUiThread(new Runnable() {
@Override
public void run() {
txtShowLog.append("\n");
txtShowLog.append(log);
}
});
}
private void flashDefaultFW() {
new Thread(new Runnable() {
@Override
public void run() {
if (!flasher.isStart(Target.CLIENT)) {
if (!flasher.start(Target.CLIENT)) {
return;
}
}
// 如果没有在Bootloader模式下,我们需要先重启设备使其进入Bootloader模式下!
appendLog("开始判断当前是否是BOOTROM模式");
if (flasher.isBootloaderMode()) {
appendLog("当前是BOOTROM模式");
if (flasher.isStart(Target.BOOT)) {
switch (mode) {
case BOOT:
if (flasher.flashBootRom(Paths.PM3_IMAGE_BOOT_FILE)) {
// ToastUtil.show(context, getString(R.string.tips_boot_flash_success), false);
appendLog(getString(R.string.tips_boot_flash_success));
ToastUtil.show(context, getString(R.string.tips_boot_flash_success), false);
} else {
// ToastUtil.show(context, getString(R.string.tips_boot_flash_failed), false);
appendLog(getString(R.string.tips_boot_flash_failed));
ToastUtil.show(context, getString(R.string.tips_boot_flash_failed), false);
}
finishFlash();
// 开启下一轮!
@@ -117,11 +102,9 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
case OS:
if (flasher.flashFullImg(Paths.PM3_IMAGE_OS_FILE)) {
// ToastUtil.show(context, getString(R.string.tips_os_flash_success), false);
appendLog(getString(R.string.tips_os_flash_success));
ToastUtil.show(context, getString(R.string.tips_os_flash_success), false);
} else {
// ToastUtil.show(context, getString(R.string.tips_os_flash_failed), false);
appendLog(getString(R.string.tips_os_flash_failed));
ToastUtil.show(context, getString(R.string.tips_os_flash_failed), false);
}
finishFlash();
ToastUtil.show(context, getString(R.string.finish), false);
@@ -129,9 +112,8 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
break;
}
} else {
appendLog("当前不是BOOTROM模式,将会重启设备进入BOOTROM模式");
if (!flasher.enterBootloader()) {
appendLog("PM3进入刷写模式失败!");
if (!flasher.start(Target.BOOT)) {
ToastUtil.show(context, getString(R.string.tips_pm3_enter_failed), false);
}
}
}
@@ -139,14 +121,15 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
}
private void finishFlash() {
flasher.flashModeClose();
flasher.close(Target.BOOT);
flasher.close(Target.CLIENT);
}
@Override
protected void onDestroy() {
super.onDestroy();
control.unregister(this);
flasher.closeProxmark3();
flasher.close(Target.CLIENT);
}
@Override
@@ -158,7 +141,7 @@ public class PM3FlasherMainActivity extends BaseActivity implements DevCallback<
@Override
public void onDetach(String dev) {
flasher.close(Target.CLIENT);
}
@Override
@@ -5,30 +5,11 @@
android:background="@color/colorBackground"
android:orientation="vertical">
<LinearLayout
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/rdv4_2" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/txtShowLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</ScrollView>
</LinearLayout>
android:layout_centerInParent="true"
android:src="@drawable/rdv4_2" />
<Button
android:id="@+id/btnFlash"
@@ -276,5 +276,6 @@
<string name="tips_boot_flash_failed">BootRom flash failed.</string>
<string name="tips_os_flash_success">OS flash successful.</string>
<string name="tips_os_flash_failed">OS flash failed.</string>
<string name="tips_pm3_enter_failed">PM3 failed to enter flash mode!</string>
</resources>
@@ -282,5 +282,6 @@
<string name="tips_boot_flash_failed">引导器刷写失败.</string>
<string name="tips_os_flash_success">操作系统刷写成功</string>
<string name="tips_os_flash_failed">操作系统刷写失败</string>
<string name="tips_pm3_enter_failed">PM3进入刷写模式失败!</string>
</resources>
+1
View File
@@ -275,5 +275,6 @@
<string name="tips_boot_flash_failed">BootRom flash failed.</string>
<string name="tips_os_flash_success">OS flash successful.</string>
<string name="tips_os_flash_failed">OS flash failed.</string>
<string name="tips_pm3_enter_failed">PM3 failed to enter flash mode!</string>
</resources>
@@ -21,15 +21,15 @@ import java.io.FileNotFoundException;
*/
public class Proxmark3Flasher {
private static Proxmark3Flasher flasher;
private static final Proxmark3Flasher flasher;
private static String LOG = "Proxmark3Flasher";
/**
* 警告!!!!!!!!!!!!!!!!!!!!!!!!!!
* 使用刷写器的时候不要频繁关闭Client
* 使用刷写器的时候尽量不要频繁关闭Client
* openProxmark3() 请在Activity -> onCreate() 中执行
* closeProxmark3() 请求Activity -> onDestroy() 中执行
* 频繁关闭客户端会导致JNI Crash!!!!!!!!!!!!
* 频繁关闭客户端可能会导致JNI Crash!!!!!!!!!!!!
* */
static {
@@ -51,6 +51,43 @@ public class Proxmark3Flasher {
return flasher;
}
public boolean start(Target target) {
synchronized (flasher) {
switch (target) {
case CLIENT:
return openProxmark3();
case BOOT:
return enterBootloader();
}
return false;
}
}
public boolean isStart(Target target) {
synchronized (flasher) {
switch (target) {
case CLIENT:
return isPM3Opened();
case BOOT:
return isBootloaderMode();
}
return false;
}
}
public void close(Target target) {
synchronized (flasher) {
switch (target) {
case CLIENT:
closeProxmark3();
break;
case BOOT:
flashModeClose();
break;
}
}
}
/**
* The pm3 client state check!
* if client is close, the UART communication will error.
@@ -58,19 +95,19 @@ public class Proxmark3Flasher {
*
* @return status, true is open, false is close.
*/
public native boolean isPM3Opened();
private native boolean isPM3Opened();
/**
* Open the client of pm3(Communication basic)
*
* @return true is opened, false is open failed!
*/
public native boolean openProxmark3();
private native boolean openProxmark3();
/**
* Close clint of pm3(Communication basic)
*/
public native void closeProxmark3();
private native void closeProxmark3();
/**
* Request to enter bootloader mode
@@ -83,14 +120,14 @@ public class Proxmark3Flasher {
*
* @return Request result, true is the request success, false is the request failure
*/
public native boolean enterBootloader() throws IllegalStateException;
private native boolean enterBootloader() throws IllegalStateException;
/**
* Check if bootloader mode is currently available
*
* @return true is available, false is unavailable
*/
public native boolean isBootloaderMode() throws IllegalStateException;
private native boolean isBootloaderMode() throws IllegalStateException;
/**
* flash BootRom, if flash once please invoke {@link Proxmark3Flasher#flashModeClose()} behind finished.
@@ -106,7 +143,9 @@ public class Proxmark3Flasher {
e.printStackTrace();
return false;
}
return flash(file, true);
synchronized (flasher) {
return flash(file, true);
}
}
/**
@@ -123,7 +162,9 @@ public class Proxmark3Flasher {
e.printStackTrace();
return false;
}
return flash(file, false);
synchronized (flasher) {
return flash(file, false);
}
}
/**
@@ -137,7 +178,7 @@ public class Proxmark3Flasher {
* if you flash bootrom and fullimage same time,
* please invoke this function at all operation finished.
*/
public native void flashModeClose();
private native void flashModeClose();
// show warning
private void printLog() {
@@ -0,0 +1,5 @@
package com.proxgrind.pm3flasher;
public enum Target {
BOOT, CLIENT
}
@@ -28,7 +28,7 @@ Arguments:
-t <data> : toytype id, 4hex symbols
-s <data> : subtype id, 4hex symbols
For fun, try the following subtype id:
For target, try the following subtype id:
0612 - Lightcore
0118 - Series 1
0138 - Series 2
@@ -28,7 +28,7 @@ Arguments:
-t <data> : toytype id, 4hex symbols
-s <data> : subtype id, 4hex symbols
For fun, try the following subtype id:
For target, try the following subtype id:
0612 - Lightcore
0118 - Series 1
0138 - Series 2
@@ -32,7 +32,7 @@ Arguments:
-t <data> : toytype id, 4hex symbols
-s <data> : subtype id, 4hex symbols
For fun, try the following subtype id:
For target, try the following subtype id:
0612 - Lightcore
0118 - Series 1
0138 - Series 2