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

CONTFIG.TXT in FAT View #3210

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
16 changes: 16 additions & 0 deletions hw/usb/tinyusb/msc_fat_view/include/msc_fat_view/msc_fat_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,20 @@ void msc_fat_view_media_eject(void);
*/
void msc_fat_view_media_insert(void);

/* Section name for root entries */
#define ROOT_DIR_SECTION __attribute__((section(".msc_fat_view_root_entry"), used))

/**
* Macro to add static root entries
*/
#define ROOT_DIR_ENTRY(entry, file_name, attr, size_fun, read_fun, write_fun, delete_fun) \
const file_entry_t entry ROOT_DIR_SECTION = { \
.name = file_name, \
.attributes = attr, \
.size = size_fun, \
.read_sector = read_fun, \
.write_sector = write_fun, \
.delete_entry = delete_fun, \
}

#endif /* __MSC_FAT_VIEW_H__ */
27 changes: 27 additions & 0 deletions hw/usb/tinyusb/msc_fat_view/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,44 @@ pkg.deps:
- "@apache-mynewt-core/kernel/os"
- "@apache-mynewt-core/hw/usb/tinyusb"
- "@apache-mynewt-core/mgmt/imgmgr"
- "@apache-mynewt-core/util/stream"
- "@mcuboot/boot/bootutil"

pkg.deps.MSC_FAT_VIEW_CONFIG:
- "@apache-mynewt-core/sys/config"

pkg.deps.MSC_FAT_VIEW_COREDUMP_FILES:
- "@apache-mynewt-core/sys/coredump"

pkg.source_files:
- src/msc_fat_view.c

pkg.whole_archive: true

pkg.source_files.MSC_FAT_VIEW_COREDUMP_FILES:
- src/coredump_files.c

pkg.source_files.MSC_FAT_VIEW_DEFAULT_README:
- src/entry_readme.c

pkg.source_files.MSC_FAT_VIEW_HUGE_FILE:
- src/entry_huge_file.c

pkg.source_files.MSC_FAT_VIEW_SLOT0_IMAGE:
- src/entry_slot0.c

pkg.source_files.MSC_FAT_VIEW_SLOT0_HEX:
- src/entry_slot0_hex.c

pkg.source_files.MSC_FAT_VIEW_MYNEWT_SHORTCUT:
- src/entry_mynewt_htm.c

pkg.source_files.MSC_FAT_VIEW_CONFIG:
- src/entry_config.c

pkg.link_tables:
- msc_fat_view_root_entry

pkg.init.'(!BOOT_LOADER && TINYUSB_AUTO_START!=0)':
msc_fat_view_pkg_init: $before:tinyusb_start

Expand Down
112 changes: 112 additions & 0 deletions hw/usb/tinyusb/msc_fat_view/src/entry_config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include <stdint.h>
#include <stream/stream.h>
#include <msc_fat_view/msc_fat_view.h>
#include <modlog/modlog.h>
#include <hal/hal_flash.h>
#include <config/config.h>

struct config_export_stream {
struct out_stream out_stream;
uint8_t *buffer;
uint32_t buffer_start_offset;
uint16_t buffer_end_offset;
uint32_t write_offset;
};

static int
config_export_write(struct out_stream *ostream, const uint8_t *buf, uint32_t count)
{
struct config_export_stream *str = (struct config_export_stream *)ostream;
uint32_t upper_limit = str->write_offset + count;
uint32_t lower_limit = str->write_offset;
int cnt = count;

if (lower_limit < str->buffer_end_offset && upper_limit > str->buffer_start_offset) {
if (lower_limit < str->buffer_start_offset) {
cnt -= str->buffer_start_offset - lower_limit;
lower_limit = str->buffer_start_offset;
}
if (upper_limit > str->buffer_end_offset) {
cnt -= upper_limit - str->buffer_end_offset;
}
memcpy(str->buffer + lower_limit - str->buffer_start_offset,
buf + (lower_limit - str->write_offset), cnt);
}
str->write_offset += count;

return count;
}

static int
config_export_flush(struct out_stream *ostream)
{
return 0;
}

OSTREAM_DEF(config_export);

static struct config_export_stream export_stream = {
.out_stream.vft = &config_export_vft,
};

static void
config_text_export(char *name, char *val)
{
int name_len = strlen(name);
int val_len = 0;
if (val) {
val_len = strlen(val);
}
ostream_write(&export_stream.out_stream, (const uint8_t *)name, name_len, false);
ostream_write(&export_stream.out_stream, (const uint8_t *)" = ", 3, false);
if (val) {
ostream_write(&export_stream.out_stream, (const uint8_t *)val, val_len, false);
}
ostream_write(&export_stream.out_stream, (const uint8_t *)"\n", 1, false);
}

static uint32_t
config_txt_size(const file_entry_t *file_entry)
{
export_stream.buffer = NULL;
export_stream.buffer_start_offset = 0;
export_stream.buffer_end_offset = 0;
export_stream.write_offset = 0;

conf_export(config_text_export, CONF_EXPORT_SHOW);

return export_stream.write_offset;
}

static void
config_txt_read(const struct file_entry *entry, uint32_t file_sector, uint8_t buffer[512])
{
export_stream.buffer = buffer;
export_stream.buffer_start_offset = 512 * file_sector;
export_stream.buffer_end_offset = export_stream.buffer_start_offset + 512;
export_stream.write_offset = 0;

MSC_FAT_VIEW_LOG_DEBUG("Config.txt read %d\n", file_sector);
conf_export(config_text_export, CONF_EXPORT_SHOW);
}

ROOT_DIR_ENTRY(config_txt, "CONFIG.TXT", FAT_FILE_ENTRY_ATTRIBUTE_READ_ONLY, config_txt_size, config_txt_read, NULL, NULL);
52 changes: 52 additions & 0 deletions hw/usb/tinyusb/msc_fat_view/src/entry_huge_file.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include <stdio.h>
#include <sysflash/sysflash.h>
#include <msc_fat_view/msc_fat_view.h>
#include <bootutil/image.h>

#if MYNEWT_VAL(MSC_FAT_VIEW_HUGE_FILE_SIZE) > 0
#define HUGE_FILE_SIZE MYNEWT_VAL(MSC_FAT_VIEW_HUGE_FILE_SIZE)
#if HUGE_FILE_SIZE > (MYNEWT_VAL(MSC_FAT_VIEW_DISK_SIZE) * 1024) + 2000000
#error HUGE_FILE_SIZE is to big for specified disk size
#endif
#elif (MYNEWT_VAL(MSC_FAT_VIEW_DISK_SIZE) * 1024) < 2000000
#error No space for huge file, increase MSC_FAT_VIEW_DISK_SIZE in syscfg
#else
#define HUGE_FILE_SIZE ((MYNEWT_VAL(MSC_FAT_VIEW_DISK_SIZE) * 1024) - 2000000)
#endif

static uint32_t
huge_file_size(const file_entry_t *file)
{
(void)file;

return HUGE_FILE_SIZE;
}

static void
huge_file_read(const struct file_entry *entry, uint32_t file_sector, uint8_t buffer[512])
{
(void)entry;

memset(buffer, (uint8_t)file_sector, 512);
}

ROOT_DIR_ENTRY(huge_file, "Huge file", FAT_FILE_ENTRY_ATTRIBUTE_READ_ONLY, huge_file_size, huge_file_read, NULL, NULL);
54 changes: 54 additions & 0 deletions hw/usb/tinyusb/msc_fat_view/src/entry_mynewt_htm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include <string.h>
#include <msc_fat_view/msc_fat_view.h>

static const char mynewt_htm_text[] =
"<!-- mynewt Website and Authentication Shortcut -->\n"
"<html>\n"
"<head>\n"
"<meta http-equiv=\"refresh\" content=\"0; url=https://mynewt.apache.org/\"/>\n"
"<title>mynewt Website Shortcut</title>\n"
"</head>\n"
"<body></body>\n"
"</html>";

static uint32_t
mynewt_htm_size(const file_entry_t *file)
{
(void)file;

return strlen(mynewt_htm_text);
}

static void
mynewt_htm_read(const struct file_entry *entry, uint32_t file_sector, uint8_t buffer[512])
{
(void)entry;

if (file_sector == 0) {
strcpy((char *)buffer, mynewt_htm_text);
memset(buffer + 512 - sizeof(mynewt_htm_text), 0, sizeof(mynewt_htm_text));
} else {
memset(buffer, 0, 512);
}
}

ROOT_DIR_ENTRY(mynew_htm, "MYNEWT.HTM", FAT_FILE_ENTRY_ATTRIBUTE_READ_ONLY, mynewt_htm_size, mynewt_htm_read, NULL, NULL);
Loading
Loading