-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in rzr/nuttx/sandbox/rzr/review/master (pull request #899)
nucleo-144: Add romfs support Image was generated using genromfs tool. It was successfuly tested on Nucleo-f767zi. Source code is aligned to STM32F4-discovery board with latest fixes (2bfbc23251ef7328b2f1d34a65a47949f08a741c). Thanks-to: Tomasz Wozniak <t.wozniak@samsung.com> Relate-to: https://bitbucket.org/nuttx/nuttx/pull-requests/494/generic-auto-romfs/diff Relate-to: rzr/webthing-iotjs#3 Change-Id: I8dd7e03172307de76d7c0c2c32769683c1298f64 Forwarded: https://bitbucket.org/nuttx/nuttx/pull-requests/899 Signed-off-by: Philippe Coval <p.coval@samsung.com> Approved-by: Gregory Nutt <gnutt@nuttx.org>
- Loading branch information
1 parent
16426d3
commit 9e622bd
Showing
5 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/**************************************************************************** | ||
* configs/nucleo-144/src/stm32_romfs.h | ||
* | ||
* Copyright (C) 2017 Tomasz Wozniak. All rights reserved. | ||
* Author: Tomasz Wozniak <t.wozniak@samsung.com> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* 3. Neither the name NuttX nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
****************************************************************************/ | ||
|
||
#ifndef __CONFIGS_NUCLEO144_SRC_STM32_ROMFS_H | ||
#define __CONFIGS_NUCLEO144_SRC_STM32_ROMFS_H | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
#ifdef CONFIG_STM32_ROMFS | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
#define ROMFS_SECTOR_SIZE 64 | ||
|
||
/**************************************************************************** | ||
* Public Function Prototypes | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: stm32_romfs_initialize | ||
* | ||
* Description: | ||
* Registers built-in ROMFS image as block device and mounts it. | ||
* | ||
* Returned Value: | ||
* Zero (OK) on success, a negated errno value on error. | ||
* | ||
* Assumptions/Limitations: | ||
* Memory addresses [&romfs_data_begin .. &romfs_data_begin) should contain | ||
* ROMFS volume data, as included in the assembly snippet above (l. 84). | ||
* | ||
****************************************************************************/ | ||
|
||
int stm32_romfs_initialize(void); | ||
|
||
#endif /* CONFIG_STM32_ROMFS */ | ||
|
||
#endif /* __CONFIGS_NUCLEO144_SRC_STM32_ROMFS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/***************************************************************************** | ||
* configs/nucleo-144/src/stm32_romfs_initialize.c | ||
* This file provides contents of an optional ROMFS volume, mounted at boot. | ||
* | ||
* Copyright (C) 2017 Tomasz Wozniak. All rights reserved. | ||
* Author: Tomasz Wozniak <t.wozniak@samsung.com> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* 3. Neither the name NuttX nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
****************************************************************************/ | ||
|
||
/***************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
#include <sys/mount.h> | ||
#include <sys/types.h> | ||
#include <stdint.h> | ||
#include <debug.h> | ||
#include <errno.h> | ||
|
||
#include <nuttx/drivers/ramdisk.h> | ||
#include "stm32_romfs.h" | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
#ifndef CONFIG_STM32_ROMFS | ||
# error "CONFIG_STM32_ROMFS must be defined" | ||
#else | ||
|
||
#ifndef CONFIG_STM32_ROMFS_IMAGEFILE | ||
# error "CONFIG_STM32_ROMFS_IMAGEFILE must be defined" | ||
#endif | ||
|
||
#ifndef CONFIG_STM32_ROMFS_DEV_MINOR | ||
# error "CONFIG_STM32_ROMFS_DEV_MINOR must be defined" | ||
#endif | ||
|
||
#ifndef CONFIG_STM32_ROMFS_MOUNTPOINT | ||
# error "CONFIG_STM32_ROMFS_MOUNTPOINT must be defined" | ||
#endif | ||
|
||
#define NSECTORS(size) (((size) + ROMFS_SECTOR_SIZE - 1)/ROMFS_SECTOR_SIZE) | ||
|
||
#define STR2(m) #m | ||
#define STR(m) STR2(m) | ||
|
||
#define MKMOUNT_DEVNAME(m) "/dev/ram" STR(m) | ||
#define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_STM32_ROMFS_DEV_MINOR) | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
__asm__ ( | ||
".section .rodata\n" | ||
".balign 16\n" | ||
".globl romfs_data_begin\n" | ||
"romfs_data_begin:\n" | ||
".incbin " STR(CONFIG_STM32_ROMFS_IMAGEFILE) "\n"\ | ||
\ | ||
".balign " STR(ROMFS_SECTOR_SIZE) "\n" | ||
".globl romfs_data_end\n" | ||
"romfs_data_end:\n" | ||
".globl romfs_data_size\n" | ||
"romfs_data_size:\n" | ||
".word romfs_data_end - romfs_data_begin\n"); | ||
|
||
extern const char romfs_data_begin; | ||
extern const char romfs_data_end; | ||
extern const int romfs_data_size; | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: stm32_romfs_initialize | ||
* | ||
* Description: | ||
* Registers the aboveincluded binary file as block device. | ||
* Then mounts the block device as ROMFS filesystems. | ||
* | ||
* Returned Value: | ||
* Zero (OK) on success, a negated errno value on error. | ||
* | ||
* Assumptions/Limitations: | ||
* Memory addresses [&romfs_data_begin .. &romfs_data_begin) should contain | ||
* ROMFS volume data, as included in the assembly snippet above (l. 84). | ||
* | ||
****************************************************************************/ | ||
|
||
int stm32_romfs_initialize(void) | ||
{ | ||
uintptr_t romfs_data_len; | ||
int ret; | ||
|
||
/* Create a ROM disk for the /etc filesystem */ | ||
|
||
romfs_data_len = (uintptr_t)&romfs_data_end - (uintptr_t)&romfs_data_begin; | ||
|
||
ret = romdisk_register(CONFIG_STM32_ROMFS_DEV_MINOR, &romfs_data_begin, | ||
NSECTORS(romfs_data_len), ROMFS_SECTOR_SIZE); | ||
if (ret < 0) | ||
{ | ||
ferr("ERROR: romdisk_register failed: %d\n", -ret); | ||
return ret; | ||
} | ||
|
||
/* Mount the file system */ | ||
|
||
finfo("Mounting ROMFS filesystem at target=%s with source=%s\n", | ||
CONFIG_STM32_ROMFS_MOUNTPOINT, MOUNT_DEVNAME); | ||
|
||
ret = mount(MOUNT_DEVNAME, CONFIG_STM32_ROMFS_MOUNTPOINT, | ||
"romfs", MS_RDONLY, NULL); | ||
if (ret < 0) | ||
{ | ||
ferr("ERROR: mount(%s,%s,romfs) failed: %d\n", | ||
MOUNT_DEVNAME, CONFIG_STM32_ROMFS_MOUNTPOINT, errno); | ||
return ret; | ||
} | ||
|
||
return OK; | ||
} | ||
|
||
#endif /* CONFIG_STM32_ROMFS */ |