firmware-utils: allow passing a specific MBR signature to ptgen
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org> SVN-Revision: 42934
This commit is contained in:
parent
4f73613c26
commit
6358368500
1 changed files with 15 additions and 4 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||||
#define cpu_to_le16(x) bswap_16(x)
|
#define cpu_to_le16(x) bswap_16(x)
|
||||||
|
@ -124,7 +125,7 @@ static inline unsigned long round_to_kb(long sect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check the partition sizes and write the partition table */
|
/* check the partition sizes and write the partition table */
|
||||||
static int gen_ptable(int nr)
|
static int gen_ptable(uint32_t signature, int nr)
|
||||||
{
|
{
|
||||||
struct pte pte[4];
|
struct pte pte[4];
|
||||||
unsigned long sect = 0;
|
unsigned long sect = 0;
|
||||||
|
@ -159,6 +160,12 @@ static int gen_ptable(int nr)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lseek(fd, 440, SEEK_SET);
|
||||||
|
if (write(fd, &signature, sizeof(signature)) != sizeof(signature)) {
|
||||||
|
fprintf(stderr, "write failed.\n");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
lseek(fd, 446, SEEK_SET);
|
lseek(fd, 446, SEEK_SET);
|
||||||
if (write(fd, pte, sizeof(struct pte) * 4) != sizeof(struct pte) * 4) {
|
if (write(fd, pte, sizeof(struct pte) * 4) != sizeof(struct pte) * 4) {
|
||||||
fprintf(stderr, "write failed.\n");
|
fprintf(stderr, "write failed.\n");
|
||||||
|
@ -187,8 +194,9 @@ int main (int argc, char **argv)
|
||||||
char type = 0x83;
|
char type = 0x83;
|
||||||
int ch;
|
int ch;
|
||||||
int part = 0;
|
int part = 0;
|
||||||
|
uint32_t signature = 0x5452574F; /* 'OWRT' */
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "h:s:p:a:t:o:vl:")) != -1) {
|
while ((ch = getopt(argc, argv, "h:s:p:a:t:o:vl:S:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'o':
|
case 'o':
|
||||||
filename = optarg;
|
filename = optarg;
|
||||||
|
@ -221,6 +229,9 @@ int main (int argc, char **argv)
|
||||||
case 'l':
|
case 'l':
|
||||||
kb_align = (int) strtoul(optarg, NULL, 0) * 2;
|
kb_align = (int) strtoul(optarg, NULL, 0) * 2;
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
signature = strtoul(optarg, NULL, 0);
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
@ -229,6 +240,6 @@ int main (int argc, char **argv)
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
if (argc || (heads <= 0) || (sectors <= 0) || !filename)
|
if (argc || (heads <= 0) || (sectors <= 0) || !filename)
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
|
|
||||||
return gen_ptable(part);
|
return gen_ptable(signature, part);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue