Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scalp_petalinux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
soma
scalp_petalinux
Commits
3bcabb87
Commit
3bcabb87
authored
4 years ago
by
joachim.schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Added a virtfs.sh tool to create file systems for the SD card.
parent
6dc6d1c3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/virtfs.sh~
+0
-108
0 additions, 108 deletions
tools/virtfs.sh~
with
0 additions
and
108 deletions
tools/virtfs.sh~
deleted
100755 → 0
+
0
−
108
View file @
6dc6d1c3
#!/usr/bin/env bash
# Input params.
root_dir_1
=
datafs
root_dir_2
=
rootfs
partition_file_1
=
datafs.ext4
partition_file_2
=
rootfs.ext4
partition_size_1_megs
=
500
partition_size_2_megs
=
28000
img_file
=
virtualfs-ext4.img
block_size
=
512
# Calculated params.
mega
=
"
$(
echo
'2^20'
| bc
)
"
partition_size_1
=
$((
$partition_size_1_megs
*
$mega
))
partition_size_2
=
$((
$partition_size_2_megs
*
$mega
))
# Create a test directory to convert to ext2.
mkdir
-p
"
${
root_dir_1
}
"
echo
content-1
>
"
${
root_dir_1
}
/file-1"
mkdir
-p
"
${
root_dir_2
}
"
echo
content-2
>
"
${
root_dir_2
}
/file-2"
# Create the 2 raw ext2 images.
rm
-f
"
${
partition_file_1
}
"
mke2fs
\
-t
ext4
\
-d
"
${
root_dir_1
}
"
\
-r
1
\
-N
0
\
-m
5
\
-L
''
\
-O
^64bit
\
"
${
partition_file_1
}
"
\
"
${
partition_size_1_megs
}
M"
\
;
rm
-f
"
${
partition_file_2
}
"
mke2fs
\
-t
ext4
\
-d
"
${
root_dir_2
}
"
\
-r
1
\
-N
0
\
-m
5
\
-L
''
\
-O
^64bit
\
"
${
partition_file_2
}
"
\
"
${
partition_size_2_megs
}
M"
\
;
# Default offset according to
part_table_offset
=
$((
2
**
20
))
cur_offset
=
0
bs
=
1024
dd
if
=
/dev/zero
of
=
"
${
img_file
}
"
bs
=
"
${
bs
}
"
count
=
$((
(
${
part_table_offset
}
+
${
partition_size_1
}
+
${
partition_size_2
}
)/
${
bs
}))
skip
=
"
$((${
cur_offset
}
/
${
bs
}))
"
printf
"
type=83, size=
$((${
partition_size_1
}
/
${
block_size
}))
type=83, size=
$((${
partition_size_2
}
/
${
block_size
}))
"
| sfdisk
"
${
img_file
}
"
cur_offset
=
$((${
cur_offset
}
+
${
part_table_offset
}))
# TODO: can we prevent this and use mke2fs directly on the image at an offset?
# Tried -E offset= but could not get it to work.
dd
if
=
"
${
partition_file_1
}
"
of
=
"
${
img_file
}
"
bs
=
"
${
bs
}
"
seek
=
"
$((${
cur_offset
}
/
${
bs
}))
"
cur_offset
=
$((${
cur_offset
}
+
${
partition_size_1
}))
rm
"
${
partition_file_1
}
"
dd
if
=
"
${
partition_file_2
}
"
of
=
"
${
img_file
}
"
bs
=
"
${
bs
}
"
seek
=
"
$((${
cur_offset
}
/
${
bs
}))
"
cur_offset
=
$((${
cur_offset
}
+
${
partition_size_2
}))
rm
"
${
partition_file_2
}
"
# Test the ext2 by mounting it with sudo.
# sudo is only used for testing, the image is completely ready at this point.
# losetup automation functions from:
# https://stackoverflow.com/questions/1419489/how-to-mount-one-partition-from-an-image-file-that-contains-multiple-partitions/39675265#39675265
loop-mount-partitions
()
(
set
-e
img
=
"
$1
"
dev
=
"
$(
sudo
losetup
--show
-f
-P
"
$img
"
)
"
echo
"
${
dev
}
"
|
sed
-E
's/.*[^[:digit:]]([[:digit:]]+$)/\1/g'
for
part
in
"
${
dev
}
p"
*
;
do
if
[
"
${
part
}
"
=
"
${
dev
}
p*"
]
;
then
# Single partition image.
part
=
"
${
dev
}
"
fi
dst
=
"/mnt/
$(
basename
"
${
part
}
"
)
"
echo
"
${
dst
}
"
1>&2
sudo mkdir
-p
"
${
dst
}
"
sudo
mount
"
${
part
}
"
"
${
dst
}
"
done
)
loop-unmount-partitions
()
(
set
-e
for
loop_id
in
"
$@
"
;
do
dev
=
"/dev/loop
${
loop_id
}
"
for
part
in
"
${
dev
}
p"
*
;
do
if
[
"
${
part
}
"
=
"
${
dev
}
p*"
]
;
then
part
=
"
${
dev
}
"
fi
dst
=
"/mnt/
$(
basename
"
${
part
}
"
)
"
sudo
umount
"
${
dst
}
"
done
sudo
losetup
-d
"
${
dev
}
"
done
)
loop_id
=
"
$(
loop-mount-partitions
"
${
img_file
}
"
)
"
#sudo cmp /mnt/loop0p1/file-1 "${root_dir_1}/file-1"
#sudo cmp /mnt/loop0p2/file-2 "${root_dir_2}/file-2"
loop-unmount-partitions
"
${
loop_id
}
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment