/* * Precondition: Since this function is called in brcms_pci_probe() context, * no locking is required. */ static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev) { int status; struct device *device = &pdev->dev; char fw_name[100]; int i; memset(&wl->fw, 0, sizeof(struct brcms_firmware)); for (i = 0; i < MAX_FW_IMAGES; i++) { if (brcms_firmwares[i] == NULL) break; sprintf(fw_name, "/*(DEBLOBBED)*/", brcms_firmwares[i], UCODE_LOADER_API_VER); status = reject_firmware(&wl->fw.fw_bin[i], fw_name, device); if (status) { wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n", KBUILD_MODNAME, fw_name); return status; } sprintf(fw_name, "/*(DEBLOBBED)*/", brcms_firmwares[i], UCODE_LOADER_API_VER); status = reject_firmware(&wl->fw.fw_hdr[i], fw_name, device); if (status) { wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n", KBUILD_MODNAME, fw_name); return status; } wl->fw.hdr_num_entries[i] = wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr)); } wl->fw.fw_cnt = i; status = brcms_ucode_data_init(wl, &wl->ucode); brcms_release_fw(wl); return status; }
static int speedtch_find_firmware(struct usbatm_data *usbatm, struct usb_interface *intf, int phase, const struct firmware **fw_p) { struct device *dev = &intf->dev; const u16 bcdDevice = le16_to_cpu(interface_to_usbdev(intf)->descriptor.bcdDevice); const u8 major_revision = bcdDevice >> 8; const u8 minor_revision = bcdDevice & 0xff; char buf[24]; sprintf(buf, "/*(DEBLOBBED)*/", phase, major_revision, minor_revision); usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); if (reject_firmware(fw_p, buf, dev)) { sprintf(buf, "/*(DEBLOBBED)*/", phase, major_revision); usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); if (reject_firmware(fw_p, buf, dev)) { sprintf(buf, "/*(DEBLOBBED)*/", phase); usb_dbg(usbatm, "%s: looking for %s\n", __func__, buf); if (reject_firmware(fw_p, buf, dev)) { usb_err(usbatm, "%s: no stage %d firmware found!\n", __func__, phase); return -ENOENT; } } } usb_info(usbatm, "found stage %d firmware %s\n", phase, buf); return 0; }
static int upload_dsp_code(struct snd_card *card) { struct snd_msnd *chip = card->private_data; const struct firmware *init_fw = NULL, *perm_fw = NULL; int err; outb(HPBLKSEL_0, chip->io + HP_BLKS); err = reject_firmware(&init_fw, INITCODEFILE, card->dev); if (err < 0) { printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE); goto cleanup1; } err = reject_firmware(&perm_fw, PERMCODEFILE, card->dev); if (err < 0) { printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE); goto cleanup; } memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size); if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) { printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n"); err = -ENODEV; goto cleanup; } printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n"); err = 0; cleanup: release_firmware(perm_fw); cleanup1: release_firmware(init_fw); return err; }
static int btrtl_setup_rtl8723b(struct hci_dev *hdev, u16 lmp_subver, const char *fw_name) { unsigned char *fw_data = NULL; const struct firmware *fw; int ret; BT_INFO("%s: rtl: loading %s", hdev->name, fw_name); ret = reject_firmware(&fw, fw_name, &hdev->dev); if (ret < 0) { BT_ERR("%s: Failed to load %s", hdev->name, fw_name); return ret; } ret = rtl8723b_parse_firmware(hdev, lmp_subver, fw, &fw_data); if (ret < 0) goto out; ret = rtl_download_firmware(hdev, fw_data, ret); kfree(fw_data); if (ret < 0) goto out; out: release_firmware(fw); return ret; }
static int btrtl_setup_rtl8723a(struct hci_dev *hdev) { const struct firmware *fw; int ret; BT_INFO("%s: rtl: loading /*(DEBLOBBED)*/", hdev->name); ret = reject_firmware(&fw, "/*(DEBLOBBED)*/", &hdev->dev); if (ret < 0) { BT_ERR("%s: Failed to load /*(DEBLOBBED)*/", hdev->name); return ret; } if (fw->size < 8) { ret = -EINVAL; goto out; } /* Check that the firmware doesn't have the epatch signature * (which is only for RTL8723B and newer). */ if (!memcmp(fw->data, RTL_EPATCH_SIGNATURE, 8)) { BT_ERR("%s: unexpected EPATCH signature!", hdev->name); ret = -EINVAL; goto out; } ret = rtl_download_firmware(hdev, fw->data, fw->size); out: release_firmware(fw); return ret; }
BOOL FIRMWAREbDownload( PSDevice pDevice ) { const struct firmware *fw; int NdisStatus; void *pBuffer = NULL; BOOL result = FALSE; u16 wLength; int ii; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Download firmware\n"); spin_unlock_irq(&pDevice->lock); if (!pDevice->firmware) { struct device *dev = &pDevice->usb->dev; int rc; rc = reject_firmware(&pDevice->firmware, FIRMWARE_NAME, dev); if (rc) { dev_err(dev, "firmware file %s request failed (%d)\n", FIRMWARE_NAME, rc); goto out; } } fw = pDevice->firmware; pBuffer = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL); if (!pBuffer) goto out; for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) { wLength = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE); memcpy(pBuffer, fw->data + ii, wLength); NdisStatus = CONTROLnsRequestOutAsyn(pDevice, 0, 0x1200+ii, 0x0000, wLength, pBuffer ); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Download firmware...%d %zu\n", ii, fw->size); if (NdisStatus != STATUS_SUCCESS) goto out; } result = TRUE; out: kfree(pBuffer); spin_lock_irq(&pDevice->lock); return result; }
/* * Download the firmware into the card, this also does a PCMCIA soft * reset on the card, to make sure it's in a sane state. */ static int symbol_dl_firmware(struct orinoco_private *priv, const struct fw_info *fw) { struct device *dev = priv->dev; int ret; const struct firmware *fw_entry; if (!orinoco_cached_fw_get(priv, true)) { if (reject_firmware(&fw_entry, fw->pri_fw, priv->dev) != 0) { dev_err(dev, "Cannot find firmware: %s\n", fw->pri_fw); return -ENOENT; } } else fw_entry = orinoco_cached_fw_get(priv, true); /* Load primary firmware */ ret = symbol_dl_image(priv, fw, fw_entry->data, fw_entry->data + fw_entry->size, 0); if (!orinoco_cached_fw_get(priv, true)) release_firmware(fw_entry); if (ret) { dev_err(dev, "Primary firmware download failed\n"); return ret; } if (!orinoco_cached_fw_get(priv, false)) { if (reject_firmware(&fw_entry, fw->sta_fw, priv->dev) != 0) { dev_err(dev, "Cannot find firmware: %s\n", fw->sta_fw); return -ENOENT; } } else fw_entry = orinoco_cached_fw_get(priv, false); /* Load secondary firmware */ ret = symbol_dl_image(priv, fw, fw_entry->data, fw_entry->data + fw_entry->size, 1); if (!orinoco_cached_fw_get(priv, false)) release_firmware(fw_entry); if (ret) dev_err(dev, "Secondary firmware download failed\n"); return ret; }
int adf_ae_fw_load(struct adf_accel_dev *accel_dev) { struct adf_fw_loader_data *loader_data = accel_dev->fw_loader; struct adf_hw_device_data *hw_device = accel_dev->hw_device; void *uof_addr, *mmp_addr; u32 uof_size, mmp_size; if (!hw_device->fw_name) return 0; if (reject_firmware(&loader_data->mmp_fw, hw_device->fw_mmp_name, &accel_dev->accel_pci_dev.pci_dev->dev)) { dev_err(&GET_DEV(accel_dev), "Failed to load MMP firmware %s\n", hw_device->fw_mmp_name); return -EFAULT; } if (reject_firmware(&loader_data->uof_fw, hw_device->fw_name, &accel_dev->accel_pci_dev.pci_dev->dev)) { dev_err(&GET_DEV(accel_dev), "Failed to load UOF firmware %s\n", hw_device->fw_name); goto out_err; } uof_size = loader_data->uof_fw->size; uof_addr = (void *)loader_data->uof_fw->data; mmp_size = loader_data->mmp_fw->size; mmp_addr = (void *)loader_data->mmp_fw->data; qat_uclo_wr_mimage(loader_data->fw_loader, mmp_addr, mmp_size); if (qat_uclo_map_uof_obj(loader_data->fw_loader, uof_addr, uof_size)) { dev_err(&GET_DEV(accel_dev), "Failed to map UOF\n"); goto out_err; } if (qat_uclo_wr_all_uimage(loader_data->fw_loader)) { dev_err(&GET_DEV(accel_dev), "Failed to load UOF\n"); goto out_err; } return 0; out_err: adf_ae_fw_release(accel_dev); return -EFAULT; }
void orinoco_cache_fw(struct orinoco_private *priv, int ap) { const struct firmware *fw_entry = NULL; const char *pri_fw; const char *fw; pri_fw = orinoco_fw[priv->firmware_type].pri_fw; if (ap) fw = orinoco_fw[priv->firmware_type].ap_fw; else fw = orinoco_fw[priv->firmware_type].sta_fw; if (pri_fw) { if (reject_firmware(&fw_entry, pri_fw, priv->dev) == 0) priv->cached_pri_fw = fw_entry; } if (fw) { if (reject_firmware(&fw_entry, fw, priv->dev) == 0) priv->cached_fw = fw_entry; } }
/** * cik_sdma_init_microcode - load ucode images from disk * * @adev: amdgpu_device pointer * * Use the firmware interface to load the ucode images into * the driver (not loaded into hw). * Returns 0 on success, error on failure. */ static int cik_sdma_init_microcode(struct amdgpu_device *adev) { const char *chip_name; char fw_name[30]; int err = 0, i; DRM_DEBUG("\n"); switch (adev->asic_type) { case CHIP_BONAIRE: chip_name = "bonaire"; break; case CHIP_HAWAII: chip_name = "hawaii"; break; case CHIP_KAVERI: chip_name = "kaveri"; break; case CHIP_KABINI: chip_name = "kabini"; break; case CHIP_MULLINS: chip_name = "mullins"; break; default: BUG(); } for (i = 0; i < adev->sdma.num_instances; i++) { if (i == 0) snprintf(fw_name, sizeof(fw_name), "/*(DEBLOBBED)*/", chip_name); else snprintf(fw_name, sizeof(fw_name), "/*(DEBLOBBED)*/", chip_name); err = reject_firmware(&adev->sdma.instance[i].fw, fw_name, adev->dev); if (err) goto out; err = amdgpu_ucode_validate(adev->sdma.instance[i].fw); } out: if (err) { printk(KERN_ERR "cik_sdma: Failed to load firmware \"%s\"\n", fw_name); for (i = 0; i < adev->sdma.num_instances; i++) { release_firmware(adev->sdma.instance[i].fw); adev->sdma.instance[i].fw = NULL; } } return err; }
static int iceland_dpm_init_microcode(struct amdgpu_device *adev) { char fw_name[30] = "/*(DEBLOBBED)*/"; int err; err = reject_firmware(&adev->pm.fw, fw_name, adev->dev); if (err) goto out; err = amdgpu_ucode_validate(adev->pm.fw); out: if (err) { DRM_ERROR("Failed to load firmware \"%s\"", fw_name); release_firmware(adev->pm.fw); adev->pm.fw = NULL; } return err; }
static int bnad_flash_device(struct net_device *netdev, struct ethtool_flash *eflash) { struct bnad *bnad = netdev_priv(netdev); struct bnad_iocmd_comp fcomp; const struct firmware *fw; int ret = 0; ret = reject_firmware(&fw, eflash->data, &bnad->pcidev->dev); if (ret) { pr_err("BNA: Can't locate firmware %s\n", eflash->data); goto out; } fcomp.bnad = bnad; fcomp.comp_status = 0; init_completion(&fcomp.comp); spin_lock_irq(&bnad->bna_lock); ret = bfa_nw_flash_update_part(&bnad->bna.flash, BFA_FLASH_PART_FWIMG, bnad->id, (u8 *)fw->data, fw->size, 0, bnad_cb_completion, &fcomp); if (ret != BFA_STATUS_OK) { pr_warn("BNA: Flash update failed with err: %d\n", ret); ret = -EIO; spin_unlock_irq(&bnad->bna_lock); goto out; } spin_unlock_irq(&bnad->bna_lock); wait_for_completion(&fcomp.comp); if (fcomp.comp_status != BFA_STATUS_OK) { ret = -EIO; pr_warn("BNA: Firmware image update to flash failed with: %d\n", fcomp.comp_status); } out: release_firmware(fw); return ret; }
static int rt2x00lib_reject_firmware(struct rt2x00_dev *rt2x00dev) { struct device *device = wiphy_dev(rt2x00dev->hw->wiphy); const struct firmware *fw; char *fw_name; int retval; /* * Read correct firmware from harddisk. */ fw_name = rt2x00dev->ops->lib->get_firmware_name(rt2x00dev); if (!fw_name) { rt2x00_err(rt2x00dev, "Invalid firmware filename\n" "Please file bug report to %s\n", DRV_PROJECT); return -EINVAL; } rt2x00_info(rt2x00dev, "Loading firmware file '%s'\n", fw_name); retval = reject_firmware(&fw, fw_name, device); if (retval) { rt2x00_err(rt2x00dev, "Failed to request Firmware\n"); return retval; } if (!fw || !fw->size || !fw->data) { rt2x00_err(rt2x00dev, "Failed to read Firmware\n"); release_firmware(fw); return -ENOENT; } rt2x00_info(rt2x00dev, "Firmware detected - version: %d.%d\n", fw->data[fw->size - 4], fw->data[fw->size - 3]); snprintf(rt2x00dev->hw->wiphy->fw_version, sizeof(rt2x00dev->hw->wiphy->fw_version), "%d.%d", fw->data[fw->size - 4], fw->data[fw->size - 3]); retval = rt2x00dev->ops->lib->check_firmware(rt2x00dev, fw->data, fw->size); switch (retval) { case FW_OK: break; case FW_BAD_CRC: rt2x00_err(rt2x00dev, "Firmware checksum error\n"); goto exit; case FW_BAD_LENGTH: rt2x00_err(rt2x00dev, "Invalid firmware file length (len=%zu)\n", fw->size); goto exit; case FW_BAD_VERSION: rt2x00_err(rt2x00dev, "Current firmware does not support detected chipset\n"); goto exit; } rt2x00dev->fw = fw; return 0; exit: release_firmware(fw); return -ENOENT; }
static int __devinit setup_instance(struct sfax_hw *card) { const struct firmware *firmware; int i, err; u_long flags; snprintf(card->name, MISDN_MAX_IDLEN - 1, "Speedfax.%d", sfax_cnt + 1); write_lock_irqsave(&card_lock, flags); list_add_tail(&card->list, &Cards); write_unlock_irqrestore(&card_lock, flags); _set_debug(card); spin_lock_init(&card->lock); card->isac.hwlock = &card->lock; card->isar.hwlock = &card->lock; card->isar.ctrl = (void *)&sfax_ctrl; card->isac.name = card->name; card->isar.name = card->name; card->isar.owner = THIS_MODULE; err = reject_firmware(&firmware, "/*(DEBLOBBED)*/", &card->pdev->dev); if (err < 0) { pr_info("%s: firmware request failed %d\n", card->name, err); goto error_fw; } if (debug & DEBUG_HW) pr_notice("%s: got firmware %zu bytes\n", card->name, firmware->size); mISDNisac_init(&card->isac, card); card->isac.dch.dev.D.ctrl = sfax_dctrl; card->isac.dch.dev.Bprotocols = mISDNisar_init(&card->isar, card); for (i = 0; i < 2; i++) { set_channelmap(i + 1, card->isac.dch.dev.channelmap); list_add(&card->isar.ch[i].bch.ch.list, &card->isac.dch.dev.bchannels); } err = setup_speedfax(card); if (err) goto error_setup; err = card->isar.init(&card->isar); if (err) goto error; err = mISDN_register_device(&card->isac.dch.dev, &card->pdev->dev, card->name); if (err) goto error; err = init_card(card); if (err) goto error_init; err = card->isar.firmware(&card->isar, firmware->data, firmware->size); if (!err) { release_firmware(firmware); sfax_cnt++; pr_notice("SpeedFax %d cards installed\n", sfax_cnt); return 0; } disable_hwirq(card); free_irq(card->irq, card); error_init: mISDN_unregister_device(&card->isac.dch.dev); error: release_region(card->cfg, 256); error_setup: card->isac.release(&card->isac); card->isar.release(&card->isar); release_firmware(firmware); error_fw: pci_disable_device(card->pdev); write_lock_irqsave(&card_lock, flags); list_del(&card->list); write_unlock_irqrestore(&card_lock, flags); kfree(card); return err; }
static int wm0010_stage2_load(struct snd_soc_codec *codec) { struct spi_device *spi = to_spi_device(codec->dev); struct wm0010_priv *wm0010 = snd_soc_codec_get_drvdata(codec); const struct firmware *fw; struct spi_message m; struct spi_transfer t; u32 *img; u8 *out; int i; int ret = 0; ret = reject_firmware(&fw, "/*(DEBLOBBED)*/", codec->dev); if (ret != 0) { dev_err(codec->dev, "Failed to request stage2 loader: %d\n", ret); return ret; } dev_dbg(codec->dev, "Downloading %zu byte stage 2 loader\n", fw->size); /* Copy to local buffer first as vmalloc causes problems for dma */ img = kzalloc(fw->size, GFP_KERNEL | GFP_DMA); if (!img) { dev_err(codec->dev, "Failed to allocate image buffer\n"); ret = -ENOMEM; goto abort2; } out = kzalloc(fw->size, GFP_KERNEL | GFP_DMA); if (!out) { dev_err(codec->dev, "Failed to allocate output buffer\n"); ret = -ENOMEM; goto abort1; } memcpy(img, &fw->data[0], fw->size); spi_message_init(&m); memset(&t, 0, sizeof(t)); t.rx_buf = out; t.tx_buf = img; t.len = fw->size; t.bits_per_word = 8; t.speed_hz = wm0010->sysclk / 10; spi_message_add_tail(&t, &m); dev_dbg(codec->dev, "Starting initial download at %dHz\n", t.speed_hz); ret = spi_sync(spi, &m); if (ret != 0) { dev_err(codec->dev, "Initial download failed: %d\n", ret); goto abort; } /* Look for errors from the boot ROM */ for (i = 0; i < fw->size; i++) { if (out[i] != 0x55) { dev_err(codec->dev, "Boot ROM error: %x in %d\n", out[i], i); wm0010_mark_boot_failure(wm0010); ret = -EBUSY; goto abort; } } abort: kfree(out); abort1: kfree(img); abort2: release_firmware(fw); return ret; }
static int wm2000_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *i2c_id) { struct wm2000_priv *wm2000; struct wm2000_platform_data *pdata; const char *filename; const struct firmware *fw = NULL; int ret, i; int reg; u16 id; wm2000 = devm_kzalloc(&i2c->dev, sizeof(struct wm2000_priv), GFP_KERNEL); if (wm2000 == NULL) { dev_err(&i2c->dev, "Unable to allocate private data\n"); return -ENOMEM; } mutex_init(&wm2000->lock); dev_set_drvdata(&i2c->dev, wm2000); wm2000->regmap = devm_regmap_init_i2c(i2c, &wm2000_regmap); if (IS_ERR(wm2000->regmap)) { ret = PTR_ERR(wm2000->regmap); dev_err(&i2c->dev, "Failed to allocate register map: %d\n", ret); goto out; } for (i = 0; i < WM2000_NUM_SUPPLIES; i++) wm2000->supplies[i].supply = wm2000_supplies[i]; ret = devm_regulator_bulk_get(&i2c->dev, WM2000_NUM_SUPPLIES, wm2000->supplies); if (ret != 0) { dev_err(&i2c->dev, "Failed to get supplies: %d\n", ret); return ret; } ret = regulator_bulk_enable(WM2000_NUM_SUPPLIES, wm2000->supplies); if (ret != 0) { dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); return ret; } /* Verify that this is a WM2000 */ reg = wm2000_read(i2c, WM2000_REG_ID1); id = reg << 8; reg = wm2000_read(i2c, WM2000_REG_ID2); id |= reg & 0xff; if (id != 0x2000) { dev_err(&i2c->dev, "Device is not a WM2000 - ID %x\n", id); ret = -ENODEV; goto err_supplies; } reg = wm2000_read(i2c, WM2000_REG_REVISON); dev_info(&i2c->dev, "revision %c\n", reg + 'A'); wm2000->mclk = devm_clk_get(&i2c->dev, "MCLK"); if (IS_ERR(wm2000->mclk)) { ret = PTR_ERR(wm2000->mclk); dev_err(&i2c->dev, "Failed to get MCLK: %d\n", ret); goto err_supplies; } filename = "/*(DEBLOBBED)*/"; pdata = dev_get_platdata(&i2c->dev); if (pdata) { wm2000->speech_clarity = !pdata->speech_enh_disable; if (pdata->download_file) filename = pdata->download_file; } ret = reject_firmware(&fw, filename, &i2c->dev); if (ret != 0) { dev_err(&i2c->dev, "Failed to acquire ANC data: %d\n", ret); goto err_supplies; } /* Pre-cook the concatenation of the register address onto the image */ wm2000->anc_download_size = fw->size + 2; wm2000->anc_download = devm_kzalloc(&i2c->dev, wm2000->anc_download_size, GFP_KERNEL); if (wm2000->anc_download == NULL) { dev_err(&i2c->dev, "Out of memory\n"); ret = -ENOMEM; goto err_supplies; } wm2000->anc_download[0] = 0x80; wm2000->anc_download[1] = 0x00; memcpy(wm2000->anc_download + 2, fw->data, fw->size); wm2000->anc_eng_ena = 1; wm2000->anc_active = 1; wm2000->spk_ena = 1; wm2000->i2c = i2c; wm2000_reset(wm2000); ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm2000, NULL, 0); err_supplies: regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies); out: release_firmware(fw); return ret; }
/* Download either STA or AP firmware into the card. */ static int orinoco_dl_firmware(struct orinoco_private *priv, const struct fw_info *fw, int ap) { /* Plug Data Area (PDA) */ __le16 *pda; struct hermes *hw = &priv->hw; const struct firmware *fw_entry; const struct orinoco_fw_header *hdr; const unsigned char *first_block; const void *end; const char *firmware; const char *fw_err; struct device *dev = priv->dev; int err = 0; pda = kzalloc(fw->pda_size, GFP_KERNEL); if (!pda) return -ENOMEM; if (ap) firmware = fw->ap_fw; else firmware = fw->sta_fw; dev_dbg(dev, "Attempting to download firmware %s\n", firmware); /* Read current plug data */ err = hw->ops->read_pda(hw, pda, fw->pda_addr, fw->pda_size); dev_dbg(dev, "Read PDA returned %d\n", err); if (err) goto free; if (!orinoco_cached_fw_get(priv, false)) { err = reject_firmware(&fw_entry, firmware, priv->dev); if (err) { dev_err(dev, "Cannot find firmware %s\n", firmware); err = -ENOENT; goto free; } } else fw_entry = orinoco_cached_fw_get(priv, false); hdr = (const struct orinoco_fw_header *) fw_entry->data; fw_err = validate_fw(hdr, fw_entry->size); if (fw_err) { dev_warn(dev, "Invalid firmware image detected (%s). " "Aborting download\n", fw_err); err = -EINVAL; goto abort; } /* Enable aux port to allow programming */ err = hw->ops->program_init(hw, le32_to_cpu(hdr->entry_point)); dev_dbg(dev, "Program init returned %d\n", err); if (err != 0) goto abort; /* Program data */ first_block = (fw_entry->data + le16_to_cpu(hdr->headersize) + le32_to_cpu(hdr->block_offset)); end = fw_entry->data + fw_entry->size; err = hermes_program(hw, first_block, end); dev_dbg(dev, "Program returned %d\n", err); if (err != 0) goto abort; /* Update production data */ first_block = (fw_entry->data + le16_to_cpu(hdr->headersize) + le32_to_cpu(hdr->pdr_offset)); err = hermes_apply_pda_with_defaults(hw, first_block, end, pda, &pda[fw->pda_size / sizeof(*pda)]); dev_dbg(dev, "Apply PDA returned %d\n", err); if (err) goto abort; /* Tell card we've finished */ err = hw->ops->program_end(hw); dev_dbg(dev, "Program end returned %d\n", err); if (err != 0) goto abort; /* Check if we're running */ dev_dbg(dev, "hermes_present returned %d\n", hermes_present(hw)); abort: /* If we requested the firmware, release it. */ if (!orinoco_cached_fw_get(priv, false)) release_firmware(fw_entry); free: kfree(pda); return err; }
static int wm0010_firmware_load(const char *name, struct snd_soc_codec *codec) { struct spi_device *spi = to_spi_device(codec->dev); struct wm0010_priv *wm0010 = snd_soc_codec_get_drvdata(codec); struct list_head xfer_list; struct wm0010_boot_xfer *xfer; int ret; struct completion done; const struct firmware *fw; const struct dfw_binrec *rec; const struct dfw_inforec *inforec; u64 *img; u8 *out, dsp; u32 len, offset; INIT_LIST_HEAD(&xfer_list); ret = reject_firmware(&fw, name, codec->dev); if (ret != 0) { dev_err(codec->dev, "Failed to request application(%s): %d\n", name, ret); return ret; } rec = (const struct dfw_binrec *)fw->data; inforec = (const struct dfw_inforec *)rec->data; offset = 0; dsp = inforec->dsp_target; wm0010->boot_failed = false; BUG_ON(!list_empty(&xfer_list)); init_completion(&done); /* First record should be INFO */ if (rec->command != DFW_CMD_INFO) { dev_err(codec->dev, "First record not INFO\r\n"); ret = -EINVAL; goto abort; } if (inforec->info_version != INFO_VERSION) { dev_err(codec->dev, "Unsupported version (%02d) of INFO record\r\n", inforec->info_version); ret = -EINVAL; goto abort; } dev_dbg(codec->dev, "Version v%02d INFO record found\r\n", inforec->info_version); /* Check it's a DSP file */ if (dsp != DEVICE_ID_WM0010) { dev_err(codec->dev, "Not a WM0010 firmware file.\r\n"); ret = -EINVAL; goto abort; } /* Skip the info record as we don't need to send it */ offset += ((rec->length) + 8); rec = (void *)&rec->data[rec->length]; while (offset < fw->size) { dev_dbg(codec->dev, "Packet: command %d, data length = 0x%x\r\n", rec->command, rec->length); len = rec->length + 8; xfer = kzalloc(sizeof(*xfer), GFP_KERNEL); if (!xfer) { dev_err(codec->dev, "Failed to allocate xfer\n"); ret = -ENOMEM; goto abort; } xfer->codec = codec; list_add_tail(&xfer->list, &xfer_list); out = kzalloc(len, GFP_KERNEL | GFP_DMA); if (!out) { dev_err(codec->dev, "Failed to allocate RX buffer\n"); ret = -ENOMEM; goto abort1; } xfer->t.rx_buf = out; img = kzalloc(len, GFP_KERNEL | GFP_DMA); if (!img) { dev_err(codec->dev, "Failed to allocate image buffer\n"); ret = -ENOMEM; goto abort1; } xfer->t.tx_buf = img; byte_swap_64((u64 *)&rec->command, img, len); spi_message_init(&xfer->m); xfer->m.complete = wm0010_boot_xfer_complete; xfer->m.context = xfer; xfer->t.len = len; xfer->t.bits_per_word = 8; if (!wm0010->pll_running) { xfer->t.speed_hz = wm0010->sysclk / 6; } else { xfer->t.speed_hz = wm0010->max_spi_freq; if (wm0010->board_max_spi_speed && (wm0010->board_max_spi_speed < wm0010->max_spi_freq)) xfer->t.speed_hz = wm0010->board_max_spi_speed; } /* Store max usable spi frequency for later use */ wm0010->max_spi_freq = xfer->t.speed_hz; spi_message_add_tail(&xfer->t, &xfer->m); offset += ((rec->length) + 8); rec = (void *)&rec->data[rec->length]; if (offset >= fw->size) { dev_dbg(codec->dev, "All transfers scheduled\n"); xfer->done = &done; } ret = spi_async(spi, &xfer->m); if (ret != 0) { dev_err(codec->dev, "Write failed: %d\n", ret); goto abort1; } if (wm0010->boot_failed) { dev_dbg(codec->dev, "Boot fail!\n"); ret = -EINVAL; goto abort1; } } wait_for_completion(&done); ret = 0; abort1: while (!list_empty(&xfer_list)) { xfer = list_first_entry(&xfer_list, struct wm0010_boot_xfer, list); kfree(xfer->t.rx_buf); kfree(xfer->t.tx_buf); list_del(&xfer->list); kfree(xfer); } abort: release_firmware(fw); return ret; }
/* steps to download the firmware to the WhiteHEAT device: - hold the reset (by writing to the reset bit of the CPUCS register) - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD - release the reset (by writing to the CPUCS register) - download the WH.HEX file for all addresses greater than 0x1b3f using VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD - hold the reset - download the WH.HEX file for all addresses less than 0x1b40 using VENDOR_REQUEST_ANCHOR_LOAD - release the reset - device renumerated itself and comes up as new device id with all firmware download completed. */ static int whiteheat_firmware_download(struct usb_serial *serial, const struct usb_device_id *id) { int response, ret = -ENOENT; const struct firmware *loader_fw = NULL, *firmware_fw = NULL; const struct ihex_binrec *record; if (reject_firmware(&firmware_fw, "/*(DEBLOBBED)*/", &serial->dev->dev)) { dev_err(&serial->dev->dev, "%s - request \"/*(DEBLOBBED)*/\" failed\n", __func__); goto out; } if (reject_firmware(&loader_fw, "/*(DEBLOBBED)*/", &serial->dev->dev)) { dev_err(&serial->dev->dev, "%s - request \"/*(DEBLOBBED)*/\" failed\n", __func__); goto out; } ret = 0; response = ezusb_set_reset (serial, 1); record = (const struct ihex_binrec *)loader_fw->data; while (record) { response = ezusb_writememory (serial, be32_to_cpu(record->addr), (unsigned char *)record->data, be16_to_cpu(record->len), 0xa0); if (response < 0) { dev_err(&serial->dev->dev, "%s - ezusb_writememory " "failed for loader (%d %04X %p %d)\n", __func__, response, be32_to_cpu(record->addr), record->data, be16_to_cpu(record->len)); break; } record = ihex_next_binrec(record); } response = ezusb_set_reset(serial, 0); record = (const struct ihex_binrec *)firmware_fw->data; while (record && be32_to_cpu(record->addr) < 0x1b40) record = ihex_next_binrec(record); while (record) { response = ezusb_writememory (serial, be32_to_cpu(record->addr), (unsigned char *)record->data, be16_to_cpu(record->len), 0xa3); if (response < 0) { dev_err(&serial->dev->dev, "%s - ezusb_writememory " "failed for first firmware step " "(%d %04X %p %d)\n", __func__, response, be32_to_cpu(record->addr), record->data, be16_to_cpu(record->len)); break; } ++record; } response = ezusb_set_reset(serial, 1); record = (const struct ihex_binrec *)firmware_fw->data; while (record && be32_to_cpu(record->addr) < 0x1b40) { response = ezusb_writememory (serial, be32_to_cpu(record->addr), (unsigned char *)record->data, be16_to_cpu(record->len), 0xa0); if (response < 0) { dev_err(&serial->dev->dev, "%s - ezusb_writememory " "failed for second firmware step " "(%d %04X %p %d)\n", __func__, response, be32_to_cpu(record->addr), record->data, be16_to_cpu(record->len)); break; } ++record; } ret = 0; response = ezusb_set_reset (serial, 0); out: release_firmware(loader_fw); release_firmware(firmware_fw); return ret; }
static void load_code(struct icom_port *icom_port) { const struct firmware *fw; char __iomem *iram_ptr; int index; int status = 0; void __iomem *dram_ptr = icom_port->dram; dma_addr_t temp_pci; unsigned char *new_page = NULL; unsigned char cable_id = NO_CABLE; struct pci_dev *dev = icom_port->adapter->pci_dev; /* Clear out any pending interrupts */ writew(0x3FFF, icom_port->int_reg); trace(icom_port, "CLEAR_INTERRUPTS", 0); /* Stop processor */ stop_processor(icom_port); /* Zero out DRAM */ memset_io(dram_ptr, 0, 512); /* Load Call Setup into Adapter */ if (reject_firmware(&fw, "/*(DEBLOBBED)*/", &dev->dev) < 0) { dev_err(&dev->dev,"Unable to load /*(DEBLOBBED)*/ firmware image\n"); status = -1; goto load_code_exit; } if (fw->size > ICOM_DCE_IRAM_OFFSET) { dev_err(&dev->dev, "Invalid firmware image for /*(DEBLOBBED)*/ found.\n"); release_firmware(fw); status = -1; goto load_code_exit; } iram_ptr = (char __iomem *)icom_port->dram + ICOM_IRAM_OFFSET; for (index = 0; index < fw->size; index++) writeb(fw->data[index], &iram_ptr[index]); release_firmware(fw); /* Load Resident DCE portion of Adapter */ if (reject_firmware(&fw, "/*(DEBLOBBED)*/", &dev->dev) < 0) { dev_err(&dev->dev,"Unable to load /*(DEBLOBBED)*/ firmware image\n"); status = -1; goto load_code_exit; } if (fw->size > ICOM_IRAM_SIZE) { dev_err(&dev->dev, "Invalid firmware image for /*(DEBLOBBED)*/ found.\n"); release_firmware(fw); status = -1; goto load_code_exit; } iram_ptr = (char __iomem *) icom_port->dram + ICOM_IRAM_OFFSET; for (index = ICOM_DCE_IRAM_OFFSET; index < fw->size; index++) writeb(fw->data[index], &iram_ptr[index]); release_firmware(fw); /* Set Hardware level */ if (icom_port->adapter->version == ADAPTER_V2) writeb(V2_HARDWARE, &(icom_port->dram->misc_flags)); /* Start the processor in Adapter */ start_processor(icom_port); writeb((HDLC_PPP_PURE_ASYNC | HDLC_FF_FILL), &(icom_port->dram->HDLCConfigReg)); writeb(0x04, &(icom_port->dram->FlagFillIdleTimer)); /* 0.5 seconds */ writeb(0x00, &(icom_port->dram->CmdReg)); writeb(0x10, &(icom_port->dram->async_config3)); writeb((ICOM_ACFG_DRIVE1 | ICOM_ACFG_NO_PARITY | ICOM_ACFG_8BPC | ICOM_ACFG_1STOP_BIT), &(icom_port->dram->async_config2)); /*Set up data in icom DRAM to indicate where personality *code is located and its length. */ new_page = pci_alloc_consistent(dev, 4096, &temp_pci); if (!new_page) { dev_err(&dev->dev, "Can not allocate DMA buffer\n"); status = -1; goto load_code_exit; } if (reject_firmware(&fw, "/*(DEBLOBBED)*/", &dev->dev) < 0) { dev_err(&dev->dev,"Unable to load /*(DEBLOBBED)*/ firmware image\n"); status = -1; goto load_code_exit; } if (fw->size > ICOM_DCE_IRAM_OFFSET) { dev_err(&dev->dev, "Invalid firmware image for /*(DEBLOBBED)*/ found.\n"); release_firmware(fw); status = -1; goto load_code_exit; } for (index = 0; index < fw->size; index++) new_page[index] = fw->data[index]; release_firmware(fw); writeb((char) ((fw->size + 16)/16), &icom_port->dram->mac_length); writel(temp_pci, &icom_port->dram->mac_load_addr); /*Setting the syncReg to 0x80 causes adapter to start downloading the personality code into adapter instruction RAM. Once code is loaded, it will begin executing and, based on information provided above, will start DMAing data from shared memory to adapter DRAM. */ /* the wait loop below verifies this write operation has been done and processed */ writeb(START_DOWNLOAD, &icom_port->dram->sync); /* Wait max 1 Sec for data download and processor to start */ for (index = 0; index < 10; index++) { msleep(100); if (readb(&icom_port->dram->misc_flags) & ICOM_HDW_ACTIVE) break; } if (index == 10) status = -1; /* * check Cable ID */ cable_id = readb(&icom_port->dram->cable_id); if (cable_id & ICOM_CABLE_ID_VALID) { /* Get cable ID into the lower 4 bits (standard form) */ cable_id = (cable_id & ICOM_CABLE_ID_MASK) >> 4; icom_port->cable_id = cable_id; } else {
/* Load the firmware. Optionally it can be in ROM or newer versions * can be on disk, saving the expense of the ROM hardware. */ int saa7164_downloadfirmware(struct saa7164_dev *dev) { /* u32 second_timeout = 60 * SAA_DEVICE_TIMEOUT; */ u32 tmp, filesize, version, err_flags, first_timeout, fwlength; u32 second_timeout, updatebootloader = 1, bootloadersize = 0; const struct firmware *fw = NULL; struct fw_header *hdr, *boothdr = NULL, *fwhdr; u32 bootloaderversion = 0, fwloadersize; u8 *bootloaderoffset = NULL, *fwloaderoffset; char *fwname; int ret; dprintk(DBGLVL_FW, "%s()\n", __func__); if (saa7164_boards[dev->board].chiprev == SAA7164_CHIP_REV2) { fwname = SAA7164_REV2_FIRMWARE; fwlength = SAA7164_REV2_FIRMWARE_SIZE; } else { fwname = SAA7164_REV3_FIRMWARE; fwlength = SAA7164_REV3_FIRMWARE_SIZE; } version = saa7164_getcurrentfirmwareversion(dev); if (version == 0x00) { second_timeout = 100; first_timeout = 100; err_flags = saa7164_readl(SAA_BOOTLOADERERROR_FLAGS); dprintk(DBGLVL_FW, "%s() err_flags = %x\n", __func__, err_flags); while (err_flags != SAA_DEVICE_IMAGE_BOOTING) { dprintk(DBGLVL_FW, "%s() err_flags = %x\n", __func__, err_flags); msleep(10); /* Checkpatch throws a < 20ms warning */ if (err_flags & SAA_DEVICE_IMAGE_CORRUPT) { printk(KERN_ERR "%s() firmware corrupt\n", __func__); break; } if (err_flags & SAA_DEVICE_MEMORY_CORRUPT) { printk(KERN_ERR "%s() device memory corrupt\n", __func__); break; } if (err_flags & SAA_DEVICE_NO_IMAGE) { printk(KERN_ERR "%s() no first image\n", __func__); break; } if (err_flags & SAA_DEVICE_IMAGE_SEARCHING) { first_timeout -= 10; if (first_timeout == 0) { printk(KERN_ERR "%s() no first image\n", __func__); break; } } else if (err_flags & SAA_DEVICE_IMAGE_LOADING) { second_timeout -= 10; if (second_timeout == 0) { printk(KERN_ERR "%s() FW load time exceeded\n", __func__); break; } } else { second_timeout -= 10; if (second_timeout == 0) { printk(KERN_ERR "%s() Unknown bootloader flags 0x%x\n", __func__, err_flags); break; } } err_flags = saa7164_readl(SAA_BOOTLOADERERROR_FLAGS); } /* While != Booting */ if (err_flags == SAA_DEVICE_IMAGE_BOOTING) { dprintk(DBGLVL_FW, "%s() Loader 1 has loaded.\n", __func__); first_timeout = SAA_DEVICE_TIMEOUT; second_timeout = 60 * SAA_DEVICE_TIMEOUT; second_timeout = 100; err_flags = saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS); dprintk(DBGLVL_FW, "%s() err_flags2 = %x\n", __func__, err_flags); while (err_flags != SAA_DEVICE_IMAGE_BOOTING) { dprintk(DBGLVL_FW, "%s() err_flags2 = %x\n", __func__, err_flags); msleep(10); /* Checkpatch throws a < 20ms warning */ if (err_flags & SAA_DEVICE_IMAGE_CORRUPT) { printk(KERN_ERR "%s() firmware corrupt\n", __func__); break; } if (err_flags & SAA_DEVICE_MEMORY_CORRUPT) { printk(KERN_ERR "%s() device memory corrupt\n", __func__); break; } if (err_flags & SAA_DEVICE_NO_IMAGE) { printk(KERN_ERR "%s() no first image\n", __func__); break; } if (err_flags & SAA_DEVICE_IMAGE_SEARCHING) { first_timeout -= 10; if (first_timeout == 0) { printk(KERN_ERR "%s() no second image\n", __func__); break; } } else if (err_flags & SAA_DEVICE_IMAGE_LOADING) { second_timeout -= 10; if (second_timeout == 0) { printk(KERN_ERR "%s() FW load time exceeded\n", __func__); break; } } else { second_timeout -= 10; if (second_timeout == 0) { printk(KERN_ERR "%s() Unknown bootloader flags 0x%x\n", __func__, err_flags); break; } } err_flags = saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS); } /* err_flags != SAA_DEVICE_IMAGE_BOOTING */ dprintk(DBGLVL_FW, "%s() Loader flags 1:0x%x 2:0x%x.\n", __func__, saa7164_readl(SAA_BOOTLOADERERROR_FLAGS), saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS)); } /* err_flags == SAA_DEVICE_IMAGE_BOOTING */ /* It's possible for both firmwares to have booted, * but that doesn't mean they've finished booting yet. */ if ((saa7164_readl(SAA_BOOTLOADERERROR_FLAGS) == SAA_DEVICE_IMAGE_BOOTING) && (saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS) == SAA_DEVICE_IMAGE_BOOTING)) { dprintk(DBGLVL_FW, "%s() Loader 2 has loaded.\n", __func__); first_timeout = SAA_DEVICE_TIMEOUT; while (first_timeout) { msleep(10); /* Checkpatch throws a < 20ms warning */ version = saa7164_getcurrentfirmwareversion(dev); if (version) { dprintk(DBGLVL_FW, "%s() All f/w loaded successfully\n", __func__); break; } else { first_timeout -= 10; if (first_timeout == 0) { printk(KERN_ERR "%s() FW did not boot\n", __func__); break; } } } } version = saa7164_getcurrentfirmwareversion(dev); } /* version == 0 */ /* Has the firmware really booted? */ if ((saa7164_readl(SAA_BOOTLOADERERROR_FLAGS) == SAA_DEVICE_IMAGE_BOOTING) && (saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS) == SAA_DEVICE_IMAGE_BOOTING) && (version == 0)) { printk(KERN_ERR "%s() The firmware hung, probably bad firmware\n", __func__); /* Tell the second stage loader we have a deadlock */ saa7164_writel(SAA_DEVICE_DEADLOCK_DETECTED_OFFSET, SAA_DEVICE_DEADLOCK_DETECTED); saa7164_getfirmwarestatus(dev); return -ENOMEM; } dprintk(DBGLVL_FW, "Device has Firmware Version %d.%d.%d.%d\n", (version & 0x0000fc00) >> 10, (version & 0x000003e0) >> 5, (version & 0x0000001f), (version & 0xffff0000) >> 16); /* Load the firmwware from the disk if required */ if (version == 0) { printk(KERN_INFO "%s() Waiting for firmware upload (%s)\n", __func__, fwname); ret = reject_firmware(&fw, fwname, &dev->pci->dev); if (ret) { printk(KERN_ERR "%s() Upload failed. " "(file not found?)\n", __func__); return -ENOMEM; } printk(KERN_INFO "%s() firmware read %Zu bytes.\n", __func__, fw->size); if (fw->size != fwlength) { printk(KERN_ERR "xc5000: firmware incorrect size\n"); ret = -ENOMEM; goto out; } printk(KERN_INFO "%s() firmware loaded.\n", __func__); hdr = (struct fw_header *)fw->data; printk(KERN_INFO "Firmware file header part 1:\n"); printk(KERN_INFO " .FirmwareSize = 0x%x\n", hdr->firmwaresize); printk(KERN_INFO " .BSLSize = 0x%x\n", hdr->bslsize); printk(KERN_INFO " .Reserved = 0x%x\n", hdr->reserved); printk(KERN_INFO " .Version = 0x%x\n", hdr->version); /* Retrieve bootloader if reqd */ if ((hdr->firmwaresize == 0) && (hdr->bslsize == 0)) /* Second bootloader in the firmware file */ filesize = hdr->reserved * 16; else filesize = (hdr->firmwaresize + hdr->bslsize) * 16 + sizeof(struct fw_header); printk(KERN_INFO "%s() SecBootLoader.FileSize = %d\n", __func__, filesize); /* Get bootloader (if reqd) and firmware header */ if ((hdr->firmwaresize == 0) && (hdr->bslsize == 0)) { /* Second boot loader is required */ /* Get the loader header */ boothdr = (struct fw_header *)(fw->data + sizeof(struct fw_header)); bootloaderversion = saa7164_readl(SAA_DEVICE_2ND_VERSION); dprintk(DBGLVL_FW, "Onboard BootLoader:\n"); dprintk(DBGLVL_FW, "->Flag 0x%x\n", saa7164_readl(SAA_BOOTLOADERERROR_FLAGS)); dprintk(DBGLVL_FW, "->Ack 0x%x\n", saa7164_readl(SAA_DATAREADY_FLAG_ACK)); dprintk(DBGLVL_FW, "->FW Version 0x%x\n", version); dprintk(DBGLVL_FW, "->Loader Version 0x%x\n", bootloaderversion); if ((saa7164_readl(SAA_BOOTLOADERERROR_FLAGS) == 0x03) && (saa7164_readl(SAA_DATAREADY_FLAG_ACK) == 0x00) && (version == 0x00)) { dprintk(DBGLVL_FW, "BootLoader version in " "rom %d.%d.%d.%d\n", (bootloaderversion & 0x0000fc00) >> 10, (bootloaderversion & 0x000003e0) >> 5, (bootloaderversion & 0x0000001f), (bootloaderversion & 0xffff0000) >> 16 ); dprintk(DBGLVL_FW, "BootLoader version " "in file %d.%d.%d.%d\n", (boothdr->version & 0x0000fc00) >> 10, (boothdr->version & 0x000003e0) >> 5, (boothdr->version & 0x0000001f), (boothdr->version & 0xffff0000) >> 16 ); if (bootloaderversion == boothdr->version) updatebootloader = 0; }
int softing_load_fw(const char *file, struct softing *card, __iomem uint8_t *dpram, unsigned int size, int offset) { const struct firmware *fw; int ret; const uint8_t *mem, *end, *dat; uint16_t type, len; uint32_t addr; uint8_t *buf = NULL, *new_buf; int buflen = 0; int8_t type_end = 0; ret = reject_firmware(&fw, file, &card->pdev->dev); if (ret < 0) return ret; dev_dbg(&card->pdev->dev, "%s, firmware(%s) got %u bytes" ", offset %c0x%04x\n", card->pdat->name, file, (unsigned int)fw->size, (offset >= 0) ? '+' : '-', (unsigned int)abs(offset)); /* parse the firmware */ mem = fw->data; end = &mem[fw->size]; /* look for header record */ ret = fw_parse(&mem, &type, &addr, &len, &dat); if (ret < 0) goto failed; if (type != 0xffff) goto failed; if (strncmp("Structured Binary Format, Softing GmbH" , dat, len)) { ret = -EINVAL; goto failed; } /* ok, we had a header */ while (mem < end) { ret = fw_parse(&mem, &type, &addr, &len, &dat); if (ret < 0) goto failed; if (type == 3) { /* start address, not used here */ continue; } else if (type == 1) { /* eof */ type_end = 1; break; } else if (type != 0) { ret = -EINVAL; goto failed; } if ((addr + len + offset) > size) goto failed; memcpy_toio(&dpram[addr + offset], dat, len); /* be sure to flush caches from IO space */ mb(); if (len > buflen) { /* align buflen */ buflen = (len + (1024-1)) & ~(1024-1); new_buf = krealloc(buf, buflen, GFP_KERNEL); if (!new_buf) { ret = -ENOMEM; goto failed; } buf = new_buf; } /* verify record data */ memcpy_fromio(buf, &dpram[addr + offset], len); if (memcmp(buf, dat, len)) { /* is not ok */ dev_alert(&card->pdev->dev, "DPRAM readback failed\n"); ret = -EIO; goto failed; } } if (!type_end) /* no end record seen */ goto failed; ret = 0; failed: kfree(buf); release_firmware(fw); if (ret < 0) dev_info(&card->pdev->dev, "firmware %s failed\n", file); return ret; }
static int wm0010_boot(struct snd_soc_codec *codec) { struct spi_device *spi = to_spi_device(codec->dev); struct wm0010_priv *wm0010 = snd_soc_codec_get_drvdata(codec); unsigned long flags; int ret; const struct firmware *fw; struct spi_message m; struct spi_transfer t; struct dfw_pllrec pll_rec; u32 *p, len; u64 *img_swap; u8 *out; int i; spin_lock_irqsave(&wm0010->irq_lock, flags); if (wm0010->state != WM0010_POWER_OFF) dev_warn(wm0010->dev, "DSP already powered up!\n"); spin_unlock_irqrestore(&wm0010->irq_lock, flags); if (wm0010->sysclk > 26000000) { dev_err(codec->dev, "Max DSP clock frequency is 26MHz\n"); ret = -ECANCELED; goto err; } mutex_lock(&wm0010->lock); wm0010->pll_running = false; dev_dbg(codec->dev, "max_spi_freq: %d\n", wm0010->max_spi_freq); ret = regulator_bulk_enable(ARRAY_SIZE(wm0010->core_supplies), wm0010->core_supplies); if (ret != 0) { dev_err(&spi->dev, "Failed to enable core supplies: %d\n", ret); mutex_unlock(&wm0010->lock); goto err; } ret = regulator_enable(wm0010->dbvdd); if (ret != 0) { dev_err(&spi->dev, "Failed to enable DBVDD: %d\n", ret); goto err_core; } /* Release reset */ gpio_set_value_cansleep(wm0010->gpio_reset, !wm0010->gpio_reset_value); spin_lock_irqsave(&wm0010->irq_lock, flags); wm0010->state = WM0010_OUT_OF_RESET; spin_unlock_irqrestore(&wm0010->irq_lock, flags); /* First the bootloader */ ret = reject_firmware(&fw, "/*(DEBLOBBED)*/", codec->dev); if (ret != 0) { dev_err(codec->dev, "Failed to request stage2 loader: %d\n", ret); goto abort; } if (!wait_for_completion_timeout(&wm0010->boot_completion, msecs_to_jiffies(20))) dev_err(codec->dev, "Failed to get interrupt from DSP\n"); spin_lock_irqsave(&wm0010->irq_lock, flags); wm0010->state = WM0010_BOOTROM; spin_unlock_irqrestore(&wm0010->irq_lock, flags); ret = wm0010_stage2_load(codec); if (ret) goto abort; if (!wait_for_completion_timeout(&wm0010->boot_completion, msecs_to_jiffies(20))) dev_err(codec->dev, "Failed to get interrupt from DSP loader.\n"); spin_lock_irqsave(&wm0010->irq_lock, flags); wm0010->state = WM0010_STAGE2; spin_unlock_irqrestore(&wm0010->irq_lock, flags); /* Only initialise PLL if max_spi_freq initialised */ if (wm0010->max_spi_freq) { /* Initialise a PLL record */ memset(&pll_rec, 0, sizeof(pll_rec)); pll_rec.command = DFW_CMD_PLL; pll_rec.length = (sizeof(pll_rec) - 8); /* On wm0010 only the CLKCTRL1 value is used */ pll_rec.clkctrl1 = wm0010->pll_clkctrl1; ret = -ENOMEM; len = pll_rec.length + 8; out = kzalloc(len, GFP_KERNEL | GFP_DMA); if (!out) { dev_err(codec->dev, "Failed to allocate RX buffer\n"); goto abort; } img_swap = kzalloc(len, GFP_KERNEL | GFP_DMA); if (!img_swap) { dev_err(codec->dev, "Failed to allocate image buffer\n"); goto abort; } /* We need to re-order for 0010 */ byte_swap_64((u64 *)&pll_rec, img_swap, len); spi_message_init(&m); memset(&t, 0, sizeof(t)); t.rx_buf = out; t.tx_buf = img_swap; t.len = len; t.bits_per_word = 8; t.speed_hz = wm0010->sysclk / 6; spi_message_add_tail(&t, &m); ret = spi_sync(spi, &m); if (ret != 0) { dev_err(codec->dev, "First PLL write failed: %d\n", ret); goto abort; } /* Use a second send of the message to get the return status */ ret = spi_sync(spi, &m); if (ret != 0) { dev_err(codec->dev, "Second PLL write failed: %d\n", ret); goto abort; } p = (u32 *)out; /* Look for PLL active code from the DSP */ for (i = 0; i < len / 4; i++) { if (*p == 0x0e00ed0f) { dev_dbg(codec->dev, "PLL packet received\n"); wm0010->pll_running = true; break; } p++; } kfree(img_swap); kfree(out); } else dev_dbg(codec->dev, "Not enabling DSP PLL."); ret = wm0010_firmware_load("/*(DEBLOBBED)*/", codec); if (ret != 0) goto abort; spin_lock_irqsave(&wm0010->irq_lock, flags); wm0010->state = WM0010_FIRMWARE; spin_unlock_irqrestore(&wm0010->irq_lock, flags); mutex_unlock(&wm0010->lock); return 0; abort: /* Put the chip back into reset */ wm0010_halt(codec); mutex_unlock(&wm0010->lock); return ret; err_core: mutex_unlock(&wm0010->lock); regulator_bulk_disable(ARRAY_SIZE(wm0010->core_supplies), wm0010->core_supplies); err: return ret; }
int softing_load_app_fw(const char *file, struct softing *card) { const struct firmware *fw; const uint8_t *mem, *end, *dat; int ret, j; uint16_t type, len; uint32_t addr, start_addr = 0; unsigned int sum, rx_sum; int8_t type_end = 0, type_entrypoint = 0; ret = reject_firmware(&fw, file, &card->pdev->dev); if (ret) { dev_alert(&card->pdev->dev, "reject_firmware(%s) got %i\n", file, ret); return ret; } dev_dbg(&card->pdev->dev, "firmware(%s) got %lu bytes\n", file, (unsigned long)fw->size); /* parse the firmware */ mem = fw->data; end = &mem[fw->size]; /* look for header record */ ret = fw_parse(&mem, &type, &addr, &len, &dat); if (ret) goto failed; ret = -EINVAL; if (type != 0xffff) { dev_alert(&card->pdev->dev, "firmware starts with type 0x%x\n", type); goto failed; } if (strncmp("Structured Binary Format, Softing GmbH", dat, len)) { dev_alert(&card->pdev->dev, "firmware string '%.*s' fault\n", len, dat); goto failed; } /* ok, we had a header */ while (mem < end) { ret = fw_parse(&mem, &type, &addr, &len, &dat); if (ret) goto failed; if (type == 3) { /* start address */ start_addr = addr; type_entrypoint = 1; continue; } else if (type == 1) { /* eof */ type_end = 1; break; } else if (type != 0) { dev_alert(&card->pdev->dev, "unknown record type 0x%04x\n", type); ret = -EINVAL; goto failed; } /* regualar data */ for (sum = 0, j = 0; j < len; ++j) sum += dat[j]; /* work in 16bit (target) */ sum &= 0xffff; memcpy_toio(&card->dpram[card->pdat->app.offs], dat, len); iowrite32(card->pdat->app.offs + card->pdat->app.addr, &card->dpram[DPRAM_COMMAND + 2]); iowrite32(addr, &card->dpram[DPRAM_COMMAND + 6]); iowrite16(len, &card->dpram[DPRAM_COMMAND + 10]); iowrite8(1, &card->dpram[DPRAM_COMMAND + 12]); ret = softing_bootloader_command(card, 1, "loading app."); if (ret < 0) goto failed; /* verify checksum */ rx_sum = ioread16(&card->dpram[DPRAM_RECEIPT + 2]); if (rx_sum != sum) { dev_alert(&card->pdev->dev, "SRAM seems to be damaged" ", wanted 0x%04x, got 0x%04x\n", sum, rx_sum); ret = -EIO; goto failed; } } if (!type_end || !type_entrypoint) goto failed; /* start application in card */ iowrite32(start_addr, &card->dpram[DPRAM_COMMAND + 2]); iowrite8(1, &card->dpram[DPRAM_COMMAND + 6]); ret = softing_bootloader_command(card, 3, "start app."); if (ret < 0) goto failed; ret = 0; failed: release_firmware(fw); if (ret < 0) dev_info(&card->pdev->dev, "firmware %s failed\n", file); return ret; }
static int emi62_load_firmware (struct usb_device *dev) { const struct firmware *loader_fw = NULL; const struct firmware *bitstream_fw = NULL; const struct firmware *firmware_fw = NULL; const struct ihex_binrec *rec; int err = -ENOMEM; int i; __u32 addr; /* Address to write */ __u8 *buf; dev_dbg(&dev->dev, "load_firmware\n"); buf = kmalloc(FW_LOAD_SIZE, GFP_KERNEL); if (!buf) goto wraperr; err = reject_firmware(&loader_fw, "/*(DEBLOBBED)*/", &dev->dev); if (err) goto nofw; err = reject_firmware(&bitstream_fw, "/*(DEBLOBBED)*/", &dev->dev); if (err) goto nofw; err = reject_firmware(&firmware_fw, FIRMWARE_FW, &dev->dev); if (err) { nofw: goto wraperr; } /* Assert reset (stop the CPU in the EMI) */ err = emi62_set_reset(dev,1); if (err < 0) goto wraperr; rec = (const struct ihex_binrec *)loader_fw->data; /* 1. We need to put the loader for the FPGA into the EZ-USB */ while (rec) { err = emi62_writememory(dev, be32_to_cpu(rec->addr), rec->data, be16_to_cpu(rec->len), ANCHOR_LOAD_INTERNAL); if (err < 0) goto wraperr; rec = ihex_next_binrec(rec); } /* De-assert reset (let the CPU run) */ err = emi62_set_reset(dev,0); if (err < 0) goto wraperr; msleep(250); /* let device settle */ /* 2. We upload the FPGA firmware into the EMI * Note: collect up to 1023 (yes!) bytes and send them with * a single request. This is _much_ faster! */ rec = (const struct ihex_binrec *)bitstream_fw->data; do { i = 0; addr = be32_to_cpu(rec->addr); /* intel hex records are terminated with type 0 element */ while (rec && (i + be16_to_cpu(rec->len) < FW_LOAD_SIZE)) { memcpy(buf + i, rec->data, be16_to_cpu(rec->len)); i += be16_to_cpu(rec->len); rec = ihex_next_binrec(rec); } err = emi62_writememory(dev, addr, buf, i, ANCHOR_LOAD_FPGA); if (err < 0) goto wraperr; } while (rec); /* Assert reset (stop the CPU in the EMI) */ err = emi62_set_reset(dev,1); if (err < 0) goto wraperr; /* 3. We need to put the loader for the firmware into the EZ-USB (again...) */ for (rec = (const struct ihex_binrec *)loader_fw->data; rec; rec = ihex_next_binrec(rec)) { err = emi62_writememory(dev, be32_to_cpu(rec->addr), rec->data, be16_to_cpu(rec->len), ANCHOR_LOAD_INTERNAL); if (err < 0) goto wraperr; } /* De-assert reset (let the CPU run) */ err = emi62_set_reset(dev,0); if (err < 0) goto wraperr; msleep(250); /* let device settle */ /* 4. We put the part of the firmware that lies in the external RAM into the EZ-USB */ for (rec = (const struct ihex_binrec *)firmware_fw->data; rec; rec = ihex_next_binrec(rec)) { if (!INTERNAL_RAM(be32_to_cpu(rec->addr))) { err = emi62_writememory(dev, be32_to_cpu(rec->addr), rec->data, be16_to_cpu(rec->len), ANCHOR_LOAD_EXTERNAL); if (err < 0) goto wraperr; } } /* Assert reset (stop the CPU in the EMI) */ err = emi62_set_reset(dev,1); if (err < 0) goto wraperr; for (rec = (const struct ihex_binrec *)firmware_fw->data; rec; rec = ihex_next_binrec(rec)) { if (INTERNAL_RAM(be32_to_cpu(rec->addr))) { err = emi62_writememory(dev, be32_to_cpu(rec->addr), rec->data, be16_to_cpu(rec->len), ANCHOR_LOAD_EXTERNAL); if (err < 0) goto wraperr; } } /* De-assert reset (let the CPU run) */ err = emi62_set_reset(dev,0); if (err < 0) goto wraperr; msleep(250); /* let device settle */ release_firmware(loader_fw); release_firmware(bitstream_fw); release_firmware(firmware_fw); kfree(buf); /* return 1 to fail the driver inialization * and give real driver change to load */ return 1; wraperr: if (err < 0) dev_err(&dev->dev,"%s - error loading firmware: error = %d\n", __func__, err); release_firmware(loader_fw); release_firmware(bitstream_fw); release_firmware(firmware_fw); kfree(buf); dev_err(&dev->dev, "Error\n"); return err; }
static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *id) { const struct firmware *firmware; struct usb_device *udev = interface_to_usbdev(intf); struct usb_host_endpoint *bulk_out_ep; struct usb_host_endpoint *bulk_in_ep; struct hci_dev *hdev; struct bfusb_data *data; BT_DBG("intf %p id %p", intf, id); /* Check number of endpoints */ if (intf->cur_altsetting->desc.bNumEndpoints < 2) return -EIO; bulk_out_ep = &intf->cur_altsetting->endpoint[0]; bulk_in_ep = &intf->cur_altsetting->endpoint[1]; if (!bulk_out_ep || !bulk_in_ep) { BT_ERR("Bulk endpoints not found"); goto done; } /* Initialize control structure and load firmware */ data = devm_kzalloc(&intf->dev, sizeof(struct bfusb_data), GFP_KERNEL); if (!data) { BT_ERR("Can't allocate memory for control structure"); goto done; } data->udev = udev; data->bulk_in_ep = bulk_in_ep->desc.bEndpointAddress; data->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress; data->bulk_pkt_size = le16_to_cpu(bulk_out_ep->desc.wMaxPacketSize); rwlock_init(&data->lock); data->reassembly = NULL; skb_queue_head_init(&data->transmit_q); skb_queue_head_init(&data->pending_q); skb_queue_head_init(&data->completed_q); if (reject_firmware(&firmware, "/*(DEBLOBBED)*/", &udev->dev) < 0) { BT_ERR("Firmware request failed"); goto done; } BT_DBG("firmware data %p size %zu", firmware->data, firmware->size); if (bfusb_load_firmware(data, firmware->data, firmware->size) < 0) { BT_ERR("Firmware loading failed"); goto release; } release_firmware(firmware); /* Initialize and register HCI device */ hdev = hci_alloc_dev(); if (!hdev) { BT_ERR("Can't allocate HCI device"); goto done; } data->hdev = hdev; hdev->bus = HCI_USB; hci_set_drvdata(hdev, data); SET_HCIDEV_DEV(hdev, &intf->dev); hdev->open = bfusb_open; hdev->close = bfusb_close; hdev->flush = bfusb_flush; hdev->send = bfusb_send_frame; set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks); if (hci_register_dev(hdev) < 0) { BT_ERR("Can't register HCI device"); hci_free_dev(hdev); goto done; } usb_set_intfdata(intf, data); return 0; release: release_firmware(firmware); done: return -EIO; }
static int s2250loader_probe(struct usb_interface *interface, const struct usb_device_id *id) { struct usb_device *usbdev; int minor, ret; pdevice_extension_t s = NULL; const struct firmware *fw; usbdev = usb_get_dev(interface_to_usbdev(interface)); if (!usbdev) { printk(KERN_ERR "Enter s2250loader_probe failed\n"); return -1; } printk(KERN_INFO "Enter s2250loader_probe 2.6 kernel\n"); printk(KERN_INFO "vendor id 0x%x, device id 0x%x devnum:%d\n", usbdev->descriptor.idVendor, usbdev->descriptor.idProduct, usbdev->devnum); if (usbdev->descriptor.bNumConfigurations != 1) { printk(KERN_ERR "can't handle multiple config\n"); return -1; } mutex_lock(&s2250_dev_table_mutex); for (minor = 0; minor < MAX_DEVICES; minor++) { if (s2250_dev_table[minor] == NULL) break; } if (minor < 0 || minor >= MAX_DEVICES) { printk(KERN_ERR "Invalid minor: %d\n", minor); goto failed; } /* Allocate dev data structure */ s = kmalloc(sizeof(device_extension_t), GFP_KERNEL); if (s == NULL) { printk(KERN_ERR "Out of memory\n"); goto failed; } s2250_dev_table[minor] = s; printk(KERN_INFO "s2250loader_probe: Device %d on Bus %d Minor %d\n", usbdev->devnum, usbdev->bus->busnum, minor); memset(s, 0, sizeof(device_extension_t)); s->usbdev = usbdev; printk(KERN_INFO "loading 2250 loader\n"); kref_init(&(s->kref)); mutex_unlock(&s2250_dev_table_mutex); if (reject_firmware(&fw, S2250_LOADER_FIRMWARE, &usbdev->dev)) { printk(KERN_ERR "s2250: unable to load firmware from file \"%s\"\n", S2250_LOADER_FIRMWARE); goto failed2; } ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2); release_firmware(fw); if (0 != ret) { printk(KERN_ERR "loader download failed\n"); goto failed2; } if (reject_firmware(&fw, S2250_FIRMWARE, &usbdev->dev)) { printk(KERN_ERR "s2250: unable to load firmware from file \"%s\"\n", S2250_FIRMWARE); goto failed2; } ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2); release_firmware(fw); if (0 != ret) { printk(KERN_ERR "firmware_s2250 download failed\n"); goto failed2; } usb_set_intfdata(interface, s); return 0; failed: mutex_unlock(&s2250_dev_table_mutex); failed2: if (s) kref_put(&(s->kref), s2250loader_delete); printk(KERN_ERR "probe failed\n"); return -1; }