Skip to content
Permalink
Browse files

uboot flash added

  • Loading branch information...
madmonkey1907 committed Mar 1, 2017
1 parent 2df5492 commit aaad6cecff35bb246faa476973feb93823793e3f
@@ -25,6 +25,7 @@ struct uboot_t
#define uboot_base_m (dram_base+0x7000000u)
#define uboot_base_f 0x100000u
#define sector_size 0x20000u
#define uboot_maxsize_f (sector_size*0x10)
#define kernel_base_f (sector_size*0x30)
#define kernel_maxsize_f (sector_size*0x20)
#define transfer_base_m (dram_base+0x7400000u)
@@ -125,11 +125,18 @@ void MainWindow::on_actionRebuild_kernel_img_triggered()

void MainWindow::on_actionFlash_kernel_triggered()
{
if(QMessageBox::warning(this,"","sure?",QMessageBox::Yes|QMessageBox::Abort,QMessageBox::Abort)!=QMessageBox::Yes)
if(QMessageBox::warning(this,"kernel","sure?",QMessageBox::Yes|QMessageBox::Abort,QMessageBox::Abort)!=QMessageBox::Yes)
return;
emit doWork(Worker::flashKernel);
}

void MainWindow::on_actionFlash_uboot_triggered()
{
if(QMessageBox::warning(this,"uboot","sure?",QMessageBox::Yes|QMessageBox::Abort,QMessageBox::Abort)!=QMessageBox::Yes)
return;
emit doWork(Worker::flashUboot);
}

void MainWindow::on_actionMemboot_triggered()
{
emit doWork(Worker::memboot);
@@ -28,6 +28,7 @@ private slots:
void on_actionUnpack_kernel_img_triggered();
void on_actionRebuild_kernel_img_triggered();
void on_actionFlash_kernel_triggered();
void on_actionFlash_uboot_triggered();
void on_actionMemboot_triggered();
void on_actionShutdown_triggered();
void on_actionDump_nand_triggered();
@@ -220,6 +220,7 @@
<addaction name="actionUnpack_kernel_img"/>
<addaction name="actionRebuild_kernel_img"/>
<addaction name="actionFlash_kernel"/>
<addaction name="actionFlash_uboot"/>
<addaction name="actionMemboot"/>
<addaction name="actionShutdown"/>
</widget>
@@ -264,6 +265,11 @@
<string>dump nand</string>
</property>
</action>
<action name="actionFlash_uboot">
<property name="text">
<string>flash uboot</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
@@ -152,6 +152,9 @@ void Worker::doWork(int work)
case flashKernel:
do_flashKernel();
break;
case flashUboot:
do_flashUboot();
break;
case memboot:
do_memboot();
break;
@@ -413,15 +416,95 @@ void Worker::do_flashKernel()
printf("kernel: verify ok\n");
else
printf("kernel: verify fuck\n");
#if 0
char cmd[1024];
sprintf(cmd,"boota %x",transfer_base_m);
if(!fel->runUbootCmd(cmd,true))
printf("%s - OK\n",Q_FUNC_INFO);
}

bool spl_checksum(char*data,uint32_t fs,int fix)
{
if(fs)
{
uint32_t*data32=reinterpret_cast<uint32_t*>(data);

if((fs<32)||((memcmp(data+4,"eGON.BT",7)!=0)&&(memcmp(data+4,"uboot",6)!=0)))
{
printf("header is not found\n");
return false;
}

uint32_t l=le32toh(data32[(memcmp(data+4,"uboot",6)==0)?5:4]);
if((l>fs)||((l%4)!=0))
{
printf("bad length in header\n");
return false;
}
l/=4;

uint32_t c=0x5F0A6C39-le32toh(data32[3]);
for(uint32_t i=0;i<l;++i)
c+=le32toh(data32[i]);

if(c!=le32toh(data32[3]))
{
if(fix!=0)
{
data32[3]=htole32(c);
printf("checksum updated\n");
return true;
}
printf("checksum check failed\n");
return false;
}

return true;
}
return false;
}

void Worker::do_flashUboot()
{
if((!init())||(!fel->haveUboot()))
{
printf("kernel: runcmd error\n");
return;
}
#endif
QByteArray u=loadFile("data/uboot.bin");
size_t usize=u.size();
if(usize==0)
{
printf("uboot.bin not found\n");
return;
}
if(usize>uboot_maxsize_f)
{
printf("uboot: invalid size in header\n");
return;
}
if(!spl_checksum(u.data(),usize,1))
return;
usize=(usize+sector_size-1)/sector_size;
usize=usize*sector_size;
if(((size_t)u.size())!=usize)
{
const size_t oldSize=u.size();
u.resize(usize);
memset(u.data()+oldSize,0xff,usize-oldSize);
}
calcProgress(-u.size()*2);
if(fel->writeFlash(uboot_base_f,usize,u.data())!=usize)
{
printf("uboot: write error\n");
return;
}
printf("uboot: write ok\n");
QByteArray baver(usize,Qt::Uninitialized);
if(fel->readFlash(uboot_base_f,usize,baver.data())!=usize)
{
printf("uboot: read error\n");
return;
}
if(memcmp(u.data(),baver.data(),usize)==0)
printf("uboot: verify ok\n");
else
printf("uboot: verify fuck\n");
printf("%s - OK\n",Q_FUNC_INFO);
}

@@ -17,6 +17,7 @@ class Worker:public QObject
unpackKernel,
packKernel,
flashKernel,
flashUboot,
memboot,
shutdown
};
@@ -41,6 +42,7 @@ private slots:
void do_unpackKernel();
void do_packKernel();
void do_flashKernel();
void do_flashUboot();
void do_memboot();
void do_shutdown();

0 comments on commit aaad6ce

Please sign in to comment.
You can’t perform that action at this time.