}
}
-void rkcommon_vrec_header(struct image_tool_params *params,
- struct image_type_params *tparams)
+int rkcommon_vrec_header(struct image_tool_params *params,
+ struct image_type_params *tparams,
+ unsigned int alignment)
{
+ unsigned int unpadded_size;
+ unsigned int padded_size;
+
/*
* The SPL image looks as follows:
*
/* Allocate, clear and install the header */
tparams->hdr = malloc(tparams->header_size);
memset(tparams->hdr, 0, tparams->header_size);
+ tparams->header_size = tparams->header_size;
+
+ /*
+ * If someone passed in 0 for the alignment, we'd better handle
+ * it correctly...
+ */
+ if (!alignment)
+ alignment = 1;
+
+ unpadded_size = tparams->header_size + params->file_size;
+ padded_size = ROUND(unpadded_size, alignment);
+
+ return padded_size - unpadded_size;
}
* @params: Pointer to the tool params structure
* @tparams: Pointer tot the image type structure (for setting
* the header and header_size)
+ * @alignment: Alignment (a power of two) that the image should be
+ * padded to (e.g. 512 if we want to align with SD/MMC
+ * blocksizes or 2048 for the SPI format)
+ *
+ * @return bytes of padding required/added (does not include the header_size)
*/
-void rkcommon_vrec_header(struct image_tool_params *params,
- struct image_type_params *tparams);
+int rkcommon_vrec_header(struct image_tool_params *params,
+ struct image_type_params *tparams,
+ unsigned int alignment);
#endif
unsigned int size;
int ret;
+ printf("params->file_size %d\n", params->file_size);
+ printf("params->orig_file_size %d\n", params->orig_file_size);
+
+ /*
+ * We need to calculate this using 'RK_SPL_HDR_START' and not using
+ * 'tparams->header_size', as the additional byte inserted when
+ * 'is_boot0' is true counts towards the payload.
+ */
size = params->file_size - RK_SPL_HDR_START;
ret = rkcommon_set_header(buf, size, params);
if (ret) {
/* TODO(sjg@chromium.org): This method should return an error */
- printf("Warning: SPL image is too large (size %#x) and will not boot\n",
- size);
+ printf("Warning: SPL image is too large (size %#x) and will "
+ "not boot\n", size);
}
}
return EXIT_FAILURE;
}
-/* We pad the file out to a fixed size - this method returns that size */
static int rksd_vrec_header(struct image_tool_params *params,
struct image_type_params *tparams)
{
- int pad_size;
-
- rkcommon_vrec_header(params, tparams);
-
- pad_size = RK_SPL_HDR_START + rkcommon_get_spl_size(params);
- debug("pad_size %x\n", pad_size);
-
- return pad_size - params->file_size - tparams->header_size;
+ /* We don't add any additional padding after the end of the image */
+ return rkcommon_vrec_header(params, tparams, 1);
}
/*
debug("size %x\n", size);
if (ret) {
/* TODO(sjg@chromium.org): This method should return an error */
- printf("Warning: SPL image is too large (size %#x) and will not boot\n",
- size);
+ printf("Warning: SPL image is too large (size %#x) and will "
+ "not boot\n", size);
}
/*
return EXIT_FAILURE;
}
-/* We pad the file out to a fixed size - this method returns that size */
+/*
+ * The SPI payload needs to be padded out to make space for odd half-sector
+ * layout used in flash (i.e. only the first 2K of each 4K sector is used).
+ */
static int rkspi_vrec_header(struct image_tool_params *params,
struct image_type_params *tparams)
{
- int pad_size;
-
- rkcommon_vrec_header(params, tparams);
-
- pad_size = ROUND(rkcommon_get_spl_size(params), 0x800);
- params->orig_file_size = pad_size;
+ int padding = rkcommon_vrec_header(params, tparams, 2048);
+ /*
+ * The file size has not been adjusted at this point (our caller will
+ * eventually add the header/padding to the file_size), so we need to
+ * add up the header_size, file_size and padding ourselves.
+ */
+ int padded_size = tparams->header_size + params->file_size + padding;
- /* We will double the image size due to the SPI format */
- pad_size += RK_SPL_HDR_START;
- pad_size *= 2;
- debug("pad_size %x\n", pad_size);
+ /*
+ * We need to store the original file-size (i.e. before padding), as
+ * imagetool does not set this during its adjustment of file_size.
+ */
+ params->orig_file_size = padded_size;
- return pad_size - params->file_size - tparams->header_size;
+ /*
+ * Converting to the SPI format (i.e. splitting each 4K page into two
+ * 2K subpages and then padding these 2K pages up to take a complete
+ * 4K sector again) will will double the image size.
+ *
+ * Thus we return the padded_size as an additional padding requirement
+ * (be sure to add this to the padding returned from the common code).
+ */
+ return padded_size + padding;
}
/*