Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
44f9671b
Commit
44f9671b
authored
Apr 21, 2020
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shell: bring back init command
parent
8720372d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
0 deletions
+112
-0
storage.c
dev/storage.c
+111
-0
shell.c
shell/shell.c
+1
-0
No files found.
dev/storage.c
View file @
44f9671b
...
...
@@ -874,6 +874,117 @@ int set_persistent_mac(uint8_t portnum, uint8_t *mac)
return
0
;
}
/*
* The init script area consist of 2-byte size field and a set of
* shell commands separated with '\n' character.
*
* -------------------
* | bytes used (2B) |
* ------------------------------------------------
* | shell commands separated with '\n'..... |
* | |
* | |
* ------------------------------------------------
*/
int
storage_init_erase
(
void
)
{
int
ret
;
if
(
sdbfs_open_id
(
&
wrc_sdbfs
,
SDB_VENDOR
,
SDB_DEV_INIT
)
<
0
)
return
-
1
;
ret
=
sdbfs_ferase
(
&
wrc_sdbfs
,
0
,
wrc_sdbfs
.
f_len
);
if
(
ret
==
wrc_sdbfs
.
f_len
)
ret
=
1
;
sdbfs_close
(
&
wrc_sdbfs
);
return
ret
==
1
?
0
:
-
1
;
}
/*
* Appends a new shell command at the end of boot script
*/
int
storage_init_add
(
const
char
*
args
[])
{
int
len
,
i
;
uint8_t
separator
=
' '
;
uint16_t
used
,
readback
;
int
ret
=
-
1
;
uint8_t
byte
;
if
(
sdbfs_open_id
(
&
wrc_sdbfs
,
SDB_VENDOR
,
SDB_DEV_INIT
)
<
0
)
return
-
1
;
/* check how many bytes we already have there */
used
=
0
;
while
(
sdbfs_fread
(
&
wrc_sdbfs
,
sizeof
(
used
)
+
used
,
&
byte
,
1
)
==
1
)
{
if
(
byte
==
0xff
)
break
;
used
++
;
}
if
(
used
>
256
/* 0xffff or wrong */
)
used
=
0
;
i
=
1
;
/* args[0] is "add" */
while
(
args
[
i
]
!=
NULL
)
{
len
=
strlen
(
args
[
i
]);
if
(
sdbfs_fwrite
(
&
wrc_sdbfs
,
sizeof
(
used
)
+
used
,
(
void
*
)
args
[
i
],
len
)
!=
len
)
goto
out
;
used
+=
len
;
if
(
args
[
i
+
1
]
!=
NULL
)
/* next one is another word of the same command */
separator
=
' '
;
else
/* no more words, end command with '\n' */
separator
=
'\n'
;
if
(
sdbfs_fwrite
(
&
wrc_sdbfs
,
sizeof
(
used
)
+
used
,
&
separator
,
sizeof
(
separator
))
!=
sizeof
(
separator
))
goto
out
;
++
used
;
++
i
;
}
/* and finally update the size of the script */
if
(
sdbfs_fwrite
(
&
wrc_sdbfs
,
0
,
&
used
,
sizeof
(
used
))
!=
sizeof
(
used
))
goto
out
;
if
(
sdbfs_fread
(
&
wrc_sdbfs
,
0
,
&
readback
,
sizeof
(
readback
))
!=
sizeof
(
readback
))
goto
out
;
ret
=
0
;
out:
sdbfs_close
(
&
wrc_sdbfs
);
return
ret
;
}
int
storage_init_show
(
void
)
{
int
ret
=
-
1
;
uint16_t
used
;
uint8_t
byte
;
if
(
sdbfs_open_id
(
&
wrc_sdbfs
,
SDB_VENDOR
,
SDB_DEV_INIT
)
<
0
)
return
-
1
;
pp_printf
(
"-- user-defined script --
\n
"
);
used
=
0
;
do
{
if
(
sdbfs_fread
(
&
wrc_sdbfs
,
sizeof
(
used
)
+
used
,
&
byte
,
1
)
!=
1
)
goto
out
;
if
(
byte
!=
0xff
)
{
pp_printf
(
"%c"
,
byte
);
used
++
;
}
}
while
(
byte
!=
0xff
);
if
(
used
==
0
)
pp_printf
(
"(empty)
\n
"
);
ret
=
0
;
out:
sdbfs_close
(
&
wrc_sdbfs
);
return
ret
;
}
int
storage_init_readcmd
(
uint8_t
*
buf
,
uint8_t
bufsize
,
uint8_t
next
)
{
int
i
=
0
,
ret
=
-
1
;
...
...
shell/shell.c
View file @
44f9671b
...
...
@@ -396,5 +396,6 @@ void shell_register_commands()
REGISTER_WRC_COMMAND
(
calibration
);
REGISTER_WRC_COMMAND
(
help
);
REGISTER_WRC_COMMAND
(
diag
);
REGISTER_WRC_COMMAND
(
init
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment