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

Bug of fastboot? or exactly on device? I tried to flash sparsed images #2

Open
werasik2aa opened this issue Jan 9, 2024 · 0 comments

Comments

@werasik2aa
Copy link

public bool UploadData(string path)
{
    //WRITE_D
    FileStream stream = new FileStream(path, FileMode.Open);
    string madx = Command("getvar:max-download-size").Payload;
    intMAX_DWN_SIZE = (int)new Int32Converter().ConvertFromString(madx);
    long totalenremain = stream.Length;
    long curlenremain = totalenremain >= MAX_DWN_SIZE ? MAX_DWN_SIZE : totalenremain;
    while (totalenremain > 0)
    {
        if (SendDataCommand(curlenremain))
        {
            var partname = stream.Name.Split('.')[0].Split('\\').Last();
            var writeEp = device.OpenEndpointWriter(WriteEndpointID.Ep01);
            LOG(0, "[Fastboot] Sending: ", partname);
            while (curlenremain > 0)
            {
                if (curlenremain < BLOCK_SIZE)
                {
                    TransferBlock(stream, new byte[curlenremain], (int)curlenremain);
                    totalenremain -= curlenremain;
                    curlenremain = 0;
                }
                else
                {
                    TransferBlock(stream, new byte[BLOCK_SIZE], BLOCK_SIZE);
                    totalenremain -= BLOCK_SIZE;
                    curlenremain -= BLOCK_SIZE;
                }
                Progress((int)(stream.Length - totalenremain), (int)stream.Length);
            }
            stream.Close();
            stream.Dispose();
            //READ_ED
            var resBuffer = new byte[64];
            ReadEp.Read(resBuffer, DefaultRWTimeout, out _);
            var strBuffer = Encoding.ASCII.GetString(resBuffer);
            if (strBuffer.Length < HEADER_SIZE)
                throw new Exception("Invalid response from device: " + strBuffer);
            if (GetStatus(new string(strBuffer.Take(HEADER_SIZE).ToArray())) != FastbootStatus.Ok)
                throw new Exception("Invalid status: " + strBuffer);
            else
            {
                LOG(0, "[Fastboot] Writing: ", partname);
                var res = Command("flash:" + partname).Payload;
                if (res.Contains("table doesn't exist"))
                {
                    LOG(1, "Skip Partition. ", res);
                    break;
                }
            }
        }
        else
        {
            stream.Close();
            stream.Dispose();
            return false;
        }
    }
    return true;
}

this code writes the fastboot image.
ALL good, but ramdisk.img wont flash
like my device aborting pipe...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant