tools: kwboot: Always call kwboot_img_patch_hdr()
The kwboot_img_patch_hdr() function already decides if header patching is needed. Always call this function and deprecate the unneeded command line option `-p`. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Stefan Roese <sr@denx.de>
This commit is contained in:
@@ -709,9 +709,9 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
kwboot_mmap_image(const char *path, size_t *size, int prot)
|
kwboot_mmap_image(const char *path, size_t *size)
|
||||||
{
|
{
|
||||||
int rc, fd, flags;
|
int rc, fd;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
void *img;
|
void *img;
|
||||||
|
|
||||||
@@ -726,9 +726,7 @@ kwboot_mmap_image(const char *path, size_t *size, int prot)
|
|||||||
if (rc)
|
if (rc)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
flags = (prot & PROT_WRITE) ? MAP_PRIVATE : MAP_SHARED;
|
img = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||||
|
|
||||||
img = mmap(NULL, st.st_size, prot, flags, fd, 0);
|
|
||||||
if (img == MAP_FAILED) {
|
if (img == MAP_FAILED) {
|
||||||
img = NULL;
|
img = NULL;
|
||||||
goto out;
|
goto out;
|
||||||
@@ -833,7 +831,6 @@ kwboot_usage(FILE *stream, char *progname)
|
|||||||
fprintf(stream, "\n");
|
fprintf(stream, "\n");
|
||||||
fprintf(stream,
|
fprintf(stream,
|
||||||
" -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP)\n");
|
" -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP)\n");
|
||||||
fprintf(stream, " -p: patch <image> to type 0x69 (uart boot)\n");
|
|
||||||
fprintf(stream,
|
fprintf(stream,
|
||||||
" -D <image>: boot <image> without preamble (Dove)\n");
|
" -D <image>: boot <image> without preamble (Dove)\n");
|
||||||
fprintf(stream, " -d: enter debug mode\n");
|
fprintf(stream, " -d: enter debug mode\n");
|
||||||
@@ -853,7 +850,7 @@ int
|
|||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *ttypath, *imgpath;
|
const char *ttypath, *imgpath;
|
||||||
int rv, rc, tty, term, prot, patch;
|
int rv, rc, tty, term;
|
||||||
void *bootmsg;
|
void *bootmsg;
|
||||||
void *debugmsg;
|
void *debugmsg;
|
||||||
void *img;
|
void *img;
|
||||||
@@ -867,7 +864,6 @@ main(int argc, char **argv)
|
|||||||
imgpath = NULL;
|
imgpath = NULL;
|
||||||
img = NULL;
|
img = NULL;
|
||||||
term = 0;
|
term = 0;
|
||||||
patch = 0;
|
|
||||||
size = 0;
|
size = 0;
|
||||||
speed = B115200;
|
speed = B115200;
|
||||||
|
|
||||||
@@ -894,7 +890,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
patch = 1;
|
/* nop, for backward compatibility */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
@@ -934,9 +930,6 @@ main(int argc, char **argv)
|
|||||||
if (!bootmsg && !term && !debugmsg)
|
if (!bootmsg && !term && !debugmsg)
|
||||||
goto usage;
|
goto usage;
|
||||||
|
|
||||||
if (patch && !imgpath)
|
|
||||||
goto usage;
|
|
||||||
|
|
||||||
if (argc - optind < 1)
|
if (argc - optind < 1)
|
||||||
goto usage;
|
goto usage;
|
||||||
|
|
||||||
@@ -949,16 +942,12 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (imgpath) {
|
if (imgpath) {
|
||||||
prot = PROT_READ | (patch ? PROT_WRITE : 0);
|
img = kwboot_mmap_image(imgpath, &size);
|
||||||
|
|
||||||
img = kwboot_mmap_image(imgpath, &size, prot);
|
|
||||||
if (!img) {
|
if (!img) {
|
||||||
perror(imgpath);
|
perror(imgpath);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (patch) {
|
|
||||||
rc = kwboot_img_patch_hdr(img, size);
|
rc = kwboot_img_patch_hdr(img, size);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
fprintf(stderr, "%s: Invalid image.\n", imgpath);
|
fprintf(stderr, "%s: Invalid image.\n", imgpath);
|
||||||
|
Reference in New Issue
Block a user