parent
2448ddcd4e
commit
adcda56894
@ -0,0 +1,3 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
int part_create(struct flash_dev *dev); |
@ -0,0 +1,40 @@ |
|||||||
|
#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; |
||||||
|
} |
Loading…
Reference in new issue