The O_TRUNC flag has to be ignored when opening devices. Otherwise
cp /somefile /dev/somedev fails. This is broken since:
| commit d4f5bb1e01
| Author: Sascha Hauer <s.hauer@pengutronix.de>
| Date: Sat Sep 28 13:12:50 2013 +0200
|
| copy_file: Add missing O_TRUNC
|
| Without it, when copying a smaller file over a larger file the
| resulting file still has the remaining space from the larger file.
|
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Simple update file format developed for Somfy, tools and library are
available under LGPLv2 (https://www.gitorious.org/libbpk).
This format in the v1.0 allow you to store 6 types a binary stream for
a unique hardware id:
- bootloader
- bootloader_version
- description.gz
- kernel
- rootfs
- firmware_version
and you can easly add more binary stream type.
The fs will display you in a directory per hw id
and if a binary stream type is unknown will be display
as unknown_%08x
# mount image.bpk /tmp
# ls -l /tmp/hw_id_0/
-rwxrwxrwx 10 firmware_version
-rwxrwxrwx 8 firmware_version.crc
-rwxrwxrwx 1845968 kernel
-rwxrwxrwx 8 kernel.crc
-rwxrwxrwx 5062656 rootfs
-rwxrwxrwx 8 rootfs.crc
-rwxrwxrwx 248 bootloader
-rwxrwxrwx 8 bootloader.crc
-rwxrwxrwx 248925 description.gz
-rwxrwxrwx 8 description.gz.crc
-rwxrwxrwx 4 bootloader_version
-rwxrwxrwx 8 bootloader_version.crc
-rwxrwxrwx 4 unknown_1234567g
-rwxrwxrwx 8 unknown_1234567g.crc
Why BPK and not CPIO or uImage
1) CPIO
cpio does not handle > 4GiB image and does not have any crc checksum
2) uImage
uImage only provide one crc32 for the all data part and only a list of binary
stream with no information about what is what (in multi-image format)
3) BPK
BPK provide a crc32 for the header part and one crc32 per binary stream
so if you does not care of some data you are not force to check them
And you known exactly the binary stream type and for which hw to
use it.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Fargier Sylvain <sylvain.fargier@somfy.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
All filesystem drivers which need a backingstore device do the same
ignoring of '/dev/' in the backingstore followed by a cdev_open. Add a
helper function for it and let the core handle the cdev. As a side
effect this makes sure that fsdev->cdev is also set when a device is
mounted without the leading '/dev/' which was previously ignored
by the mount code.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
this will provide the image data and information via file
# ls -l /tmp/
-rwxrwxrwx 3 arch
-rwxrwxrwx 12 compression
-rwxrwxrwx 16 name
-rwxrwxrwx 5 os
-rwxrwxrwx 24 time
-rwxrwxrwx 12 type
-rwxrwxrwx 10 load_addr
-rwxrwxrwx 10 entry_point
-rwxrwxrwx 2199875 data0
-rwxrwxrwx 2199875 data
-rwxrwxrwx 10 data.crc
if it's multi image
# ls -l /tmp-multi/
-rwxrwxrwx 3 arch
-rwxrwxrwx 12 compression
-rwxrwxrwx 16 name
-rwxrwxrwx 5 os
-rwxrwxrwx 24 time
-rwxrwxrwx 16 type
-rwxrwxrwx 10 load_addr
-rwxrwxrwx 10 entry_point
-rwxrwxrwx 1292 data0
-rwxrwxrwx 983 data1
-rwxrwxrwx 2287 data
-rwxrwxrwx 10 data.crc
you can get the image header via an ioctl on any file
UIMAGEFS_METADATA
if you want to check the crc do
# crc32 -f /tmp-multi/data -V /tmp-multi/data.crc
CRC32 for /tmp-multi/data 0x00000000 ... 0x000008ee ==> 0x88d5a0db
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This adds ubifs support from u-boot-2013.07. This is taken
mostly as-is, only the necessary adjustments to attach to the
barebox fs layer have been made.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
cdev_open() opens a cdev by name. This introduces cdev_do_open which
allows to open a cdev when the cdev is already found by other means.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
currently most partition cdevs have the name <devname>.<partname>
This makes it hard to find a partition by <partname>. This introduces
a partname field in struct cdev so that.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Some tftp servers (for example netkit-tftp) do not pass the filesize.
Add a workaround for read_file which reads the file into a temporary
file which then is copied to a buffer.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Some systems are runnignfrom a very limited SRAM, but have a huge
malloc space in SDRAM. The bss normally is in SRAM, so we should
avoid having big structures there. The FILE table is 5120 bytes
big, so allocate it dynamically instead.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Add pread and pwrite functions.
Split read and write functions to save some space.
The functions pread and pwrite saves and sets the file
position to a given offset and restore them afterwards.
This also makes the nandtest command use these function
which is necessary to not break compilation for the nandtest
command.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
When during tftp receive operation a ACK packet can't successfully be sent
the timer was resetted directly after send resulting in a deadlock.
This patch changes the timer reset operation in a way that it is only resetted
when the actually is progress, namely in the TFTP_ACK/TFTP_DATA pathes in the
tftp handler.
Reported-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Tested-by: Antony Pavlov <antonynpavlov@gmail.com>
To make that, we need to shift mtd_erase before mtd_ioctl.
ubi-utils need that, especially ubiformat.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
dev_add_child is a very unsafe function. If called multiple times
it allows setting the same device to different parents thus corrupting
the siblings list. This happens regularly since:
| commit c2e568d19c
| Author: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
| Date: Sat Nov 3 16:11:05 2012 +0100
|
| bus: add bus device
|
| automatically add it as parent of any bus device if none already specified
|
| we have now a nice output per bus
If for example a FATfs is mounted this nice output per bus often ends with:
> `---- fat0
> `---- 0
> `---- 0x86f0000087020031-0x86f000410df27124: /dev/<NULL>
> `---- sram00
> `---- 0x00000000-0xffffffffffffffff: /dev/<NULL>
> `---- 0x00000000-0xffffffffffffffff: /dev/<NULL>
> unable to handle NULL pointer dereference at address 0x0000000c
> pc : [<87f08a20>] lr : [<87f08a04>]
> sp : 86eff8c0 ip : 87f3fbde fp : ffffffff
> r10: ffffffff r9 : 00000000 r8 : 00000003
> r7 : 86f075b8 r6 : 00000002 r5 : ffffffec r4 : 86f07544
> r3 : 00000000 r2 : 43f900b4 r1 : 00000020 r0 : 00000005
> Flags: Nzcv IRQs off FIQs off Mode SVC_32
> [<87f08a20>] (do_devinfo_subtree+0x90/0x130) from [<87f08a90>] (do_devinfo_subtree+0x100/0x130)
>
> [<87f3e070>] (unwind_backtrace+0x0/0x90) from [<87f28514>] (panic+0x28/0x3c)
> [<87f28514>] (panic+0x28/0x3c) from [<87f3e4b8>] (do_exception+0x10/0x14)
> [<87f3e4b8>] (do_exception+0x10/0x14) from [<87f3e544>] (do_data_abort+0x2c/0x38)
> [<87f3e544>] (do_data_abort+0x2c/0x38) from [<87f3e268>] (data_abort+0x48/0x60)
This patch fixes this by adding a device to its parents children list in
register_device so that dev_add_child is no longer needed. This function
is removed from the tree. Now callers of register_device have to clearly
set the parent *before* registering a device.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reported-by: Jan Lübbe <jlu@pengutronix.de>
This patch provides a global cleanup barebox Kconfig files. This includes
replacing spaces to tabs, formatting in accordance format, removing
extraneous lines and spaces. No functional changes.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
The ext4 implementation has been taken from U-Boot with some
changes:
- No global variables to allow for multiple filesystems to
be mounted and multiple files to be open.
- remove fs internal link following and use the barebox link
implementation.
- remove write support. This is incomplete in U-Boot, so I decided
to skip this for now.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
In tftp_read we send a request for a new packet without checking if we
have enough space in the FIFO. This can lead to a FIFO overflow and a
corrupt file. Add a check for it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
tftp_send is called often. Each time, when in STATE_RDATA, a packet
is requested from the tftp server, even if we requested the same packet
already.
Stop this by tracking which packet we requested.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Use filetype to detect FAT boot sector.
Add support for disk with MBR on the first sector.
Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
The FSF address has changed in the past. Instead of updating it
each time the address changes, just drop it completely treewide.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Fix casting on min argument, to avoid warnings on 64bit build.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
For compatibility put a inline on lstat for stat until we have the symlink
support.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
The standard devices are currently broken since they have
the size ~0. As now files use loff_t as file size which is a signed
type the read implementation gets confused and now returns -1.
The current implementation also has the (somewhat theorical) problem
that we do not have real streaming devices, so /dev/zero went out
of zeroes after reading 4GB (or now LLONG_MAX).
This patch introduces a new cdev flag DEVFS_IS_CHARACTER_DEV and a new
file size flag FILE_SIZE_STREAM which makes it possible to create
real stream devices instead.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Storing the size instead of the resource end in struct resource was
a mistake. 'size' ranges from 0 to UINT[32|64]_MAX + 1 which obviously
leads to problems. 'end' on the other hand will never exceed
UINT[32|64]_MAX. Also this way we can express a iomem region covering
the whole address space.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
When creating a file or a directory we have to check if the parent
is actually a directory. Otherwise trying it results in a crash.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
In the Kernel the mtd ioctls expect a pointer to the offset, whereas
barebox interprets the pointer itself as an offset. Since we want
to add 64bit support for file sizes a pointer may not be sufficient,
so align with the kernel and convert it to a pointer to the offset.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
With files smaller than the tftp block size the whole transfer is done
in tftp_do_open already. In this case we are in STATE_DONE, but there
is no error. Set priv->err to 0 and check for it to be able to transfer
small files.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Passing a too large size or offset to erase could
affect flash outside the partition boundary.
Addresses for SPI flash wrap around, thus giving a
count + offset going past the end of the flash would
wrap around and erase flash at offset 0.
Add the same check for protect.
Signed-off-by: Johannes Stezenbach <js@sig21.net>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
"erase /dev/myflash0.mypart 0xf0000+0xf0000" could erase past
the end of the partition.
Signed-off-by: Johannes Stezenbach <js@sig21.net>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
The tftp filesystem support is by no means dependent on the old tftp
support, it depends on NET though.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
The patch making errno a positive value has another bug:
lseek was switched to return -errno instead of -1. This does not
work since we can lseek we can address the whole 4G address space,
have of which has a negative offset when interpreted as a signed
integer. Let lseek return -1 on failure again instead.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Writing big files takes longer and longer because of the chunk list
By storing a pointer of the recent used chunk in the inode, access times are
improved.
Testet on with tftp 10M:
OMAP4 chunk size 4096: 12244ms 8192: 4239ms
patched 2647ms 2785ms
i.MX35 chunk size 8192: 7225ms
patched 2691ms
No impact on much smaller files seen
Signed-off-by: Jan Weitzel <j.weitzel@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This got lost in:
commit 6188685091
Author: Sascha Hauer <s.hauer@pengutronix.de>
Date: Sun May 13 12:43:58 2012 +0200
Make errno a positive value
Normally errno contains a positive error value. A certain unnamed developer
mixed this up while implementing U-Boot-v2. Also, normally errno is never
set to zero by any library function.
This patch fixes this.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This patch adds readonly NFS support. Currently no links are supported.
This is based on the previous U-Boot/NetBSD based code and some Kernel
bits.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Normally errno contains a positive error value. A certain unnamed developer
mixed this up while implementing U-Boot-v2. Also, normally errno is never
set to zero by any library function.
This patch fixes this.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
instead of assuming the backingstore is a ip address, use resolv()
to make it possible to pass in a hostname.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This makes it possible to pass a command sequence to the automount
command instead of only a script (a command sequence would get confused
by the additional argument)
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
- forward the return value of chk_mounted to detect whether mount succeeded
- free resources on mount failure
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
We used to simply answer with -ENOENT in open() when the
initial call to stat() failed. Instead, forward the error from
stat().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This patch adds an automount command which makes it possible
to execute a script when a certain directory is first accessed.
It's the commands responsibility to make this directory available
(bringing devices up and mounting it). This results in automount
support which makes sure that from the shell every file can
be accessed without having to care for device bringup. Bringing
up devices may be expensive (USB, dhcp). The automount support
makes it easy for the environment to bringup devices when they
are actually needed.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
every struct fs_device_d contains a struct mtab_entry, so they
have a 1:1 relationship. Instead of having to use container_of
to get from a struct mtab_entry to a struct fs_device_d we can
better embed the members of struct mtab_entry into struct fs_device_d
directly.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
get_fs_device_by_path returns a struct device_d instead of what the
name suggests a struct fs_device_d. Also it returns the rootpath
of the corresponding fs_device. This patch changes the name of
this function to get_fs_device_and_root_path to better reflect what
the function does and changes the return type to struct fs_device_d.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This adds tftp filesystem support. It currently duplicates
significant amounts of the tftp (command) support. This is ok
since we can eventually drop the original tftp command later.
tftp is not really suitable to be handled as a filesystem. It lacks
support for stat, reading directories and other things. Handling
it as a filesystem has one big advantage though: tftp is no special
case for boot scripts and/or commands anymore which makes them simpler.
This implementation has some improvements to the original tftp command.
It supports blocksize negotiation which speeds up transfers if the tftp
server supports it. Also we can determine the filesize to transfer if
the remote end supports it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>