Exemplo n.º 1
0
int kmain(int argc, char* argv[], uint32_t table) {
	int exit_num = 0;
	unsigned *old_instr1 = 0, *old_instr2 = 0;
	unsigned *old_instr_irq_1 = 0, *old_instr_irq_2 = 0;

	app_startup(); /* bss is valid after this point */
	global_data = table;

	//install the swi custom handler
	install_handler((unsigned int*)0x8, (int)swi_handler, old_instr1, old_instr2);
	//install the irq custom handler
	install_handler((unsigned int*)0x18, (int)irq_handler, old_instr_irq_1, old_instr_irq_2);

	//initiate the interrupt and timer 0
	init_interrupt();
	init_timer0();
	
	//load user program	
	exit_num = load_user(argc, argv);

	//restore the swi system handler
	restore_handler((unsigned int*)0x8, old_instr1, old_instr2);
	//restore the irq system handler
	restore_handler((unsigned int*)0x18, old_instr_irq_1, old_instr_irq_2);

	return exit_num;

}
Exemplo n.º 2
0
int kmain(int argc, char** argv, uint32_t table)
{
	app_startup(); /* bss is valid after this point */
	global_data = table;

	/* Add your code here */


	int status_swi,status_irq,status;	
 	unsigned original_swi_1, original_swi_2,original_irq_1,original_irq_2;  //variables used to store the original swi handler
 	unsigned handler_swi,handler_irq;  // store the address of swi handler
 	unsigned ICMR,ICLR,OIER;

	status_swi = install_handler((unsigned *)EX_SWI,&handler_swi,S_Handler, &original_swi_1,&original_swi_2); //install custom swi handler

	status_irq = install_handler((unsigned *)EX_IRQ,&handler_irq,I_Handler,&original_irq_1,&original_irq_2);

	if(!status_swi && !status_irq){ // if it is a valid load instruction
		
		kernel_time = 0;

		setup_peripheral_device(&ICMR,&ICLR,&OIER);
		
		status=setup(argc,argv); // setup user space
	
		restore_handler((unsigned *)handler_swi,original_swi_1,original_swi_2); // restore original handler

		restore_handler((unsigned *)handler_irq,original_irq_1,original_irq_2);

		restore_peripheral_device(ICMR,ICLR,OIER);

		return status;
	}
	else{ // if it is not a valid load instruction
		printf("Unrecognized instruction.\n");

		return error_status;
	}


}
Exemplo n.º 3
0
int nandroid_restore_partition_extended(const char* backup_path, const char* mount_point, int umount_when_finished) {
    int ret = 0;
    char* name = basename(mount_point);
    
    char tmp[PATH_MAX];
    sprintf(tmp, "%s/%s.img", backup_path, name);
    struct stat file_info;
    if (0 != (ret = statfs(tmp, &file_info))) {
        ui_print("%s.img not found. Skipping restore of %s.\n", name, mount_point);
        return 0;
    }

    ensure_directory(mount_point);

    int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) != 0;

    ui_print("Restoring %s...\n", name);
    /*
    if (0 != (ret = ensure_root_path_unmounted(root))) {
        ui_print("Can't unmount %s!\n", mount_point);
        return ret;
    }
    */
    if (0 != (ret = format_volume(mount_point))) {
        ui_print("Error while formatting %s!\n", mount_point);
        return ret;
    }
    
    if (0 != (ret = ensure_path_mounted(mount_point))) {
        ui_print("Can't mount %s!\n", mount_point);
        return ret;
    }
    
    nandroid_restore_handler restore_handler = get_restore_handler(mount_point);
    if (restore_handler == NULL) {
        ui_print("Error finding an appropriate restore handler.\n");
        return -2;
    }
    if (0 != (ret = restore_handler(tmp, mount_point, callback))) {
        ui_print("Error while restoring %s!\n", mount_point);
        return ret;
    }

    if (umount_when_finished) {
        ensure_path_unmounted(mount_point);
    }
    
    return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
	
 	int status;	
 	unsigned original_1, original_2;  //variables used to store the original swi handler
 	unsigned handler;  // store the address of swi handler

	status = install_swi_handler((unsigned *)vector_entry,&handler,S_Handler, &original_1,&original_2); //install custom swi handler

	if(!status){ // if it is a valid load instruction
		
		status=setup(argc,argv); // setup user space
	
		restore_handler((unsigned *)handler,original_1,original_2); // restore original handler

		return status;
	}
	else{ // if it is not a valid load instruction
		printf("Unrecognized instruction.\n");

		return error_status;
	}
}
Exemplo n.º 5
0
// Main program
int main(int argc, char *argv[])
{
  int option;
  const char *opt_output, *opt_stdout, *opt_stderr;
  bool opt_quiet, opt_batch;
  const char *opt_target;
  int opt_keepalive = -1;

  twopence_command_t cmd;
  struct twopence_target *target;
  struct sigaction old_action;
  twopence_buf_t stdout_buf, stderr_buf;
  twopence_status_t status;
  int rc;

  // Parse options
  opt_output = NULL; opt_stdout = NULL; opt_stderr = NULL;
  opt_quiet = false; opt_batch = false;

  twopence_command_init(&cmd, NULL);

  while ((option = getopt_long(argc, argv, short_options, long_options, NULL))
         != -1) switch(option)         // parse individual options
  {
    case 'u': cmd.user = optarg;
              break;
    case 't': cmd.timeout = atol(optarg);
              break;
    case 'o': opt_output = optarg;
              break;
    case '1': opt_stdout = optarg;
              break;
    case '2': opt_stderr = optarg;
              break;
    case 'q': opt_quiet = true;
              break;
    case 'b': opt_batch = true;
              break;
    case 'd': twopence_debug_level++;
	      break;
    case 'v': printf("%s version 0.3.5\n", argv[0]);
              exit(RC_OK);
    case 'h': usage(argv[0]);
              exit(RC_OK);
    case OPT_KEEPALIVE:
	      if (!strcmp(optarg, "no"))
		opt_keepalive = 0;
	      else
		opt_keepalive = atoi(optarg);
	      break;
    case 'e':
	      {
		char *name = optarg, *value;

		if ((value = strchr(optarg, '=')) != NULL)
		  *value++ = '\0';
		else
		  value = getenv(name);
	        twopence_command_setenv(&cmd, optarg, value);
	      }
	      break;

    invalid_options:
    default: usage(argv[0]);
             exit(RC_INVALID_PARAMETERS);
  }

  if (argc != optind + 2)              // mandatory arguments: target and command
    goto invalid_options;

  opt_target = argv[optind++];
  cmd.command = argv[optind++];

  twopence_command_ostreams_reset(&cmd);
  twopence_command_iostream_redirect(&cmd, TWOPENCE_STDIN, 0, false);

  twopence_buf_init(&stdout_buf);
  twopence_buf_init(&stderr_buf);

  if (opt_quiet) {
    if (opt_output || opt_stdout || opt_stderr) {
      fprintf(stderr, "You cannot use options -o, -1 or -2 with -q\n");
      goto invalid_options;
    }

    /* Output streams are not connected. */
  } else
  if (opt_output) {
    if (opt_stdout || opt_stderr) {
      fprintf(stderr, "You cannot use options -o together with -1 or -2\n");
      goto invalid_options;
    }
    /* Connect both output streams to the same buffer */
    twopence_buf_resize(&stdout_buf, 65536);
    twopence_command_ostream_capture(&cmd, TWOPENCE_STDOUT, &stdout_buf);
    twopence_command_ostream_capture(&cmd, TWOPENCE_STDERR, &stdout_buf);
  } else
  if (opt_stdout || opt_stderr) {
    /* Connect both output streams to separate buffers */
    twopence_buf_resize(&stdout_buf, 65536);
    twopence_command_ostream_capture(&cmd, TWOPENCE_STDOUT, &stdout_buf);
    twopence_buf_resize(&stderr_buf, 65536);
    twopence_command_ostream_capture(&cmd, TWOPENCE_STDERR, &stderr_buf);
  } else {
    /* No output, no -q option. Just send everything to our regular output. */

    /* FIXME: if our stdout and stderr are redirected to the same file,
     * we should merge the standard output of the command on the server
     * side. */

    twopence_command_iostream_redirect(&cmd, TWOPENCE_STDOUT, 1, false);
    twopence_command_iostream_redirect(&cmd, TWOPENCE_STDERR, 2, false);
  }

  // Create target object
  rc = twopence_target_new(opt_target, &target);
  if (rc < 0)
  {
    twopence_perror("Error while initializing library", rc);
    exit(RC_LIBRARY_INIT_ERROR);
  }

  if (opt_keepalive != -1) {
    rc = twopence_target_set_option(target, TWOPENCE_TARGET_OPTION_KEEPALIVE,
		    &opt_keepalive);
    if (rc < 0) {
      twopence_perror("Unable to set connection keepalive", rc);
      exit(RC_LIBRARY_INIT_ERROR);
    }
  }

  // Install signal handler
  twopence_handle = target;
  if (install_handler(SIGINT, &old_action))
  {
    fprintf(stderr, "Error installing signal handler\n");
    twopence_target_free(target);
    exit(RC_SIGNAL_HANDLER_ERROR);
  }

  // Run command
  rc = twopence_run_test(twopence_handle, &cmd, &status);

  if (rc == 0)
  {
    if (!opt_batch)
    {
      printf("Return code from the test server: %d\n", status.major);
      printf("Return code of tested command: %d\n", status.minor);
    }
    if (status.major || status.minor)
      rc = RC_REMOTE_COMMAND_FAILED;
  }
  else
  {
    twopence_perror("Unable to execute command", rc);
    rc = RC_EXEC_COMMAND_ERROR;
  }

  // Restore original signal handler
  if (restore_handler(SIGINT, &old_action))
  {
    fprintf(stderr, "Error removing signal handler\n");
    twopence_target_free(target);
    if (rc == 0) rc = RC_SIGNAL_HANDLER_ERROR;
  }

  // Write captured stdout and stderr to 0, 1, or 2 files
  if (opt_output) {
    if (write_output(opt_output, &stdout_buf) < 0)
      if (rc == 0) rc = RC_WRITE_RESULTS_ERROR;
  } else {
    if (opt_stdout)
      if (write_output(opt_stdout, &stdout_buf) < 0)
        if (rc == 0) rc = RC_WRITE_RESULTS_ERROR;
    if (opt_stderr)
      if (write_output(opt_stderr, &stderr_buf) < 0)
        if (rc == 0) rc = RC_WRITE_RESULTS_ERROR;
  }

  // End library
  twopence_target_free(target);
  return rc;
}
Exemplo n.º 6
0
int nandroid_restore_partition_extended(const char* backup_path, const char* mount_point, int umount_when_finished) {
    int ret = 0;
    char* name = basename(mount_point);

    nandroid_restore_handler restore_handler = NULL;
    const char *filesystems[] = { "yaffs2", "ext2", "ext3", "ext4", "vfat", "rfs", NULL };
    const char* backup_filesystem = NULL;
    Volume *vol = volume_for_path(mount_point);
    const char *device = NULL;
    if (vol != NULL)
        device = vol->device;

    char tmp[PATH_MAX];
    sprintf(tmp, "%s/%s.img", backup_path, name);
    struct stat file_info;
    if (0 != (ret = statfs(tmp, &file_info))) {
        // can't find the backup, it may be the new backup format?
        // iterate through the backup types
        printf("couldn't find old .img format\n");
        char *filesystem;
        int i = 0;
        while ((filesystem = filesystems[i]) != NULL) {
            sprintf(tmp, "%s/%s.%s.img", backup_path, name, filesystem);
            if (0 == (ret = statfs(tmp, &file_info))) {
                backup_filesystem = filesystem;
                restore_handler = unyaffs_wrapper;
                break;
            }
            sprintf(tmp, "%s/%s.%s.tar", backup_path, name, filesystem);
            if (0 == (ret = statfs(tmp, &file_info))) {
                backup_filesystem = filesystem;
                restore_handler = tar_extract_wrapper;
                break;
            }
            sprintf(tmp, "%s/%s.%s.dup", backup_path, name, filesystem);
            if (0 == (ret = statfs(tmp, &file_info))) {
                backup_filesystem = filesystem;
                restore_handler = dedupe_extract_wrapper;
                break;
            }
            i++;
        }

        if (backup_filesystem == NULL || restore_handler == NULL) {
            //ui_print("%s.img not found. Skipping restore of %s.\n", name, mount_point);
            ui_print("No %s backup found(img, tar, dup). Skipping restore of %s.\n", name, mount_point);
            return 0;
        }
        else {
            printf("Found new backup image: %s\n", tmp);
        }

        // If the fs_type of this volume is "auto" or mount_point is /data
        // and is_data_media, let's revert
        // to using a rm -rf, rather than trying to do a
        // ext3/ext4/whatever format.
        // This is because some phones (like DroidX) will freak out if you
        // reformat the /system or /data partitions, and not boot due to
        // a locked bootloader.
        // Other devices, like the Galaxy Nexus, XOOM, and Galaxy Tab 10.1
        // have a /sdcard symlinked to /data/media.
        // Or of volume does not exist (.android_secure), just rm -rf.
        if (vol == NULL || 0 == strcmp(vol->fs_type, "auto"))
            backup_filesystem = NULL;
        if (0 == strcmp(vol->mount_point, "/data") && is_data_media())
            backup_filesystem = NULL;
    }

    ensure_directory(mount_point);

    int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) != 0;
    compute_archive_stats(tmp);

    ui_print("Restoring %s...\n", name);
    if (backup_filesystem == NULL) {
        if (0 != (ret = format_volume(mount_point))) {
            ui_print("Error while formatting %s!\n", mount_point);
            return ret;
        }
    }
    else if (0 != (ret = format_device(device, mount_point, backup_filesystem))) {
        ui_print("Error while formatting %s!\n", mount_point);
        return ret;
    }

    if (0 != (ret = ensure_path_mounted(mount_point))) {
        ui_print("Can't mount %s!\n", mount_point);
        return ret;
    }

    if (restore_handler == NULL)
        restore_handler = get_restore_handler(mount_point);
    if (restore_handler == NULL) {
        ui_print("Error finding an appropriate restore handler.\n");
        return -2;
    }
    if (0 != (ret = restore_handler(tmp, mount_point, callback))) {
        ui_print("Error while restoring %s!\n", mount_point);
        return ret;
    }

    if (umount_when_finished) {
        ensure_path_unmounted(mount_point);
    }
    
    return 0;
}
Exemplo n.º 7
0
int nandroid_restore_partition_extended(const char* backup_path, const char* mount_point, int umount_when_finished) {
    int ret = 0;
    char* name = basename(mount_point);

    nandroid_restore_handler restore_handler = NULL;
    const char *filesystems[] = { "yaffs2", "ext2", "ext3", "ext4", "vfat", "rfs", NULL };
    const char* backup_filesystem = NULL;
    Volume *vol = volume_for_path(mount_point);
    const char *device = NULL;
    if (vol != NULL)
        device = vol->device;

    char tmp[PATH_MAX];
    sprintf(tmp, "%s/%s.img", backup_path, name);
    struct stat file_info;
    if (strcmp(backup_path, "-") == 0) {
        if (vol)
            backup_filesystem = vol->fs_type;
        restore_handler = tar_extract_wrapper;
        strcpy(tmp, "/proc/self/fd/0");
    }
    else if (0 != (ret = statfs(tmp, &file_info))) {
        // can't find the backup, it may be the new backup format?
        // iterate through the backup types
        printf("找不到默认\n");
        char *filesystem;
        int i = 0;
        while ((filesystem = filesystems[i]) != NULL) {
            sprintf(tmp, "%s/%s.%s.img", backup_path, name, filesystem);
            if (0 == (ret = statfs(tmp, &file_info))) {
                backup_filesystem = filesystem;
                restore_handler = unyaffs_wrapper;
                break;
            }
            sprintf(tmp, "%s/%s.%s.tar", backup_path, name, filesystem);
            if (0 == (ret = statfs(tmp, &file_info))) {
                backup_filesystem = filesystem;
                restore_handler = tar_extract_wrapper;
                break;
            }
            sprintf(tmp, "%s/%s.%s.dup", backup_path, name, filesystem);
            if (0 == (ret = statfs(tmp, &file_info))) {
                backup_filesystem = filesystem;
                restore_handler = dedupe_extract_wrapper;
                break;
            }
            i++;
        }

        if (backup_filesystem == NULL || restore_handler == NULL) {
            ui_print("%s.镜像没找到,因此跳过该处恢复. %s.\n", name, mount_point);
            return 0;
        }
        else {
            printf("找到新的可恢复镜像: %s\n", tmp);
        }
    }

    // If the fs_type of this volume is "auto" or mount_point is /data
    // and is_data_media, let's revert
    // to using a rm -rf, rather than trying to do a
    // ext3/ext4/whatever format.
    // This is because some phones (like DroidX) will freak out if you
    // reformat the /system or /data partitions, and not boot due to
    // a locked bootloader.
    // Other devices, like the Galaxy Nexus, XOOM, and Galaxy Tab 10.1
    // have a /sdcard symlinked to /data/media.
    // Or of volume does not exist (.android_secure), just rm -rf.
    if (vol == NULL || 0 == strcmp(vol->fs_type, "auto"))
        backup_filesystem = NULL;
    if (0 == strcmp(vol->mount_point, "/data") && is_data_media())
        backup_filesystem = NULL;

    ensure_directory(mount_point);

    int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) != 0;

    ui_print("正在恢复 %s...\n", name);
    if (backup_filesystem == NULL) {
        if (0 != (ret = format_volume(mount_point))) {
            ui_print("格式化下列分区失败 %s!\n", mount_point);
            return ret;
        }
    }
    else if (0 != (ret = format_device(device, mount_point, backup_filesystem))) {
        ui_print("格式化下列分区失败 %s!\n", mount_point);
        return ret;
    }

    if (0 != (ret = ensure_path_mounted(mount_point))) {
        ui_print("挂载下列分区失败 %s!\n", mount_point);
        return ret;
    }

    if (restore_handler == NULL)
        restore_handler = get_restore_handler(mount_point);

    // override restore handler for undump
    if (strcmp(backup_path, "-") == 0) {
        restore_handler = tar_undump_wrapper;
    }

    if (restore_handler == NULL) {
        ui_print("找不到合适的方案\n");
        return -2;
    }

    if (0 != (ret = restore_handler(tmp, mount_point, callback))) {
        ui_print("恢复失败: %s!\n", mount_point);
        return ret;
    }

    if (umount_when_finished) {
        ensure_path_unmounted(mount_point);
    }

    return 0;
}
Exemplo n.º 8
0
int nandroid_restore_partition_extended(const char* backup_path, const char* mount_point, int umount_when_finished) {
    int ret = 0;
    char* name = basename(mount_point);

    nandroid_restore_handler restore_handler = NULL;
    const char *filesystems[] = { "yaffs2", "ext2", "ext3", "ext4", "vfat", "rfs", NULL };
    const char* backup_filesystem = NULL;
    Volume *vol = volume_for_path(mount_point);
    const char *device = NULL;
    if (vol != NULL)
        device = vol->device;

    char tmp[PATH_MAX];
    sprintf(tmp, "%s/%s.img", backup_path, name);
    struct stat file_info;
    if (0 != (ret = statfs(tmp, &file_info))) {
        // can't find the backup, it may be the new backup format?
        // iterate through the backup types
        printf("couldn't find default\n");
        char *filesystem;
        int i = 0;
        while ((filesystem = filesystems[i]) != NULL) {
            sprintf(tmp, "%s/%s.%s.img", backup_path, name, filesystem);
            if (0 == (ret = statfs(tmp, &file_info))) {
                backup_filesystem = filesystem;
                restore_handler = unyaffs_wrapper;
                break;
            }
            sprintf(tmp, "%s/%s.%s.tar", backup_path, name, filesystem);
            if (0 == (ret = statfs(tmp, &file_info))) {
                backup_filesystem = filesystem;
                restore_handler = tar_extract_wrapper;
                break;
            }
            i++;
        }

        if (backup_filesystem == NULL || restore_handler == NULL) {
            ui_print("%s.img not found. Skipping restore of %s.\n", name, mount_point);
            return 0;
        }
        else {
            printf("Found new backup image: %s\n", tmp);
        }

        // If the fs_type of this volume is "auto", let's revert to using a
        // rm -rf, rather than trying to do a ext3/ext4/whatever format.
        // This is because some phones (like DroidX) will freak out if you
        // reformat the /system or /data partitions, and not boot due to
        // a locked bootloader.
        // The "auto" fs type preserves the file system, and does not
        // trigger that lock.
        // Or of volume does not exist (.android_secure), just rm -rf.
        if (vol == NULL || 0 == strcmp(vol->fs_type, "auto"))
            backup_filesystem = NULL;
    }
    else {
        // Force legacy tar extraction to old CWM2 backup files
        restore_handler = tar_extract_wrapper_legacy;
    }

    ensure_directory(mount_point);

    int callback = stat("/sdcard/clockworkmod/.hidenandroidprogress", &file_info) != 0;

    ui_print("Restoring %s...\n", name);
    if (backup_filesystem == NULL) {
        if (0 != (ret = format_volume(mount_point))) {
            ui_print("Error while formatting %s!\n", mount_point);
            return ret;
        }
    }
    else if (0 != (ret = format_device(device, mount_point, backup_filesystem))) {
        ui_print("Error while formatting %s!\n", mount_point);
        return ret;
    }

    if (0 != (ret = ensure_path_mounted(mount_point))) {
        ui_print("Can't mount %s!\n", mount_point);
        return ret;
    }

    if (restore_handler == NULL)
        restore_handler = get_restore_handler(mount_point);
    if (restore_handler == NULL) {
        ui_print("Error finding an appropriate restore handler.\n");
        return -2;
    }
    if (0 != (ret = restore_handler(tmp, mount_point, callback))) {
        ui_print("Error while restoring %s!\n", mount_point);
        return ret;
    }

    if (umount_when_finished) {
        ensure_path_unmounted(mount_point);
    }
    
    return 0;
}