CHAR8 * ConvertComponentName2SupportLanguage ( IN EFI_COMPONENT_NAME2_PROTOCOL *ComponentName, IN CHAR8 *Language ) /*++ Routine Description: Do some convertion for the ComponentName2 supported language. It do the convertion just for english language code currently. Arguments: ComponentName - Pointer to the ComponentName2 protocl pointer. Language - The language string. Returns: Return the duplication of Language if it is not english otherwise return the supported english language code. --*/ { CHAR8 *SupportedLanguages; CHAR8 *LangCode; UINTN Index; LangCode = NULL; SupportedLanguages = NULL; // // treat all the english language code (en-xx or eng) equally // if ((strncmpa(Language, "en-", 3) == 0) || (strcmpa(Language, "eng") == 0)) { SupportedLanguages = strstra(ComponentName->SupportedLanguages, "en-"); if (SupportedLanguages == NULL) { SupportedLanguages = strstra(ComponentName->SupportedLanguages, "eng"); } } // // duplicate the Language if it is not english // if (SupportedLanguages == NULL) { SupportedLanguages = Language; } // // duplicate the returned language code. // if (strstra(SupportedLanguages, "-") != NULL) { LangCode = EfiLibAllocateZeroPool(32); for(Index = 0; (Index < 31) && (SupportedLanguages[Index] != '\0') && (SupportedLanguages[Index] != ';'); Index++) { LangCode[Index] = SupportedLanguages[Index]; } LangCode[Index] = '\0'; } else { LangCode = EfiLibAllocateZeroPool(4); for(Index = 0; (Index < 3) && (SupportedLanguages[Index] != '\0'); Index++) { LangCode[Index] = SupportedLanguages[Index]; } LangCode[Index] = '\0'; } return LangCode; }
static EFI_STATUS flash_zimage(VOID *data, UINTN size) { struct boot_img_hdr *bootimage, *new_bootimage; VOID *new_cur, *cur; UINTN new_size, partlen; EFI_STATUS ret; ret = gpt_get_partition_by_label(L"boot", &gparti, LOGICAL_UNIT_USER); if (EFI_ERROR(ret)) { error(L"Unable to get information on the boot partition"); return ret; } partlen = (gparti.part.ending_lba + 1 - gparti.part.starting_lba) * gparti.bio->Media->BlockSize; bootimage = AllocatePool(partlen); if (!bootimage) { error(L"Unable to allocate bootimage buffer"); return EFI_OUT_OF_RESOURCES; } ret = uefi_call_wrapper(gparti.dio->ReadDisk, 5, gparti.dio, gparti.bio->Media->MediaId, gparti.part.starting_lba * gparti.bio->Media->BlockSize, partlen, bootimage); if (EFI_ERROR(ret)) { efi_perror(ret, L"Failed to load the current bootimage"); goto out; } if (strncmpa((CHAR8 *)BOOT_MAGIC, bootimage->magic, BOOT_MAGIC_SIZE)) { error(L"boot partition does not contain a valid bootimage"); ret = EFI_UNSUPPORTED; goto out; } new_size = bootimage_size(bootimage) - bootimage->kernel_size + pagealign(bootimage, size); if (new_size > partlen) { error(L"Kernel image is too large to fit in the boot partition"); ret = EFI_INVALID_PARAMETER; goto out; } new_bootimage = AllocateZeroPool(new_size); if (!new_bootimage) { ret = EFI_OUT_OF_RESOURCES; goto out; } /* Create the new bootimage. */ memcpy((VOID *)new_bootimage, bootimage, bootimage->page_size); new_bootimage->kernel_size = size; new_bootimage->kernel_addr = bootimage->kernel_addr; new_cur = (VOID *)new_bootimage + bootimage->page_size; memcpy(new_cur, data, size); new_cur += pagealign(new_bootimage, size); cur = (VOID *)bootimage + bootimage->page_size + pagealign(bootimage, bootimage->kernel_size); memcpy(new_cur, cur, bootimage->ramdisk_size); new_cur += pagealign(new_bootimage, new_bootimage->ramdisk_size); cur += pagealign(bootimage, bootimage->ramdisk_size); memcpy(new_cur, cur, bootimage->second_size); /* Flash new the bootimage. */ cur_offset = gparti.part.starting_lba * gparti.bio->Media->BlockSize; ret = flash_write(new_bootimage, new_size); FreePool(new_bootimage); out: FreePool(bootimage); return ret; }