/* Apply a single relocation of type @type at @addr. This function is intentionally simple, and does the bare minimum needed to fixup the relocated U-Boot - in particular, it does not check for overflows.  */
static void apply_reloc(unsigned int type, void *addr, long off)
/* Apply a single relocation of type @type at @addr. This function is intentionally simple, and does the bare minimum needed to fixup the relocated U-Boot - in particular, it does not check for overflows.  */
static void apply_reloc(unsigned int type, void *addr, long off)
{
	uint32_t u32;
	switch (type) {
	case R_MIPS_26:
		u32 = *(uint32_t *)addr;
		u32 = (u32 & GENMASK(31, 26)) |
		      ((u32 + (off >> 2)) & GENMASK(25, 0));
		*(uint32_t *)addr = u32;
		break;
	case R_MIPS_32:
		*(uint32_t *)addr += off;
		break;
	case R_MIPS_64:
		*(uint64_t *)addr += off;
		break;
	case R_MIPS_HI16:
		*(uint32_t *)addr += off >> 16;
		break;
	default:
		panic("Unhandled reloc type %u\n", type);
	}
}