Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LIVE-11184][Europa] Firmware update support #6775

Merged
merged 7 commits into from
May 2, 2024
Merged
5 changes: 5 additions & 0 deletions .changeset/fair-spiders-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Firmware update: fix restore step for Europa
5 changes: 5 additions & 0 deletions .changeset/heavy-panthers-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/device-core": patch
---

Fix getVersion parsing for Europa
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ const EarlySecurityChecks = ({
closeFwUpdateDrawer();
restartChecksAfterUpdate();
},
deviceHasPin: deviceModelId !== DeviceModelId.stax, // early security checks are triggered only if the device is in one of the steps prior to setting a PIN code
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this prop gets overridden so it's useless here

},
{
preventBackdropClick: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import StepUpdating from "../steps/02-step-updating";
import StepConfirmation, { StepConfirmFooter } from "../steps/03-step-confirmation";
import { Step, StepId, STEPS } from "../types";
import { isDeviceLocalizationSupported } from "@ledgerhq/live-common/device/use-cases/isDeviceLocalizationSupported";
import { isCustomLockScreenSupported } from "@ledgerhq/live-common/device/use-cases/isCustomLockScreenSupported";

export const createFirmwareUpdateSteps = ({
firmware,
Expand All @@ -23,7 +24,8 @@ export const createFirmwareUpdateSteps = ({
stateStepId: StepId;
}) => {
const hasRestoreStep =
firmware && isDeviceLocalizationSupported(firmware.final.name, deviceModelId);
isCustomLockScreenSupported(deviceModelId) ||
(firmware && isDeviceLocalizationSupported(firmware.final.name, deviceModelId));

const restoreStepLabel =
stateStepId === STEPS.FINISH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ const UpdateModal = ({
setIsLanguagePromptOpen,
confirmedPrompt,
setConfirmedPrompt,
deviceHasPin: !(deviceModelId === DeviceModelId.stax && !props.deviceInfo?.onboarded),
deviceHasPin: !(
[DeviceModelId.stax, DeviceModelId.europa].includes(deviceModelId) &&
!props.deviceInfo?.onboarded
),
};

const getMainContent = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const StepPrepare = ({
}
// This whole flow is still not a device action. The step originally would only send
// the firmware update payload to the device whereas now we are backing up the CLS too
// but only for stax.
// but only for stax or europa.
const deviceId = device?.deviceId ?? "";
const maybeCLSBackup =
deviceInfo.onboarded && isCustomLockScreenSupported(deviceModelId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ test("isBootloaderVersionSupported", () => {
expect(isBootloaderVersionSupported("0.9.0", stax)).toBe(false);
expect(isBootloaderVersionSupported("1.0.0", stax)).toBe(true);
expect(isBootloaderVersionSupported("1.0.0-whatever0", stax)).toBe(true);

/**
* Europa
*/
expect(isBootloaderVersionSupported("0.1.0", "europa" as DeviceModelId)).toBe(true);
expect(isBootloaderVersionSupported("0.1.0-whatever0", "europa" as DeviceModelId)).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const deviceVersionRangesForBootloaderVersion: {
nanoX: ">=2.0.0",
nanoSP: ">=1.0.0",
stax: ">=1.0.0",
europa: ">=1.0.0",
europa: ">=0.0.0",
};
/**
* @returns whether the Bootloader Version bytes are included in the result of the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeviceModelId } from "@ledgerhq/devices";
import { isDeviceLocalizationSupported } from "./isDeviceLocalizationSupported";
const { nanoS, nanoSP, nanoX, stax } = DeviceModelId;
const { nanoS, nanoSP, nanoX, stax, europa } = DeviceModelId;

test("isDeviceLocalizationSupported", () => {
/**
Expand Down Expand Up @@ -45,4 +45,10 @@ test("isDeviceLocalizationSupported", () => {
* */
expect(isDeviceLocalizationSupported("9.0.0", nanoS)).toBe(false);
expect(isDeviceLocalizationSupported("9.0.0-whatever", nanoS)).toBe(false);

/**
* Europa
* */
expect(isDeviceLocalizationSupported("0.0.0", europa)).toBe(true);
expect(isDeviceLocalizationSupported("0.0.0-whatever", europa)).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const deviceVersionRangesForLocalization: { [key in DeviceModelId]?: string } =
nanoX: ">=2.1.0",
nanoSP: ">=1.1.0",
stax: ">=1.0.0",
europa: ">=1.0.0",
europa: ">=0.0.0",
};

export const isDeviceLocalizationSupported = (
Expand Down
20 changes: 11 additions & 9 deletions libs/ledger-live-common/src/hw/firmwareUpdate-repair.ts
Copy link
Contributor Author

@ofreyssinet-ledger ofreyssinet-ledger Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a small refacto here, for improved readability

Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ export const repairChoices = [
},
];

const filterMCUForDeviceInfo = deviceInfo => {
const provider = getProviderId(deviceInfo);
return mcu => mcu.providers.includes(provider);
};

const repair = (
deviceId: string,
forceMCU_?: string | null,
Expand Down Expand Up @@ -126,9 +121,16 @@ const repair = (
seVersion,
seTargetId,
});
const validMcusForDeviceInfo = mcus
.filter(filterMCUForDeviceInfo(deviceInfo))
.filter(mcu => mcu.from_bootloader_version !== "none");
const provider = getProviderId(deviceInfo);

/**
* filter the MCUs that are available on the provider and
* have a "from_bootloader_version" different from "none"
* */
const availableMcus = mcus.filter(
mcu =>
mcu.providers.includes(provider) && mcu.from_bootloader_version !== "none",
);

log("hw", "firmwareUpdate-repair valid mcus for device", {
validMcusForDeviceInfo,
Expand All @@ -152,7 +154,7 @@ const repair = (
});

const mcu = ManagerAPI.findBestMCU(
validMcusForDeviceInfo.filter(({ id }: McuVersion) =>
availableMcus.filter(({ id }: McuVersion) =>
finalFirmware.mcu_versions.includes(id),
),
);
Expand Down
Loading