-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathab.js
64 lines (58 loc) · 1.66 KB
/
ab.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* eslint-disable import/no-commonjs */
/* eslint-disable no-sync */
const fs = require("fs");
const simg2img = require("./simg2img");
const {fastbootExec} = require("./fastboot");
async function extractBpartitions(firmwareFolder) {
if (!fs.existsSync(firmwareFolder + "/system.img")) {
if (process.platform === "linux") {
await simg2img({
cmd:
firmwareFolder +
"/system.img_sparsechunk.* " +
firmwareFolder +
"/system.img",
});
if (!fs.existsSync(firmwareFolder + "/vendor.img")) {
await simg2img({
cmd:
firmwareFolder +
"/vendor.img_sparsechunk.* " +
firmwareFolder +
"/vendor.img",
});
}
} else if (process.platform === "win32") {
await simg2img({
cmd:
"/decompress " +
firmwareFolder +
"/system.img_sparsechunk.0 " +
firmwareFolder +
"/system.img",
});
if (!fs.existsSync(firmwareFolder + "/vendor.img")) {
await simg2img({
cmd:
"/decompress " +
firmwareFolder +
"/vendor.img_sparsechunk.0 " +
firmwareFolder +
"/vendor.img",
});
}
}
console.log("Done");
}
}
async function flashBpartitions(firmwareFolder) {
console.log("\nDevice is using A/B partitions");
console.log("\nFlashing system and vendor to slot b");
await fastbootExec({
cmd: "flash system_b " + firmwareFolder + "/system.img",
});
await fastbootExec({
cmd: "flash vendor_b " + firmwareFolder + "/vendor.img",
});
}
module.exports = { extractBpartitions, flashBpartitions };