Skip to content

Commit

Permalink
configurable flash top address.
Browse files Browse the repository at this point in the history
  • Loading branch information
zjli-2019 committed Apr 19, 2023
1 parent b41637a commit 15c2286
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
30 changes: 29 additions & 1 deletion app/src/main/java/com/ingchips/app/SecondFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
Expand Down Expand Up @@ -139,7 +140,7 @@ private void ParsePacket() {
}

Spinner spinner = binding.chipFamilySpinner;
if (!PlanBuilder.makeFlashProcedure(plan, (int)spinner.getSelectedItemId(), false)) {
if (!PlanBuilder.makeFlashProcedure(plan, (int)spinner.getSelectedItemId(), getFlashTopAddress())) {
showMsg("failed to make flash procedure");
plan = null;
} else {
Expand Down Expand Up @@ -310,6 +311,19 @@ private void onDisconnected(BluetoothGatt gatt) {
.show();
}

private long getFlashTopAddress() {
String s = binding.editFlashTopAddr.getText().toString();
return s.startsWith("0x") || s.startsWith("0X") ?
Integer.parseInt(s.substring(2), 16)
:
Integer.parseInt(s);
}
private void updateFlashTopAddress() {
Spinner spinner = binding.chipFamilySpinner;
long top = PlanBuilder.getFlashTopAddress((int)spinner.getSelectedItemId());
binding.editFlashTopAddr.setText(String.format("0x%08X", top));
}

@SuppressLint("ResourceType")
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Expand All @@ -320,6 +334,20 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
R.array.ota_chip_family, android.R.layout.simple_spinner_dropdown_item));
binding.chipFamilySpinner.setPrompt("Select chip family");

binding.chipFamilySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
updateFlashTopAddress();
}

@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});

updateFlashTopAddress();

if (otaLocal == null) {
otaLocal = new OtaLocalFragment(this);
otaOnline = new OtaOnlineFragment(this);
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/ingchips/fota/PlanBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ private Plan() {}
new FlashInfo(0x02000000, 512 * 1024, 4 * 1024, false)
};

public static boolean makeFlashProcedure(Plan plan, int chipSeries, boolean isSecure) {
public static long getFlashTopAddress(int chipSeries) {
FlashInfo f = FlashInfos[chipSeries];
return f.BaseAddr + f.TotalSize;
}

public static boolean makeFlashProcedure(Plan plan, int chipSeries,
long flashTopAddress) {
FlashInfo CurrentFlash = FlashInfos[chipSeries];
plan.manualReboot = CurrentFlash.ManualReboot;
plan.pageSize = CurrentFlash.PageSize;

int FLASH_PAGE_SIZE = CurrentFlash.PageSize;
long FLASH_OTA_DATA_HIGH = CurrentFlash.BaseAddr + CurrentFlash.TotalSize;
long FLASH_OTA_DATA_HIGH = flashTopAddress;

for (UpdateItem item : plan.items) {
int size = ((item.data.length + (FLASH_PAGE_SIZE - 1)) / FLASH_PAGE_SIZE) * FLASH_PAGE_SIZE;
Expand Down
24 changes: 21 additions & 3 deletions app/src/main/res/layout/fragment_second.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
<LinearLayout
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="25dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp">
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textLog2"
Expand All @@ -41,7 +45,21 @@
android:id="@+id/chip_family_spinner"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="36dp" />
android:layout_height="48dp" />

<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Flash Top Address" />

<EditText
android:id="@+id/editFlashTopAddr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:minHeight="48dp" />

<TableLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit 15c2286

Please sign in to comment.