kexec: determine size of block device
Subsystems (2)
PATCH 1/1 kexec: determine size of block device
starting 'kexec -l /dev/mmcblk0p1' fails since the size of a block device can not be determined with stat
--- kexec/kexec.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kexec/kexec.c +10 -0
@@ -26,7 +26,9 @@#include <stdlib.h> #include <errno.h> #include <limits.h> +#include <sys/ioctl.h> #include <sys/mman.h> +#include <sys/mount.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/reboot.h>
@@ -554,6 +556,14 @@ char *slurp_file(const char *filename, off_t *r_size)die ("Can not seek to the begin of file %s: %s\n" , filename,strerror (errno)); buf =slurp_fd (fd, filename, size, &nread); + }else if (S_ISBLK (stats.st_mode)) { +/* taken from blockdev */ +unsigned long long llu =-1 ; + err =ioctl (fd,BLKGETSIZE64 , &llu); +if (err <0 ) +die ("Can't retrieve size of block device %s: %s\n" , + filename,strerror (errno)); + size = llu; }else { size = nread = stats.st_size; buf = mmap(NULL, size,
Signature · 7 lines
2.5.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Andreas,
Quoted 2 lines · Andreas Fenkart
starting 'kexec -l
/dev/mmcblk0p1' fails since the size of a block device can not be determined with stat
Could you provide some motivation for kexec reading a kernel image from a block device as per the example above?
Quoted 20 lines
Signed-off-by Andreas Fenkart <[email protected]>--- kexec/kexec.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kexec/kexec.c +2
-0@@ -26,7 +26,9 @@#include <stdlib.h> #include <errno.h> #include <limits.h> +#include <sys/ioctl.h> #include <sys/mman.h> +#include <sys/mount.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/reboot.h>
kexec/kexec.c char *slurp_file(const char *filename, off_t *r_size) · line 560
Quoted 5 lines
kexec/kexec.c +2
-0@@ -554,6 +556,14 @@ char *slurp_file(const char *filename, off_t *r_size)die ("Can not seek to the begin of file %s: %s\n" , filename,strerror (errno)); buf =slurp_fd (fd, filename, size, &nread); + }else if (S_ISBLK (stats.st_mode)) { +/* taken from blockdev */
Is "blockdev" Linux kernel code?
Quoted 18 lines
kexec/kexec.c +6
-0+unsigned long long llu =-1 ; + err =ioctl (fd,BLKGETSIZE64 , &llu); +if (err <0 ) +die ("Can't retrieve size of block device %s: %s\n" , + filename,strerror (errno)); + size = llu; }else { size = nread = stats.st_size; buf = mmap(NULL, size,Signature · 7 lines
2.5.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Simon,
2015-10-16 3:30 GMT+02:00 Simon Horman <[email protected]>:
Quoted 6 lines · Andreas Fenkart
Quoted 2 lines
starting 'kexec -l
/dev/mmcblk0p1' fails since the size of a block device can not be determined with statCould you provide some motivation for kexec reading a kernel image from a block device as per the example above?
We plan to use it for our embedded system
We have an interim initramfs, that selects the kernel we want to boot our real system. Something like a n+1 stage boot loader, where n is the last stage of u-boot. The motivation is to do a safe kernel upgrade on the production rootfs through package management. The new kernel is dropped into a folder where the interim system will selects the kernel with the highest priority. No reconfiguration of u-boot/rescue system needed. In case no kernel has yet been installed, we fall back to the factory default, which is installed in a raw flash partition on eMMC without filesystem.
Quoted 19 lines
Quoted 19 lines
Signed-off-by Andreas Fenkart <[email protected]>--- kexec/kexec.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kexec/kexec.c +2
-0@@ -26,7 +26,9 @@#include <stdlib.h> #include <errno.h> #include <limits.h> +#include <sys/ioctl.h> #include <sys/mman.h> +#include <sys/mount.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/reboot.h>
Quoted 8 lines
kexec/kexec.c char *slurp_file(const char *filename, off_t *r_size) · line 560
Quoted 6 lines
kexec/kexec.c +2
-0@@ -554,6 +556,14 @@ char *slurp_file(const char *filename, off_t *r_size)die ("Can not seek to the begin of file %s: %s\n" , filename,strerror (errno)); buf =slurp_fd (fd, filename, size, &nread); + }else if (S_ISBLK (stats.st_mode)) { +/* taken from blockdev */ Is "blockdev" Linux kernel code?
It is a util-linux tool, which is GPL of course. I added the comment as a reference, since I couldn't find a man page for BLKGETSIZE64. Since it's a straight forward ioctl call, there is probably no copyright violation at all, and I could well remove it.
Quoted 14 lines
Quoted 14 lines
kexec/kexec.c +6
-1+unsigned long long llu =-1 ; + err =ioctl (fd,BLKGETSIZE64 , &llu); +if (err <0 ) +die ("Can't retrieve size of block device %s: %s\n" , + filename,strerror (errno)); + size = llu; }else { size = nread = stats.st_size; buf = mmap(NULL, size, --2.5.1
Quoted 5 lines
Quoted 5 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 22 lines · Andreas Fenkart
Hi Simon,
2015-10-16 3:30 GMT+02:00 Simon Horman <[email protected]>:
Quoted 6 lines · Andreas Fenkart
Quoted 2 lines
starting 'kexec -l
/dev/mmcblk0p1' fails since the size of a block device can not be determined with statCould you provide some motivation for kexec reading a kernel image from a block device as per the example above?
We plan to use it for our embedded system
We have an interim initramfs, that selects the kernel we want to boot our real system. Something like a n+1 stage boot loader, where n is the last stage of u-boot. The motivation is to do a safe kernel upgrade on the production rootfs through package management. The new kernel is dropped into a folder where the interim system will selects the kernel with the highest priority. No reconfiguration of u-boot/rescue system needed. In case no kernel has yet been installed, we fall back to the factory default, which is installed in a raw flash partition on eMMC without filesystem.
Quoted 1 line
Nice :)
Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
Signed-off-by Andreas Fenkart <[email protected]>--- kexec/kexec.c | 10 ++++++++++ 1 file changed, 10 insertions(+)kexec/kexec.c +2
-0@@ -26,7 +26,9 @@#include <stdlib.h> #include <errno.h> #include <limits.h> +#include <sys/ioctl.h> #include <sys/mman.h> +#include <sys/mount.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/reboot.h> Quoted 8 lines
kexec/kexec.c char *slurp_file(const char *filename, off_t *r_size) · line 560
Quoted 6 lines
kexec/kexec.c +2
-0@@ -554,6 +556,14 @@ char *slurp_file(const char *filename, off_t *r_size)die ("Can not seek to the begin of file %s: %s\n" , filename,strerror (errno)); buf =slurp_fd (fd, filename, size, &nread); + }else if (S_ISBLK (stats.st_mode)) { +/* taken from blockdev */ Is "blockdev" Linux kernel code?
Quoted 4 lines
It is a util-linux tool, which is GPL of course. I added the comment as a reference, since I couldn't find a man page for BLKGETSIZE64. Since it's a straight forward ioctl call, there is probably no copyright violation at all, and I could well remove it.
Understood. Could you repost with the blockdev comment removed?
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
kexec/kexec.c +6
-1+unsigned long long llu =-1 ; + err =ioctl (fd,BLKGETSIZE64 , &llu); +if (err <0 ) +die ("Can't retrieve size of block device %s: %s\n" , + filename,strerror (errno)); + size = llu; }else { size = nread = stats.st_size; buf = mmap(NULL, size, --2.5.1
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec