Skip to content

Commit

Permalink
Сделан унифицированный вывод таблицы разделов
Browse files Browse the repository at this point in the history
  • Loading branch information
forth32 committed Mar 14, 2016
1 parent db7bdcf commit b7af7f0
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ hdlc.o: hdlc.c
sahara.o: sahara.c
chipconfig.o: chipconfig.c
memio.o: memio.c
ptable.o: ptable.c
# $(CC) -c qcio.c

qcommand: qcommand.o $(OBJS)
Expand All @@ -28,7 +29,7 @@ qcommand: qcommand.o $(OBJS)
qrmem: qrmem.o $(OBJS)
gcc $^ -o $@ $(LIBS)

qrflash: qrflash.o $(OBJS)
qrflash: qrflash.o $(OBJS) ptable.o
gcc $^ -o $@ $(LIBS)

qwflash: qwflash.o $(OBJS)
Expand Down
52 changes: 49 additions & 3 deletions ptable.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Процедуры работы с таблицей разделов флешки
//
#include "include.h"

// глобальные переменные

Expand Down Expand Up @@ -33,15 +34,60 @@ for (blk=0;blk<12;blk++) {
mempoke(nand_exec,1); // сектор 2 - продолжение таблицы
nandwait();
memread(buf+udsize,sector_buf, udsize);
// копируем образ таблицы в структуру
memcpy(&fptable,buf,sizeof(fptable));

if ((fptable.magic1 != LASH_PART_MAGIC1) || (fptable.magic1 != LASH_PART_MAGIC1)) continue;
// нашли таблицу - читаем хвост
if ((fptable.magic1 != FLASH_PART_MAGIC1) || (fptable.magic2 != FLASH_PART_MAGIC2)) continue;
// нашли таблицу
validpart=1;
// корректируем длину последнего раздела
if ((maxblock != 0) && (fptable.part[fptable.numparts-1].len == 0xffffffff))
fptable.part[fptable.numparts-1].len=maxblock-fptable.part[fptable.numparts-1].offset; // если длина - FFFF, то есть растущий раздел
return 1; // все - таблица найдна, более тут делать нечего
}
}
validpart=0;
return 0;
}

//***************************************************
//* Вывод заголовка таблицы разделов
//***************************************************
void print_ptable_head() {

printf("\n # адрес размер A0 A1 A2 F# формат ------ Имя------\n");
}


//***************************************************
//* Вывод информции о разделе по его номеру
//***************************************************
int show_part(int pn) {

if (pn>=fptable.numparts) return 0; // неправильный номер раздела
printf("\r%02u %6x %6x %02x %02x %02x %02x %s %.16s\n",
pn,
fptable.part[pn].offset,
fptable.part[pn].len,
fptable.part[pn].attr1,
fptable.part[pn].attr2,
fptable.part[pn].attr3,
fptable.part[pn].which_flash,
(fptable.part[pn].attr2==1)?"LNX":"STD",
fptable.part[pn].name);

return 1;
}


//*************************************
//* Вывод таблицы разделов на экран
//*************************************
void list_ptable() {

int i;

printf("\n Версия таблицы разделов: %i",fptable.version);
print_ptable_head();
for (i=0;i<fptable.numparts;i++) show_part(i);
}

17 changes: 11 additions & 6 deletions ptable.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ struct flash_partition_entry {
uint32 offset;

// размер раздела в блоках
uint32 length;
uint32 len;

// атрибуты раздела
uint8 attrib1;
uint8 attrib2;
uint8 attrib3;
uint8 attr1;
uint8 attr2;
uint8 attr3;

// Флешка, на которой находится раздел (0 - первичная, 1 - вторичная)
uint8 which_flash;
Expand Down Expand Up @@ -164,7 +164,7 @@ struct flash_partition_table {
// Число определенных разделов
uint32 numparts;
// Список разделов
struct flash_partition_entry part_entry[FLASH_NUM_PART_ENTRIES];
struct flash_partition_entry part[FLASH_NUM_PART_ENTRIES];
int8 trash[112];
};

Expand All @@ -182,9 +182,14 @@ struct flash_usr_partition_table {
// Число определенных разделов
uint32 numparts; /* number of partition entries */
// Список разделов
struct flash_usr_partition_entry part_entry[FLASH_NUM_PART_ENTRIES];
struct flash_usr_partition_entry part[FLASH_NUM_PART_ENTRIES];
};

void print_ptable_head();
int show_part(int pn);
void list_ptable();


extern struct flash_partition_table fptable;
extern int validpart; // валидность таблицы разделов

Expand Down
1 change: 0 additions & 1 deletion qcio.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ int flash_read(int block, int page, int sect);
void setaddr(int block, int page);
void nandwait();
void hello(int mode);
int load_ptable(unsigned char* ptable);
extern int siofd;
void port_timeout(int timeout);
int send_cmd_massdata(unsigned char* incmdbuf, int blen, unsigned char* iobuf, unsigned int datalen);
Expand Down
26 changes: 17 additions & 9 deletions qrflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ char devname[50]="/dev/ttyUSB0";
#else
char devname[50]="";
#endif
//unsigned char ptable[1100]; // таблица разделов
unsigned char ptable[1100]; // таблица разделов
printf("\n sizeofpt = %i",sizeof(ptable));

memset(partlist,0,sizeof(partlist)); // очищаем список разрешенных к чтению разделов
Expand Down Expand Up @@ -459,12 +459,6 @@ if (forced_oobsize != -1) {
}
cwsize=sectorsize;
if (xflag) cwsize+=oobsize/spp; // наращиваем размер codeword на размер порции OOB на каждый сектор
if (partflag == 2)
// загружаем таблицу разделов
if (!load_ptable(ptable)) {
printf("\n Таблица разделов не найдена. Завершаем работу.\n");
return;
}
// dump(ptable,1024,0);
//printf("\n -- eccflag = %i --\n",eccflag);
mempoke(nand_ecc_cfg,mempeek(nand_ecc_cfg)&0xfffffffe|eccflag); // ECC on/off
Expand Down Expand Up @@ -520,11 +514,25 @@ if (partflag == 0) {
// Режим чтения по таблице разделов
//###################################################

if (strncmp(ptable,"\xAA\x73\xEE\x55\xDB\xBD\x5E\xE3",8) != 0) {
printf("\nТаблица разделов повреждена\n");
if (partflag == 2)
// загружаем таблицу разделов из флешки
if (!load_ptable(ptable)) {
printf("\n Таблица разделов не найдена. Завершаем работу.\n");
return;
}


if (!validpart) {
printf("\nТаблица разделов не найдена или повреждена\n");
return;
}

// Режим просмотре таблицы разделов
if (listmode) {
list_ptable();
return;
}

npar=*((unsigned int*)&ptable[12]);
printf("\n Версия таблицы разделов: %i",*((unsigned int*)&ptable[8]));
if ((partnumber != -1) && (partnumber>=npar)) {
Expand Down

0 comments on commit b7af7f0

Please sign in to comment.