コード例 #1
0
ファイル: mkdblk.c プロジェクト: danome/mm
int main(int argc, char **argv) {
    int     c;
    int     err;
    uint8_t buf[MS_BUF_SIZE];
    u32_t   pstart, pend, cstart, cend, dstart, dend;
    int     do_dblk_loc, do_panic0;

    while ((c = getopt_long(argc,argv,"c:d:p:DhvVw", longopts, NULL)) != EOF)
	switch (c) {
	  case 'c':
	      fprintf(stderr, "-c not implemented yet, defaults to 8192\n");
	      break;
	  case 'd':
	      fprintf(stderr, "-d not implemented yet, defaults to 0 (rest of partition\n");
	      break;
	  case 'D':
	      debug++;
	      break;
	  case 'h':
	      usage(argv[0]);
	      break;
	  case 'p':
	      fprintf(stderr, "-c not implemented yet, defaults to 128k\n");
	      break;
	  case 'v':
	      verbose++;
	      break;
	  case 'V':
	      fprintf(stderr, VERSION);
	      exit(0);
	      break;
	  case 'w':
	      do_write++;
	      break;
	  default:
	      usage(argv[0]);
	      break;
	}
    if (optind != argc - 1)
	usage(argv[0]);

    if (verbose)
	fprintf(stderr, VERSION);
    fx_hard_init();
    err = ms_init(argv[optind]);
    if (err == MS_READONLY) {
      fprintf(stderr, "mkdblk: %s is read only\n", argv[optind]);
      err = MS_OK;
      do_write = 0;
    }
    if (err) {
	fprintf(stderr, "ms_init: %s (0x%x)\n", ms_dsp_err(err), err);
	exit(1);
    }
    err = fx_set_buf(buf);
    if (err) {
	fprintf(stderr, "fx_set_buf: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
    }
    err = fx_init();
    if (err) {
	fprintf(stderr, "fx_init: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
    }
    if (!do_write) {
	display_info();
	exit(0);
    }
    do_dblk_loc = 1;
    do_panic0   = !msc.panic0_blk;
    err = fx_create_contig("PANIC001", "   ", panic_size, &pstart, &pend);
    if (err) {
	fprintf(stderr, "fx_create_contig: PANIC001: %s (0x%x)\n", fx_dsp_err(err), err);
	pstart = msc.panic_start;
	pend = msc.panic_end;
	do_dblk_loc = 0;
    }
    err = fx_create_contig("CNFG0001", "   ", config_size, &cstart, &cend);
    if (err) {
	fprintf(stderr, "fx_create_contig: CNFG0001: %s (0x%x)\n", fx_dsp_err(err), err);
	cstart = msc.config_start;
	cend   = msc.config_end;
	do_dblk_loc = 0;
    }
    err = fx_create_contig("DBLK0001", "   ", dblk_size, &dstart, &dend);
    if (err) {
	fprintf(stderr, "fx_create_contig: DBLK0001: %s (0x%x)\n", fx_dsp_err(err), err);
	dstart = msc.dblk_start;
	dend   = msc.dblk_end;
	do_dblk_loc = 0;
    }
    if (do_dblk_loc) {
      fprintf(stderr, "*** writing dblk locator\n");
      err = fx_write_locator(pstart, pend, cstart, cend, dstart, dend);
      if (err) {
	fprintf(stderr, "fx_write_locator: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
      }
      do_panic0 = 1;			/* always write if we wrote the dblk locator */
    }

    if (do_panic0) {
      fprintf(stderr, "*** writing PANIC0 blk\n");
      err = fx_write_panic0(pstart, pend);
      if (err) {
	fprintf(stderr, "fx_write_panic: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
      }
    }

    display_info();

    if (!do_dblk_loc && !do_panic0)
      fprintf(stderr, "*** no changes written\n");

    err = fx_set_buf(NULL);
    if (err) {
	fprintf(stderr, "fx_set_buf: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
    }
    return(0);
}
コード例 #2
0
ファイル: tagfmtsd.c プロジェクト: MamMark/mm
int main(int argc, char **argv) {
    int     c;
    int     err;
    uint8_t buf[MS_BUF_SIZE];
    u32_t   image_size;
    int     do_fs_loc, do_panic0;

    while ((c = getopt_long(argc,argv,"c:d:i:p:DhvVw", longopts, NULL)) != EOF)
	switch (c) {
	  case 'c':
	      fprintf(stderr, "-c not implemented yet, defaults to 8192\n");
	      break;
	  case 'd':
	      fprintf(stderr, "-d not implemented yet, defaults to 0 (rest of partition)\n");
	      break;
	  case 'D':
	      debug++;
	      break;
	  case 'h':
	      usage(argv[0]);
	      break;
	  case 'i':
	      fprintf(stderr, "-i not implemented yet, defaults to 4 slots, 128k each\n");
	      break;
	  case 'p':
	      fprintf(stderr, "-p not implemented yet, defaults to 128k\n");
	      break;
	  case 'v':
	      verbose++;
	      break;
	  case 'V':
	      fprintf(stderr, VERSION);
	      exit(0);
	      break;
	  case 'w':
	      do_write++;
	      break;
	  default:
	      usage(argv[0]);
	      break;
	}
    if (optind != argc - 1)
	usage(argv[0]);

    if (verbose)
	fprintf(stderr, VERSION);
    fx_hard_init();
    err = ms_init(argv[optind]);
    if (err == MS_READONLY) {
      fprintf(stderr, "tagfmtsd: %s is read only\n", argv[optind]);
      err = MS_OK;
      do_write = 0;
    }
    if (err) {
	fprintf(stderr, "ms_init: %s (0x%x)\n", ms_dsp_err(err), err);
	exit(1);
    }
    err = fx_set_buf(buf);
    if (err) {
	fprintf(stderr, "fx_set_buf: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
    }
    err = fx_init();
    if (err) {
	fprintf(stderr, "fx_init: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
    }
    if (!do_write) {
	display_info();
	exit(0);
    }
    do_fs_loc = 1;
    do_panic0   = !msc_panic0_blk;
    err = fx_create_contig("PANIC001", "   ", panic_size,
                           &loc.locators[FS_LOC_PANIC].start,
                           &loc.locators[FS_LOC_PANIC].end);
    if (err) {
	fprintf(stderr, "fx_create_contig: PANIC001: %s (0x%x)\n", fx_dsp_err(err), err);
	do_fs_loc = 0;
    }
    err = fx_create_contig("CNFG0001", "   ", config_size,
                           &loc.locators[FS_LOC_CONFIG].start,
                           &loc.locators[FS_LOC_CONFIG].end);
    if (err) {
	fprintf(stderr, "fx_create_contig: CNFG0001: %s (0x%x)\n", fx_dsp_err(err), err);
	do_fs_loc = 0;
    }

    /*
     * each slot is 128KiB (128 * 1024) bytes + 512, directory sector.
     */
    image_size = img_slots * 128 * 1024 + 512;
    err = fx_create_contig("IMAGE001", "   ", image_size,
                           &loc.locators[FS_LOC_IMAGE].start,
                           &loc.locators[FS_LOC_IMAGE].end);
    if (err) {
	fprintf(stderr, "fx_create_contig: IMAGE001: %s (0x%x)\n", fx_dsp_err(err), err);
	do_fs_loc = 0;
    } else {
    }
    err = fx_create_contig("DBLK0001", "   ", dblk_size,
                           &loc.locators[FS_LOC_DBLK].start,
                           &loc.locators[FS_LOC_DBLK].end);
    if (err) {
	fprintf(stderr, "fx_create_contig: DBLK0001: %s (0x%x)\n", fx_dsp_err(err), err);
	do_fs_loc = 0;
    }
    if (do_fs_loc) {
      fprintf(stderr, "*** writing fs locator\n");
      err = fx_write_locator(&loc);
      if (err) {
	fprintf(stderr, "fx_write_locator: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
      }
      do_panic0 = 1;			/* always write if we wrote the dblk locator */
    }

    if (do_panic0) {
      fprintf(stderr, "*** writing PANIC0 blk\n");
      err = fx_write_panic0(loc.locators[FS_LOC_PANIC].start,
                            loc.locators[FS_LOC_PANIC].end);
      if (err) {
	fprintf(stderr, "fx_write_panic: %s (0x%x)\n", fx_dsp_err(err), err);
	exit(1);
      }
    }

    display_info();

    if (!do_fs_loc && !do_panic0)
      fprintf(stderr, "*** no changes written\n");

    return(0);
}