Skip to content

Commit

Permalink
libptable: Add an array of known partition types, reserve futurefs
Browse files Browse the repository at this point in the history
JIRA: NIL-694
  • Loading branch information
Darchiv committed Dec 10, 2024
1 parent b7ebb23 commit 8105d56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
10 changes: 6 additions & 4 deletions cmds/ptable.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static void cmd_ptableInfo(void)

static int partPrint(ptable_t *p)
{
const char *type;
unsigned int i = p->count;
unsigned int j = 0;

Expand All @@ -52,11 +53,12 @@ static int partPrint(ptable_t *p)

while (i-- != 0) {
ptable_part_t *entry = &p->parts[i];
type = ptable_typeName(entry->type);
lib_printf(
PTABLE_ENTRY_FORMAT,
++j, entry->name, entry->offset, entry->offset + entry->size,
entry->size / ptable_common.blksz, entry->size,
ptable_typeName(entry->type));
PTABLE_ENTRY_FORMAT,
++j, entry->name, entry->offset, entry->offset + entry->size,
entry->size / ptable_common.blksz, entry->size,
(type != NULL) ? type : "???");
}

return 0;
Expand Down
11 changes: 0 additions & 11 deletions lib/ptable.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@
#define htole32(a) (a)


const char *ptable_typeName(int type)
{
switch (type) {
case ptable_raw: return "raw";
case ptable_jffs2: return "jffs2";
case ptable_meterfs: return "meterfs";
default: return "unknown";
}
}


static inline u32 ptable_crc32(const void *data, size_t len)
{
return ~lib_crc32(data, len, 0xffffffff);
Expand Down
24 changes: 18 additions & 6 deletions lib/ptable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#ifndef _LIB_PTABLE_H_
#define _LIB_PTABLE_H_

#include <hal/hal.h>

/* Changelog:
* version 2: Add checksum and version fields
*/
Expand All @@ -30,17 +32,18 @@
* NOTE: data in partition table should be stored in little endian
*/

/* clang-format off */

/* Partition table magic signature */
static const u8 ptable_magic[] = { 0xde, 0xad, 0xfc, 0xbe };


/* Supported partition types */
enum { ptable_raw = 0x51, ptable_jffs2 = 0x72, ptable_meterfs = 0x75 };

/* clang-format off */
enum { ptable_raw = 0x51, ptable_jffs2 = 0x72, ptable_meterfs = 0x75, ptable_futurefs = 0x78 };
/* clang-format on */

static const u8 ptable_knownTypes[] = { ptable_raw, ptable_jffs2, ptable_meterfs, ptable_futurefs };


typedef struct {
u8 name[8]; /* Partition name */
Expand All @@ -61,16 +64,25 @@ typedef struct {
} ptable_t;


static inline const char *ptable_typeName(int type)
{
switch (type) {
case ptable_raw: return "raw";
case ptable_jffs2: return "jffs2";
case ptable_meterfs: return "meterfs";
case ptable_futurefs: return "futurefs";
default: return NULL;
}
};


/* Returns partition table size provided partition count */
static inline u32 ptable_size(u32 count)
{
return sizeof(ptable_t) + count * sizeof(ptable_part_t) + sizeof(ptable_magic);
}


extern const char *ptable_typeName(int type);


/* Converts partition table to host endianness and verifies it */
extern int ptable_deserialize(ptable_t *ptable, u32 memsz, u32 blksz);

Expand Down

0 comments on commit 8105d56

Please sign in to comment.