You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
693 B
41 lines
693 B
8 years ago
|
#include <stdint.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include <flash.h>
|
||
|
#include <macros.h>
|
||
|
|
||
|
#include <fs/block.h>
|
||
|
#include <fs/part.h>
|
||
|
|
||
|
struct part_hdr {
|
||
|
char magic[8];
|
||
|
char rsv[24];
|
||
|
} __attribute__((packed));
|
||
|
|
||
|
struct part_entry {
|
||
|
char label[16];
|
||
|
uint32_t start, end;
|
||
|
uint32_t flags;
|
||
|
uint32_t rsv;
|
||
|
} __attribute__((packed));
|
||
|
|
||
|
#define PART_MAGIC "FL-PART\x7f"
|
||
|
|
||
|
int part_create(struct flash_dev *dev)
|
||
|
{
|
||
|
struct part_hdr hdr;
|
||
|
|
||
|
if (block_is_erased(dev, 0, 4 * KIB) != 0 &&
|
||
|
flash_erase(dev, 0, 4 * KIB) != 0)
|
||
|
return -1;
|
||
|
|
||
|
memset(&hdr, 0, sizeof hdr);
|
||
|
memcpy(hdr.magic, PART_MAGIC, sizeof hdr.magic);
|
||
|
|
||
|
if (flash_write(dev, 0, &hdr, sizeof hdr) != 0)
|
||
|
return -1;
|
||
|
|
||
|
return 0;
|
||
|
}
|