Skip to content

Repository files navigation

EDLLibrary

捐赠 / Donate

支付宝 Alipay

微信 WeChat

Qualcomm EDL (Emergency Download) 相关操作库,支持 Sahara/Firehose 通信、分区读写、OnePlus 兼容流程、super 免合并刷写、设备信息读取与 OCDT 生成。
A C# library for Qualcomm EDL workflows, including Sahara/Firehose communication, partition read/write, OnePlus compatibility flows, direct super flashing, device info extraction, and OCDT generation.

功能概览 / Features

  • Flash:串口连接、Sahara 引导下载、Firehose 配置、分区读写、擦除、重启、部分 OnePlus 认证流程。
    Flash: serial connection, Sahara programmer download, Firehose configuration, partition read/write, erase, reboot, and selected OnePlus auth flows.
  • SuperDirectWriter:识别散包并将逻辑分区直接写入 super(支持官方 metadata 或重算 metadata)。
    SuperDirectWriter: detect scattered ROM packages and write logical partitions directly into super (official metadata or regenerated metadata).
  • DeviceInfoReader:从 super/system 读取 build.prop 并解析为键值。
    DeviceInfoReader: read and parse build.prop from super/system into key-value pairs.
  • OcdtGenerator:按 projId 生成/保存 OCDT,支持从文本中提取 projId 和 rawprogram 中的 OCDT 大小。
    OcdtGenerator: generate/save OCDT by projId, with helpers to extract projId and OCDT size from text/rawprogram.
  • ProgressManager:统一进度事件(百分比、速度、状态)。
    ProgressManager: unified progress event reporting (percentage, speed, status).

环境要求 / Requirements

  • .NET SDK: 10.0(项目目标框架为 net10.0
    .NET SDK: 10.0 (target framework is net10.0)
  • 操作系统:Windows(依赖 System.IO.Ports 串口通信)
    OS: Windows (uses System.IO.Ports serial communication)
  • 设备需处于 EDL 模式并可通过 COM 口访问。
    Device must be in EDL mode and reachable through a COM port.

构建 / Build

dotnet restore
dotnet build -c Release

快速开始 / Quick Start

using EDLLibrary;
using EDLLibrary.code.Utility;
using System;
using System.Threading;

ProgressManager.ProgressUpdated += (_, e) =>
{
    Console.WriteLine($"{e.Progress:F2}% | {e.Speed:F2} MB/s | {e.Status}");
};

using var flash = new Flash("COM5", "ufs"); // storageType: "ufs" or "emmc"
flash.RegisterPort();

bool inFirehose = flash.ProbeDeviceMode();
if (!inFirehose)
{
    bool saharaOk = flash.Sahara(@"C:\path\prog_firehose.elf");
    if (!saharaOk) throw new Exception("Sahara failed.");
}

string cfg = flash.ConfigureDDR();
if (cfg != "success")
{
    // possible values: success / failed / needsig / oplus_auth_failed
    throw new Exception($"ConfigureDDR failed: {cfg}");
}

// Example write: file -> LUN0, start sector 0, label boot
flash.WriteFile(
    filepath: @"C:\path\boot.img",
    start_sector: "0",
    num_sector: "0",
    physical_partition_number: "0",
    label: "boot",
    token: CancellationToken.None);

主要 API / Main APIs

Flash

  • 初始化与连接 / Init and connect
    • new Flash(portName, storageType)
    • Initialize(portName, storageType)
    • RegisterPort()
  • Sahara / Firehose
    • Sahara<T>(T programmerFile) (string 路径或 Stream)
    • ConfigureDDR(), ConfigureDDR_Oplus(bool enableVip = true)
  • 读写擦除 / Read, write, erase
    • WriteFile(...), WriteFileAsync(...)
    • Read(...), ReadWithLabel(...)
    • Erase(...), WriteBytes(...)
  • OnePlus 相关 / OnePlus related
    • EnableOnePlusLegacyMode(projId, socSn)
    • RunOnePlusAuth()
    • AutoEnableOnePlusLegacyMode()

SuperDirectWriter

using EDLLibrary;
using System;
using System.Threading;

var info = SuperDirectWriter.DetectScatteredPackage(@"C:\rom\rawprogram0.xml");
if (!info.IsScatteredPackage) throw new Exception("Not a scattered package.");

using var flash = new Flash("COM5", "ufs");
flash.RegisterPort();

var writer = new SuperDirectWriter(flash);
info = writer.ParseOffsetsFromOfficialMeta(info); // or: writer.ParseAndCalculateOffsets(info)

if (!info.ValidateAllPartitions(out var errors))
    throw new Exception(string.Join(Environment.NewLine, errors));

bool ok = await writer.WriteScatteredToSuper(
    info,
    lun: 0,
    superStartSector: 0,
    useOfficialMeta: true,
    partitionCallback: (name, size, index, total, status) =>
        Console.WriteLine($"{index}/{total} {name} {size} {status}"),
    cancellationToken: CancellationToken.None);

if (!ok) throw new Exception(writer.LastError ?? "WriteScatteredToSuper failed.");

DeviceInfoReader

using EDLLibrary;
using System.Threading;

var reader = new DeviceInfoReader(flash);
var props = await reader.ReadBuildInfoAsync(
    superLun: 0,
    superStartSector: 0,
    ct: CancellationToken.None);

if (props.TryGetValue("ro.build.fingerprint", out var fp))
    Console.WriteLine(fp);

OcdtGenerator

using EDLLibrary;

int projId = 19821;
if (!OcdtGenerator.IsSupported(projId))
    throw new ArgumentException("Unsupported projId");

byte[] ocdt = OcdtGenerator.Generate128KB(projId);
OcdtGenerator.GenerateAndSave(projId, @"C:\out\ocdt.img", 131072);

int extracted = OcdtGenerator.ExtractProjId(ocdt);

日志与进度 / Logging and Progress

  • 库日志默认写入:<AppBase>\tool\logs\NeKo-Edl-*.log
    Default log path: <AppBase>\tool\logs\NeKo-Edl-*.log
  • 进度事件:ProgressManager.ProgressUpdated
    Progress event: ProgressManager.ProgressUpdated

注意事项 / Notes

  • 此库会直接操作设备底层分区,存在数据丢失或设备变砖风险。
    This library writes low-level partitions and may cause data loss or device bricking.
  • 请确保 loader、分区表参数、LUN 与扇区偏移准确。
    Ensure loader, partition parameters, LUN, and sector offsets are correct.
  • 建议先在测试设备验证流程。
    Validate your workflow on a test device first.

许可证 / License

本项目采用 GNU General Public License v3.0 (GPL-3.0),详见 LICENSE.txt
This project is licensed under the GNU General Public License v3.0 (GPL-3.0). See LICENSE.txt for details.

About

Qualcomm communication source code, supports direct flashing via Meta, generated by Ocdt.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages