Commit c66667ff authored by Michal Suchanek's avatar Michal Suchanek Committed by Henrik Nordstrom
Browse files

nand-part: Reject wrong partition version.


Signed-off-by: default avatarMichal Suchanek <hramrach@gmail.com>
Signed-off-by: default avatarHenrik Nordstrom <henrik@henriknordstrom.net>
parent f1eca9d4
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mount.h> /* BLKRRPART */ #include <sys/mount.h> /* BLKRRPART */
#include "nand-part.h" #include "nand-part.h"
...@@ -96,6 +97,8 @@ __u32 calc_crc32(void * buffer, __u32 length) ...@@ -96,6 +97,8 @@ __u32 calc_crc32(void * buffer, __u32 length)
MBR *_get_mbr(int fd, int mbr_num) MBR *_get_mbr(int fd, int mbr_num)
{ {
MBR *mbr; MBR *mbr;
const char * magic = "softw311";
unsigned version = 0x100;
/*request mbr space*/ /*request mbr space*/
mbr = malloc(sizeof(MBR)); mbr = malloc(sizeof(MBR));
...@@ -112,6 +115,16 @@ MBR *_get_mbr(int fd, int mbr_num) ...@@ -112,6 +115,16 @@ MBR *_get_mbr(int fd, int mbr_num)
/*checksum*/ /*checksum*/
printf("check partition table copy %d: ", mbr_num); printf("check partition table copy %d: ", mbr_num);
printmbrheader(mbr); printmbrheader(mbr);
if(strncmp((char *)mbr->magic, magic, 8))
{
printf("magic %8.8s is not %8s\n", mbr->magic, magic);
return NULL;
}
if(mbr->version != version)
{
printf("version 0x%08x is not 0x%08x\n", mbr->version, version);
return NULL;
}
if(*(__u32 *)mbr == calc_crc32((__u32 *)mbr + 1,MBR_SIZE - 4)) if(*(__u32 *)mbr == calc_crc32((__u32 *)mbr + 1,MBR_SIZE - 4))
{ {
printf("OK\n"); printf("OK\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment