static void *omap_xload_boot_mmc(void) { int ret; void *buf; int len; const char *diskdev; char *partname; diskdev = omap_get_bootmmc_devname(); if (!diskdev) diskdev = "disk0"; device_detect_by_name(diskdev); partname = asprintf("%s.0", diskdev); ret = mount(partname, "fat", "/", NULL); free(partname); if (ret) { printf("Unable to mount %s (%d)\n", partname, ret); return NULL; } buf = read_file("/barebox.bin", &len); if (!buf) { printf("could not read barebox.bin from sd card\n"); return NULL; } return buf; }
static int tqma6x_env_init(void) { void *flash_header_start; void *flash_header_end; if (of_machine_is_compatible("tq,tqma6s")) { flash_header_start = (void *)flash_header_tqma6dl_start; flash_header_end = (void *)flash_header_tqma6dl_end; } else if (of_machine_is_compatible("tq,tqma6q")) { flash_header_start = (void *)flash_header_tqma6q_start; flash_header_end = (void *)flash_header_tqma6q_end; } else { return 0; } devfs_add_partition("m25p0", 0, SZ_512K, DEVFS_PARTITION_FIXED, "m25p0.barebox"); imx6_bbu_internal_spi_i2c_register_handler("spiflash", "/dev/m25p0.barebox", BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_start, flash_header_end - flash_header_start, 0); imx6_bbu_internal_mmc_register_handler("emmc", "/dev/mmc2.boot0", 0, (void *)flash_header_start, flash_header_end - flash_header_start, 0); device_detect_by_name("mmc2"); default_environment_path = "/dev/mmc2.boot1"; return 0; }
static int imx_bbu_internal_mmcboot_update(struct bbu_handler *handler, struct bbu_data *data) { struct bbu_data _data = *data; int ret; char *bootpartvar; const char *bootpart; char *devicefile; const char *devname = devpath_to_name(data->devicefile); ret = device_detect_by_name(devname); if (ret) { pr_err("Couldn't detect device '%s'\n", devname); return ret; } ret = asprintf(&bootpartvar, "%s.boot", devname); if (ret < 0) return ret; bootpart = getenv(bootpartvar); if (!bootpart) { pr_err("Couldn't read the value of '%s'\n", bootpartvar); ret = -ENOENT; goto free_bootpartvar; } if (!strcmp(bootpart, "boot0")) { bootpart = "boot1"; } else { bootpart = "boot0"; } ret = asprintf(&devicefile, "/dev/%s.%s", devname, bootpart); if (ret < 0) goto free_bootpartvar; _data.devicefile = devicefile; ret = imx_bbu_update(handler, &_data); if (ret) goto free_devicefile; /* on success switch boot source */ ret = setenv(bootpartvar, bootpart); free_devicefile: free(devicefile); free_bootpartvar: free(bootpartvar); return ret; }
static int do_detect(int argc, char *argv[]) { struct device_d *dev; int opt, i, ret; int option_list = 0; int option_error = 0; int option_all = 0; while ((opt = getopt(argc, argv, "ela")) > 0) { switch (opt) { case 'l': option_list = 1; break; case 'e': option_error = 1; break; case 'a': option_all = 1; break; default: return COMMAND_ERROR_USAGE; } } if (option_list) { for_each_device(dev) { if (dev->detect) printf("%s\n", dev_name(dev)); } return 0; } if (option_all) { for_each_device(dev) { ret = device_detect(dev); if (ret && ret != -ENOSYS && option_error) return ret; } return 0; } if (argc == optind) return COMMAND_ERROR_USAGE; for (i = optind; i < argc; i++) { ret = device_detect_by_name(argv[i]); if (ret && option_error) return ret; } return 0; }
static int imx_bbu_check_prereq(struct imx_internal_bbu_handler *imx_handler, const char *devicefile, struct bbu_data *data, enum filetype expected_type) { int ret; const void *blob; size_t len; enum filetype type; type = file_detect_type(data->image, data->len); switch (type) { case filetype_arm_barebox: /* * Specifying expected_type as unknown will disable the * inner image type check. * * The only user of this code is * imx_bbu_external_nor_register_handler() used by * i.MX27. */ if (expected_type == filetype_unknown) break; blob = data->image + imx_handler->flash_header_offset; len = data->len - imx_handler->flash_header_offset; type = file_detect_type(blob, len); if (type != expected_type) { pr_err("Expected image type: %s, " "detected image type: %s\n", file_type_to_string(expected_type), file_type_to_string(type)); return -EINVAL; } break; default: if (!bbu_force(data, "Not an ARM barebox image")) return -EINVAL; } ret = bbu_confirm(data); if (ret) return ret; device_detect_by_name(devpath_to_name(devicefile)); return 0; }
static int tqma6x_env_init(void) { if (!of_machine_is_compatible("tq,mba6x")) return 0; devfs_add_partition("m25p0", 0, SZ_512K, DEVFS_PARTITION_FIXED, "m25p0.barebox"); imx6_bbu_internal_spi_i2c_register_handler("spiflash", "/dev/m25p0.barebox", BBU_HANDLER_FLAG_DEFAULT); imx6_bbu_internal_mmc_register_handler("emmc", "/dev/mmc2.boot0", 0); device_detect_by_name("mmc2"); default_environment_path_set("/dev/mmc2.boot1"); barebox_set_hostname("mba6x"); return 0; }
static int gk802_env_init(void) { char *bootsource_name; char *barebox_name; char *default_environment_name; if (!of_machine_is_compatible("zealz,imx6q-gk802")) return 0; /* Keep RTL8192CU disabled */ gpio_direction_output(GK802_GPIO_RTL8192_PDN, 1); gpio_direction_input(GK802_GPIO_RECOVERY_BTN); setenv("recovery", gpio_get_value(GK802_GPIO_RECOVERY_BTN) ? "0" : "1"); if (bootsource_get() != BOOTSOURCE_MMC) return 0; switch (bootsource_get_instance()) { case 2: bootsource_name = "mmc2"; barebox_name = "mmc2.barebox"; default_environment_name = "mmc2.bareboxenv"; default_environment_path = "/dev/mmc2.bareboxenv"; break; case 3: bootsource_name = "mmc3"; barebox_name = "mmc3.barebox"; default_environment_name = "mmc3.bareboxenv"; default_environment_path = "/dev/mmc3.bareboxenv"; break; default: return 0; } device_detect_by_name(bootsource_name); devfs_add_partition(bootsource_name, 0x00000, SZ_512K, DEVFS_PARTITION_FIXED, barebox_name); devfs_add_partition(bootsource_name, SZ_512K, SZ_512K, DEVFS_PARTITION_FIXED, default_environment_name); return 0; }
static int omap_env_init(void) { struct stat s; char *partname; const char *diskdev; int ret; if (bootsource_get() != BOOTSOURCE_MMC) return 0; if (omap_bootmmc_dev) diskdev = omap_bootmmc_dev; else diskdev = "disk0"; device_detect_by_name(diskdev); partname = asprintf("/dev/%s.0", diskdev); ret = stat(partname, &s); free(partname); if (ret) { printf("no %s. using default env\n", diskdev); return 0; } mkdir("/boot", 0666); ret = mount(diskdev, "fat", "/boot", NULL); if (ret) { printf("failed to mount %s\n", diskdev); return 0; } default_environment_path_set("/boot/barebox.env"); return 0; }