Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edited README.md, modified build instructions #72

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ To select target chip, choose one of:
- `export BADGEROS_PORT=esp32p4`
- `export BADGEROS_PORT=esp32c6` (default)

Before building, first run: `make prepare`

To build: `make build`

To remove build files: `make clean`
Expand Down
12 changes: 6 additions & 6 deletions kernel/src/filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void fs_mount(badge_err_t *ec, fs_type_t type, blkdev_t *media, char const *moun

// Delegate to filesystem-specific mount.
switch (type) {
// case FS_TYPE_FAT: vfs_fat_mount(ec, &vfs_table[vfs_index]); break;
case FS_TYPE_FAT: vfs_fat_mount(ec, &vfs_table[vfs_index]); break;
case FS_TYPE_RAMFS: vfs_ramfs_mount(ec, &vfs_table[vfs_index]); break;
default: badge_err_set(ec, ELOC_FILESYSTEM, ECAUSE_PARAM); break;
}
Expand Down Expand Up @@ -450,7 +450,7 @@ void fs_umount(badge_err_t *ec, char const *mountpoint) {

// Delegate to filesystem-specific mount.
switch (vfs_table[vfs_index].type) {
// case FS_TYPE_FAT: vfs_fat_umount(&vfs_table[vfs_index]); break;
case FS_TYPE_FAT: vfs_fat_umount(&vfs_table[vfs_index]); break;
case FS_TYPE_RAMFS: vfs_ramfs_umount(&vfs_table[vfs_index]); break;
default: __builtin_unreachable();
}
Expand All @@ -464,12 +464,12 @@ void fs_umount(badge_err_t *ec, char const *mountpoint) {
// Returns `FS_TYPE_UNKNOWN` on error or if the filesystem is unknown.
fs_type_t fs_detect(badge_err_t *ec, blkdev_t *media) {
(void)media;
// if (vfs_fat_detect(ec, media)) {
// return FS_TYPE_FAT;
// } else {
if (vfs_fat_detect(ec, media)) {
return FS_TYPE_FAT;
} else {
badge_err_set_ok(ec);
return FS_TYPE_UNKNOWN;
// }
}
}


Expand Down
43 changes: 41 additions & 2 deletions kernel/src/filesystem/vfs_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,49 @@
#include "filesystem/vfs_fat.h"

// Try to mount a FAT filesystem.
void vfs_fat_mount(badge_err_t *ec, vfs_t *vfs);
void vfs_fat_mount(badge_err_t *ec, vfs_t *vfs) {
// Read BPB
fat_bpb_t bpb;
uint32_t root_dir_sectors, sectors_per_fat, total_sectors, data_sector_cnt, cluster_count, first_data_sector;
blkdev_read_partial(ec, vfs->media, 0, 0, (void *)&bpb, sizeof(fat_bpb_t));

// Determine FAT type
// Root Entry Count is 0 on FAT32
if(bpb.root_entry_count == 0) {
fat32_header_t fat32_header;
root_dir_sectors = 0;
blkdev_read_partial(ec, vfs->media, 0, 36, (void *)&fat32_header, sizeof(fat32_header_t));
sectors_per_fat = fat32_header.sectors_per_fat_32;
total_sectors = bpb.sector_count_32;
data_sector_cnt = total_sectors - (bpb.reserved_sector_count + (bpb.fat_count * sectors_per_fat));
}
else {
// FAT12/FAT16
fat16_header_t fat16_header;
root_dir_sectors = ((bpb.root_entry_count * 32) + (bpb.bytes_per_sector - 1)) / bpb.bytes_per_sector;
blkdev_read_partial(ec, vfs->media, 0, 36, (void *)&fat16_header, sizeof(fat16_header_t));
sectors_per_fat = bpb.sectors_per_fat_16;
total_sectors = bpb.sector_count_16;
data_sector_cnt = total_sectors - (bpb.reserved_sector_count + (bpb.fat_count * sectors_per_fat) + root_dir_sectors);
}

// Calculate some parameters
cluster_count = data_sector_cnt / bpb.sectors_per_cluster;
first_data_sector = bpb.reserved_sector_count + (bpb.fat_count * sectors_per_fat) + root_dir_sectors;

// Store disk parameters
vfs->type = FS_TYPE_FAT;
vfs->fat.bytes_per_sector = bpb.bytes_per_sector;
vfs->fat.sectors_per_cluster = bpb.sectors_per_cluster;
vfs->fat.data_sector = first_data_sector;
vfs->fat.fat_sector = bpb.reserved_sector_count;
vfs->fat.cluster_count = cluster_count;
}

// Unmount a FAT filesystem.
void vfs_fat_umount(vfs_t *vfs);
void vfs_fat_umount(vfs_t *vfs) {

}

// Identify whether a block device contains a FAT filesystem.
// Returns false on error.
Expand Down
Loading