From a1f00b1ca4d571968ad008f47e3eb5ceb79e5f63 Mon Sep 17 00:00:00 2001 From: madmonkey Date: Fri, 29 Sep 2017 16:17:55 +0300 Subject: write nand --- hakchi-gui/src/mainwindow.cpp | 6 ++++ hakchi-gui/src/mainwindow.h | 1 + hakchi-gui/src/mainwindow.ui | 6 ++++ hakchi-gui/src/worker.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++ hakchi-gui/src/worker.h | 2 ++ 5 files changed, 80 insertions(+) diff --git a/hakchi-gui/src/mainwindow.cpp b/hakchi-gui/src/mainwindow.cpp index 25bba76..9c498bf 100644 --- a/hakchi-gui/src/mainwindow.cpp +++ b/hakchi-gui/src/mainwindow.cpp @@ -151,3 +151,9 @@ void MainWindow::on_actionDump_nand_triggered() { emit doWork(Worker::dumpNandFull); } + +void MainWindow::on_actionWrite_nand_triggered() +{ +// do not use +// emit doWork(Worker::writeNandFull); +} diff --git a/hakchi-gui/src/mainwindow.h b/hakchi-gui/src/mainwindow.h index 7c9b8c9..45a98c9 100644 --- a/hakchi-gui/src/mainwindow.h +++ b/hakchi-gui/src/mainwindow.h @@ -32,6 +32,7 @@ private slots: void on_actionMemboot_triggered(); void on_actionShutdown_triggered(); void on_actionDump_nand_triggered(); + void on_actionWrite_nand_triggered(); private: Ui::MainWindow*ui; diff --git a/hakchi-gui/src/mainwindow.ui b/hakchi-gui/src/mainwindow.ui index a85fcac..f2d26ef 100644 --- a/hakchi-gui/src/mainwindow.ui +++ b/hakchi-gui/src/mainwindow.ui @@ -217,6 +217,7 @@ + @@ -265,6 +266,11 @@ dump nand + + + write nand + + flash uboot diff --git a/hakchi-gui/src/worker.cpp b/hakchi-gui/src/worker.cpp index aa25b84..a57ca64 100644 --- a/hakchi-gui/src/worker.cpp +++ b/hakchi-gui/src/worker.cpp @@ -143,6 +143,9 @@ void Worker::doWork(int work) case dumpNandFull: do_dumpNandFull(); break; + case writeNandFull: + do_writeNandFull(); + break; case unpackKernel: do_unpackKernel(); break; @@ -356,6 +359,68 @@ void Worker::do_dumpNandFull() printf("%s - OK\n",Q_FUNC_INFO); } +void Worker::do_writeNandFull() +{ + if((!init())||(!fel->haveUboot())) + { + return; + } + const size_t block=0x2000000; + const size_t count=0x10; + calcProgress(0-(block*count)); + const QString nandFile("dump/nand.bin"); + QDir(".").mkdir("dump"); + size_t fs=loadFile(nandFile.toLocal8Bit(),0); + size_t offset=0; + md5context context; + md5init(&context); + QByteArray buf(block,Qt::Uninitialized); + if((fs>0)&&((fs%block)==0)&&(fs<=(block*count))) + { + FILE*hf=fopen(nandFile.toLocal8Bit(),"rb"); + if(hf) + { + while(fread(buf.data(),1,block,hf)==block) + { + if(fel->writeFlash(offset,block,buf.data())!=block) + { + printf("nand: write error\n"); + return; + } + md5update(&context,buf.data(),block); +// calcProgress(block); + offset+=block; + } + fclose(hf); + } +// printf("%zuM done, continuing\n",fs/0x100000); + } + else + { +// QDir(".").remove(nandFile); + } + /* + uint8_t md5[16]; + char md5str[40]; + while(offset<(block*count)) + { + if(fel->readFlash(offset,block,buf.data())!=block) + { + printf("nand: read error\n"); + return; + } + appendFile(nandFile.toLocal8Bit(),buf.data(),block); + offset+=block; + md5update(&context,buf.data(),block); + md5calc(buf.data(),block,md5); + printf("%s\n",md5print(md5,md5str)); + } + md5final(&context,md5); + printf("%s\n",md5print(md5,md5str)); + */ + printf("%s - OK\n",Q_FUNC_INFO); +} + void Worker::do_unpackKernel() { if(::system(QString("extractimg \"%1\"").arg(kernelFile).toLocal8Bit())==0) diff --git a/hakchi-gui/src/worker.h b/hakchi-gui/src/worker.h index 57fb476..3135b89 100644 --- a/hakchi-gui/src/worker.h +++ b/hakchi-gui/src/worker.h @@ -14,6 +14,7 @@ public: dumpUboot, dumpKernel, dumpNandFull, + writeNandFull, unpackKernel, packKernel, flashKernel, @@ -39,6 +40,7 @@ private: void do_dumpUboot(); void do_dumpKernel(); void do_dumpNandFull(); + void do_writeNandFull(); void do_unpackKernel(); void do_packKernel(); void do_flashKernel(); -- cgit v1.2.3