Skip to content

Commit 71f5c18

Browse files
committed
Mynewt support.
1 parent 90b5f3c commit 71f5c18

File tree

10 files changed

+637
-0
lines changed

10 files changed

+637
-0
lines changed

cmd/fs_mgmt/pkg.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
pkg.name: cmd/fs_mgmt
21+
pkg.description: 'File system command handlers for mcumgr.'
22+
pkg.author: "Apache Mynewt <[email protected]>"
23+
pkg.homepage: "http://mynewt.apache.org/"
24+
pkg.keywords:
25+
26+
pkg.deps:
27+
- '@apache-mynewt-core/fs/fs'
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "mgmt/mgmt.h"
21+
#include "fs_mgmt/fs_mgmt_impl.h"
22+
#include "fs/fs.h"
23+
24+
int
25+
fs_mgmt_impl_filelen(const char *path, size_t *out_len)
26+
{
27+
struct fs_file *file;
28+
int rc;
29+
30+
rc = fs_open(path, FS_ACCESS_READ, &file);
31+
if (rc != 0) {
32+
return MGMT_ERR_EUNKNOWN;
33+
}
34+
35+
rc = fs_filelen(file, &out_len);
36+
fs_close(file);
37+
if (rc != 0) {
38+
return MGMT_ERR_EUNKNOWN;
39+
}
40+
41+
return 0;
42+
}
43+
44+
int
45+
fs_mgmt_impl_read(const char *path, size_t offset, size_t len,
46+
void *out_data, size_t *out_len)
47+
{
48+
struct fs_file *file;
49+
uint32_t bytes_read;
50+
int rc;
51+
52+
rc = fs_open(path, FS_ACCESS_READ, &file);
53+
if (rc != 0) {
54+
return MGMT_ERR_EUNKNOWN;
55+
}
56+
57+
rc = fs_seek(file, offset);
58+
if (rc != 0) {
59+
goto done;
60+
}
61+
62+
rc = fs_read(file, len, file_data, &bytes_read);
63+
if (rc != 0) {
64+
goto done;
65+
}
66+
67+
*out_len = bytes_read;
68+
69+
done:
70+
fs_close(file);
71+
72+
if (rc != 0) {
73+
return MGMT_ERR_EUNKNOWN;
74+
}
75+
76+
return 0;
77+
}
78+
79+
int
80+
fs_mgmt_impl_write(const char *path, size_t offset, const void *data,
81+
size_t len)
82+
{
83+
struct fs_file *file;
84+
uint8_t access;
85+
int rc;
86+
87+
access = FS_ACCESS_WRITE;
88+
if (offset == 0) {
89+
access |= FS_ACCESS_TRUNCATE;
90+
} else {
91+
access |= FS_ACCESS_APPEND;
92+
}
93+
94+
rc = fs_open(path, access, &file);
95+
if (rc != 0) {
96+
return MGMT_ERR_EUNKNOWN;
97+
}
98+
99+
rc = fs_write(file, data, len);
100+
fs_close(file);
101+
if (rc != 0) {
102+
return MGMT_ERR_EUNKNOWN;
103+
}
104+
105+
return 0;
106+
}

cmd/fs_mgmt/syscfg.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
syscfg.defs:
21+
FS_MGMT_UL_CHUNK_SIZE:
22+
description: >
23+
Limits the maximum chunk size in file uploads. A buffer of this
24+
size gets allocated on the stack during handling of a file upload
25+
command.
26+
value: 512
27+
28+
FS_MGMT_DL_CHUNK_SIZE:
29+
description: >
30+
Limits the maximum chunk size in file downloads. A buffer of this
31+
size gets allocated on the stack during handling of a file download
32+
command.
33+
value: 512
34+
35+
FS_MGMT_PATH_SIZE:
36+
description: >
37+
Limits the maximum path length in file operations. A buffer of
38+
this size gets allocated on the stack during handling of file
39+
upload and download commands.
40+
value: 64

cmd/img_mgmt/pkg.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
pkg.name: cmd/img_mgmt
21+
pkg.description: 'Image management command handlers for mcumgr.'
22+
pkg.author: "Apache Mynewt <[email protected]>"
23+
pkg.homepage: "http://mynewt.apache.org/"
24+
pkg.keywords:
25+
26+
pkg.deps:
27+
- '@apache-mynewt-core/boot/split'
28+
- '@apache-mynewt-core/encoding/base64'
29+
- '@apache-mynewt-core/sys/flash_map'
30+
- '@mynewt-mcumgr/mgmt'

0 commit comments

Comments
 (0)